Talk:Order of import statements

From D Wiki
Revision as of 22:53, 17 December 2012 by Shd (talk | contribs)
(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;
    // cannot use writeln here

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

I've been using using your syntax for a while, however it does not supports selective imports such as
	std.stdio : writeln,

However, that's the content moved from the old wiki (because i find it valuable). I don't feel competent to discuss about best practices, so if you find the topic interesting enough you can post on the forums. If you think this advice is no longer relevant (because of nested imports) you can freely delete that. Shd (talk) 23:53, 17 December 2012 (CET)