Import concerns revisited
Regan Heath
regan at netwin.co.nz
Tue Jul 11 05:59:37 PDT 2006
On Tue, 11 Jul 2006 14:01:12 +0200, xs0 <xs0 at xs0.com> wrote:
> Walter Bright wrote:
>> xs0 wrote:
>>>> The imports can be placed anywhere in the module, even (ugh) inside
>>>> class definitions. 'import' isn't any easier to search for than
>>>> 'alias'.
>>> I was wondering - is there any good reason to allow imports everywhere?
>> It's usually a good idea to make things as orthogonal, with as few
>> special case, as possible. Since imports are a declaration, they should
>> work wherever declarations work.
>
> OK, I guess, I never thought of them as declarations... Must be too much
> Java ;)
>
>>> OT: if you'll be changing the import system, _PLEASE_ make private
>>> imports the default.
>> It's too late for that, sorry. Also, everything else in D is public by
>> default, and consistency is sometimes better than special case rules,
>> even if those special case rules make some things easier.
>
> Well, I agree that consistency is often better than special case rules,
> but I don't agree this is one of those cases. Just so I wouldn't be
> biased by my own experience, I went and counted all the imports in
> mango.io, which confirmed my suspicions - the vast majority of imports
> are private.. My count is 173 imports, 32 of which were public (~18%).
> If it wasn't for one-class-per-module Mango seems to be doing, my guess
> is that there'd be no public imports at all, as most of them seem to
> just be convenience imports for various interfaces.
>
> And I agree with Lars - it's not too late and public being the default
> for everything may not be the best option anyway. For example, in Java
> the default is package-private, which would roughly translate to
> module-private in D. I rarely need to change that default (i.e. specify
> a different protection), as things are usually pretty consistent with
> what I want that way.
>
> Finally, your own stated major goal for D is to "improve productivity ..
> by adjusting language features so that common bugs are eliminated from
> the start", and from what I've seen in the newsgroups, forgetting to
> import privately is definitely a common bug, and nobody seems to expect
> an unqualified import to be public.
I'd prefer if imports were private by default. Making everything public
may make it easier to remember initially but once you know something it
really doesn't matter if it's the same as something else. So, while it may
help the beginner learn and remember it, it penalizes the every day user
by making it harder and more verbose to code in a 'clean' fashion.
Regan
More information about the Digitalmars-d
mailing list