Flag proposal

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jun 10 19:10:32 PDT 2011


On 6/10/11 8:21 PM, 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

Maybe you also care less about what you import.

Similar arguments have been made for placing all variable declarations 
at the top of the function etc. It's unclear at this point how far local 
imports would go, but I see good advantages.

Andrei


More information about the Digitalmars-d mailing list