Order of import statements

From D Wiki
Revision as of 21:35, 23 November 2012 by Shd (talk | contribs) (order of import statements)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Order of Import Statements

As an aid to maintainability, discoverability and possible automation, it would be helpful to have a simple import ordering convention? Specifically:

  • imports from std come first. Root-level comes first, followed by in alphabetical order for sub-levels
  • an empty line comes next
  • imports from third-party come next. Root-level comes first, followed by in alphabetical order for sub-levels
  • an empty line comes next
  • imports from other modules in "this" organisation/project/library come last. Root-level comes first, followed by in alphabetical order for sub-levels

An example:

 import std.loader;
 import std.utf;
 import std.c.windows.windows;

 import mango.blah;
 import mango.stuff;
 import mango.abc.otherstuff;
 import mango.things.nicethings;

 public import mylib.stuff
 public import mylib.badthings.hmm;
 public import mylib.goodstuff.garbage;