Quote:
|
Quote:
Thanks for sharing your insight! |
Quote:
|
Quote:
OK, so could you separate your code into two files ? Doing that will hopefully show yet another inherent problem. |
Quote:
If the problem is that the main module will be able to overwrite createCar from the second module, than this is not a problem, no matter how much you'd like it to be. In fact, it's a feature which makes testing possible. Your Perl code is untestable since unit tests cannot substitute the car creation routine with some other routine which returns a mock object. |
Quote:
|
Quote:
Code:
$ cat car.py |
Quote:
I.e. the 'car' name pollutes top level namespace, correct ? ... Was it, by the way, 'Car' rather than 'car' ? If yes, you see yet another source of potential errors ? You need to know the class name, don't you ? You probably need the files to follow <class_name>'py naming convention ? |
Quote:
Quote:
By the way, either of the below will work as well: Code:
import car as blah Code:
from car import createCar Code:
from car import createCar as blah Quote:
Quote:
Quote:
So, have we established already that your argument is invalid? |
Quote:
Module names are in global namespace in both Perl and Pyhton, while top level lexical variables are not. Furthermore, and I think it's the fundamental issue Python proponents do not understand, with anonymous export -> named import, i.e. with Code:
my $foo = require 'some_file.prl'; With Code:
my $foo = require 'some_file.prl'; ... Maybe I'll prepare a shorter example showing lack of protection of variables in producer. And maybe even in consumer - I have to check Python documentation and maybe even write some code myself. |
I'm seriously getting tired of this argument. Granted, in
Code:
my $foo = require 'file.prl'; Code:
import file as foo |
Quote:
I am saying that give_name_to_anonymous foo_name is simpler than rename foo bar . Or in yet other words - why to have a name if it is to be discarded anyway ? And AFAIR, in ( http://docs.python.org/release/2.5.2/ref/import.html ) Quote:
|
Quote:
Quote:
Quote:
|
Quote:
I meant that when writing first the producer gives a name, and then the consumer renames that name in Quote:
So why giving name in the first place ? And, overall, this example shows that in order to imitate block scope classes are used, and classes require names, and the name is then discarded. Readable ? Logical ? By the way, in Java scopes also used to suck, and the workaround was also to use classes, and classes could be anonymous, but 'class' keyword was needed. I suspect Java designers wanted to make Java as different from C++ as possible, and Python designers wanted to make Python as different from Perl as possible. Ironically, both Java and Python designers in the end had to introduce closures. ... Quote:
|
Quote:
Code:
>>> import foo as bar |
All times are GMT -5. The time now is 02:59 AM. |