Flag proposal

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Sat Jun 11 03:45:26 PDT 2011


bearophile wrote:

> Andrei:
> 
>> This module won't compile in today's D, but not for a matter of
>> principles; it's just a random limitation of the language. (It does work
>> if you import from within a class or struct.) You can insert most
>> declarations in a scope, so the ones you can't insert are just awkward
>> exceptions, unless there's a good reason to actively disable them. Any
>> code should work if you just wrap another scope around it.
>> 
>> Walter and I call the above a "turtle feature", in allusion to the
>> "turtles all the way down" meme. Walter wants to fix this, and similar
>> limitations that act "unturtly". Imports inside a scope won't be visible
>> outside that scope, and importing the same module from several different
>> functions will come at no cost in compilation time.
> 
> You are allowed to import modules inside functions in Python too (there is
> a just a minor restriction), but I have never asked for this feature in D
> because this feature has a cost too. Putting all imports at the top of the
> module is more tidy, it allows the person that reads the code to find all
> the used imports very quickly. If they are spread in the module they
> become less easy to find, you need to use your editor/IDE to search for
> them.
> 
> Bye,
> bearophile

Why would you have to find local imports? It's considered good practice to 
narrow scope of variables and put declarations as close as possible to point 
of use, yet you don't hunt for local variable declarations all the time.

If an import is local, it is simply (supposedly) only of concern to that 
scope and relevant when doing work concerning whatever is in that scope. In 
effect this could as well lead to reducing to need to look for imports!

Python is a bit different because there's an awful lot more going on when 
importing, with increased chances of bugs when not careful. Simply importing 
something more than once can introduce errors. Hopefully, that is less so 
with D. The only really tricky thing are module constructors (circular 
imports). But at this level, it's probably easier to use facilities of dmd 
to tell you what imports what.


More information about the Digitalmars-d mailing list