Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I'd say the biggest difference between Python and Ruby's is that Python's has a syntax, whereas Ruby's is a function call

This is not true on two fronts.

First, the import statement is a convenient, hookable wrapper around the __import__ function. It's quite customizable already. See PEP302 which references and allows implementation of PEP273 (importing modules from Zip archives). Other points of reference include [0], [1] and [2]

Also, the biggest difference is that when you 'require', you require a filename (i.e the arbitrary content of a file in the filesystem), but when you 'import', you import objects from a namespace into a scope. The namespace is resolved as an item living in the filesystem. In Ruby I could require 'foo/bar' and it could create the constants Foo::Bar and Qux::Quux. I have no way to require Qux::Quux. Rails for example tries to autoload constants based on their names, but for all I know, the second I reference Foo::Bar, it could actually define Qux::Quux. Ruby encourages this style of programming, spreading extendable classes and modules around in multiple files, while Python decides that things should be contained and well-behaving, and not trivially pollute unrelated module namespaces.

My analysis is that by definition you just can't have both, and that either one has a set of benefits and drawbacks.

[0] http://docs.python.org/library/importlib.html#importlib.impo...

[1] http://docs.python.org/library/imputil.html

[2] http://docs.python.org/py3k/library/importlib.html?highlight...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: