Import concerns revisited

kris foo at bar.com
Wed Jul 12 17:48:55 PDT 2006


Walter Bright wrote:
> Derek Parnell wrote:
> 
>> On Thu, 13 Jul 2006 05:05:22 +1000, Walter Bright
>>
>>> It's not always true, but languages that are less wordy in their 
>>> example code tend to be picked up faster. People's first projects in 
>>> D aren't going to be large, complex, professional products. They'll 
>>> want to just try it out on something simple. That bar should be as 
>>> low as reasonable.
>>
>>
>> I understand your desire to not 'frighten' new comers away. My concern 
>> is that your "low as reasonable" seems to encourage poor programming 
>> practices. Can you provide an example where the 'import' and 
>> 'visibility' ideas being brainstormed at the moment would force 
>> example code to look scary? At worst, someone might have to add 
>> 'public { ... }' somewhere.
> 
> 
> Not exactly what you're after, but consider the Java hello world program:
> 
>   class HelloWorldApp {
>     public static void main(String[] args) {
>         System.out.println("Hello World!");
>     }
>   }
> 
> There's a reason for everything there, but it's a little off-putting. 
> Consider the D version:
> 
>   import std.stdio;
> 
>   void main() {
>      writefln("Hello World!");
>   }
> 
> I can go straighter towards what I want to do, without detouring through 
> all the other requirements Java puts on things that seem, with such a 
> simple program, to be beside the point.
> 
> Just for fun, here's an Ada version:
> 
>   With STANDARD_IO;
>   Use STANDARD_IO;
>   Procedure HELLO_WORLD is begin
>     Put("Hello world!");
>   End HELLO_WORLD;
> 
> No thanks! <g>


And the concise & completely safe D version:

    import std.stdio io;

    void main() {
       io.writefln("Hello World!");
    }

However, this example imports only the one module, so use of the unsafe 
import might be ok for such things?

On the other hand, someone pointed out that habits are formed from just 
such examples (was it Derek?). One should perhaps be careful to ensure 
the safe approach is /encouraged/ right from the start, if such habits 
are indeed formed in this manner? That's a question for another time.


 > I can go straighter towards what I want to do, without detouring
 > through all the other requirements Java puts on things that seem,
 > with such a simple program, to be beside the point.

If concise language is considered beneficial, then D would likely gain 
from a less wordy safe-import (in terms of overal usage).


 > I can go straighter towards what I want to do, without detouring
 > through all the other requirements Java puts on things that seem,
 > with such a simple program, to be beside the point.

Then why detour with an extra alais statement?

     import lib.db.model.odbc odbc;

     void main() {
        auto db = odbc.open ("db");
     }

versus this:

     static import lib.db.model.odbc;
     alias lib.db.model.odbc odbc;

     void main() {
        auto db = odbc.open ("db");
     }

To echo your own sentiment, No thanks! <g>


the latter looks rather like the Ada version.

 >   With STANDARD_IO;
 >   Use STANDARD_IO;
 >   Procedure HELLO_WORLD is begin
 >     Put("Hello world!");
 >   End HELLO_WORLD;





More information about the Digitalmars-d mailing list