Import concerns revisited

Derek Parnell derek at psych.ward
Sun Jul 9 04:32:17 PDT 2006


On Sun, 09 Jul 2006 17:59:36 +1000, Walter Bright  
<newshound at digitalmars.com> wrote:

> kris wrote:
>> The use of alias, regarding imports, should very likely be kept to a  
>> bare minimum in anything other than Q&D development. Ideally zero.
>
> I really don't understand your pov. I can't help but think you regard  
> alias as like C++'s #define:
>
> 	alias foo bar;
> 	#define bar foo

I'm hope I'm not messing up Kris' words here but I think he is saying that  
we need to cut down on the amount of typing and reading people *must* do  
in a program. Keep it to a minimum. Try and work the syntax so that the  
common and mandatory things are short, easy, and intuitive to do. Make the  
unusual and 'special' things have more detail in the syntax.

> Such #define's I would agree are a terrible hack that don't belong in  
> professional code. But aliasing isn't like that, it's a sane and  
> well-behaved replacement.

I don't think we are talking so much about the semantics of alias but more  
about how to code it efficiently.

> With the "static import", there is no longer any possibility of name  
> collisions, so we're not at square one. With no aliases, fully qualified  
> module contents lookup will be needed.

"static import" is not an intuitive syntax. I doesn't mean much until one  
explicitly learns it.


>>  // import as we know it today, and with a required prefix "locale."
>> import lib.text.locale;
>> import lib.text.locale as locale;
>>  // selective import of one entity, and alternatively with an alias
>> import lib.text.locale.Time;
>> import lib.text.locale.Time as otherTime;
>>  ==================================
>
> But those *are* aliases. It's just using a different keyword, "as"  
> instead of "alias", and a slightly rearranged syntax. So what's the  
> difference between:
>
> import lib.text.locale.Time as otherTime;
>
> and:
>
> alias lib.text.locale.Time otherTime;
>
> ? Absolutely none, unless I am totally misunderstanding your proposal.

Not really. Firstly "import ... as ...;" is a single statement but "import  
...; alias ...;" is two which can be separated and 'hidden' in the  
clutter. Secondly, the proposed syntax is not redundant - the module name  
is typed in only once.

> The "static import" is a bit ugly looking, ok. It's a little wordier,  
> ok. But it does work and produces exactly the results you asked for.

*NOT* ok. Why encourage mediocrity. You can do us and future D coders a  
favour by giving us a better syntax than something that is admittedly ugly  
and too wordy.

-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d mailing list