Nested public imports - bug or feature?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 13 08:59:46 PDT 2015


On 08/13/2015 05:49 PM, Dicebot wrote:
> On Thursday, 13 August 2015 at 15:40:12 UTC, Timon Gehr wrote:
>> You know about static imports, right?
>
> Yes, as well as about renamed and selective ones ;)
>
> Problem with static imports is that they are all-or-nothing.

(Which is an arbitrary restriction most likely motivated by 
implementation difficulties.)

> And in our
> projects it is common to have module names with 5 nested packages or
> even more. Typing all of it is impractical - simple prefix gives enough
> protection from random clashes.
>
>>> D module system is completely broken in that regard.
>>
>> What's the alternative?
>
> When doing my old "Rust vs D" comparison I have been mentioning their
> import semantics as a big win. When you do import like this:
>
> use phrases::english::greetings;
>
> You must always also qualify symbol name with module name like this:
>
> println!("Hello in English: {}", greetings::hello());
>
> And this won't compile:
>
> println!("Hello in English: {}", hello());
>
> It has similar benefits as the idiom proposed in this topic - greatly
> reduced risk of accidental clashes.

static import greetings=phrases.english.greetings;

?


More information about the Digitalmars-d mailing list