Import concerns revisited

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Wed Jul 12 17:32:31 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!");
>   }

Changing the language syntax so that imports are private by default does
not change anything in either of those examples. Perhaps this is a
better example:

module gfx_subsystem:
  private import GUI;

  void init_gfx_system() { setvideomode(); clearbuffers(); ... }

module game_engine:
  (private) import gfx_subsystem, sound_subsystem;

  void init_engine() { init_gfx_system(); ... }

Here the developer of game_engine is really not interested in GUI
widgets. If gfx_subsystem publicly imported the GUI stuff, the namespace
of game_engine would be totally poisoned. Then why should it be the
default behavior? After all, this is a very common pattern in
applications programming. Using public imports also makes the
development process a lot more time consuming. Think of all the
irrelevant proposals the IDE shows when auto-completing code in a
poisoned namespace.

-- 
Jari-Matti



More information about the Digitalmars-d mailing list