Talk:Order of import statements

From D Wiki
Revision as of 16:14, 17 December 2012 by Quickfur (talk | contribs) (new syntax)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
This is a talk page. It is to be used for discussion of potentially controversial or otherwise large changes to the article itself.
  • Please use the Add Topic link to start a discussion on a separate topic. Don't start a new topic inside an unrelated section, as it will only cause confusion.
  • As a rule, it is considered bad form to edit somebody else's comments. Instead, post your reply to their comments immediately after.
  • Please sign your comments with four tildes (~~~~) so that we know who said what.

What about the new syntax?

I'm not sure if this is in 2.060 yet, but dmd in git head supports this syntax, which is more compact:

import std.algorithm, std.range, std.stdio;

And also supports imports within a limited scope, which corresponds better with declaring things near where they are used, as opposed to arbitrary locations like the top of the file:

module MyModule;
void myFunc() {
    foreach (i; 0..100) {
        auto j = i*123;
        import std.stdio;
        writeln(j);
    }
    // cannot use writeln here
}

Quickfur (talk) 17:14, 17 December 2012 (CET)