Journal Journal: Circular dependencies in three languages 1
Here are six files for ya, showing a problem in 3 different scripting languages. What will they do?
--------- test1.php:
<?php
require 'test2.php';
define('SOMECONSTANT','hello world');
function foo() {
return SOMECONSTANT;
}
echo foo(); echo "\n";
--------- test2.php:
<?php
require_once 'test1.php';
echo foo(); echo "\n";
--------- test1.py:
#!/usr/bin/python
import test2
SOMECONSTANT='hello world'
def foo():
return SOMECONSTANT
print foo()
--------- test2.py:
#!/usr/bin/python
import test1
print test1.foo()
--------- test1.rb:
#!/usr/bin/ruby
require 'test2.rb'
SOMECONSTANT='hello world'
def foo
SOMECONSTANT
end
puts foo()
--------- test2.rb:
#!/usr/bin/ruby
require 'test1.rb'
puts foo()
---------
Ok, scriptfiends, predict the output of these three commands:
php -q -f test1.php
python test1.py
ruby test1.rb
and then do some pasting and try it out. Match your predictions?
The PHP one bit me pretty hard today.