Import concerns revisited
Dave
Dave_member at pathlink.com
Tue Jul 11 08:15:39 PDT 2006
Walter Bright wrote:
> Dave wrote:
>> Walter, I think what most are getting at here is that the 'as' syntax
>> just seems cleaner and more efficient from a coding and maintenance POV.
>>
>> If it's easy to implement, then I say go for it. If nothing else,
>> people can still use 'explicit' aliasing. I argue that 'as' will
>> actually be quicker for newbies to grasp (*especially* when they see
>> it in example code), and my sense is that it will be a boon to
>> maintenance because it generally won't end-up buried in the middle of
>> a module like many aliases would be. It's not like alias will be a
>> wasted feature - most prominently it will be used for storage types;
>> it just feels more 'natural' that way.
>
> I think you're saying that this is not a discussion about functionality,
> but about aesthetics. I agree with that.
>
> A couple of people have brought up the alias-in-the-middle thing:
>
> 1) If it's in the middle because it's in a nested scope, then it only
> applies for the duration of that scope. Presumably, it would be easily
> visible to anyone looking at that scope.
>
> 2) I think we can all agree that if it is at module scope in the middle,
> that is probably bad coding style - especially if there are forward
> references to it.
>
> 3) The with-import-as won't eliminate bad coding style with aliases. One
> can still plop an alias down in the middle of the module.
>
> 4) At least with aliases, they need to be defined within the module.
> This means one can do a simple search of one source file to find any
> aliases.
>
> Let's look a bit at the aesthetics:
>
> with foo.bar import
> abc as def,
> ghi as jkl,
> mno;
>
> import very.long.name as N;
> vs:
> static import foo.bar;
> alias foo.bar.abc def;
> alias foo.bar.ghi jkl;
> alias foo.bar.mno mno;
>
> import very.long.name;
> alias very.long.name N;
>
>
> Yes, the latter is more typing. If one was to do this a lot, it can get
> annoying. But is it going to be done a lot? I think that is the crux of
> the matter.
>
> P.S. There are other possible syntaxes:
>
> import foo.bar
> { def = abc,
> jkl = ghi,
> mno,
> }
If we go that route, then that syntax would be fine by me as well!
I don't like starting with 'with/from' because that 'hides' 'import' or
'private import' which is what D users are used to when they scan a page
for imports.
More information about the Digitalmars-d
mailing list