Difference between revisions of "Talk:Order of import statements"

From D Wiki
Jump to: navigation, search
(new syntax)
 
 
Line 20: Line 20:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
&mdash;[[User:Quickfur|Quickfur]] ([[User talk:Quickfur|talk]]) 17:14, 17 December 2012 (CET)
 
&mdash;[[User:Quickfur|Quickfur]] ([[User talk: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
 +
<syntaxhighlight lang=D>
 +
import
 +
std.stdio : writeln,
 +
std.algorithm;
 +
</syntaxhighlight>
 +
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. [[User:Shd|Shd]] ([[User talk:Shd|talk]]) 23:53, 17 December 2012 (CET)

Latest revision as of 22:53, 17 December 2012

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)

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

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)