www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - import/format tools?

reply mark <mark qtrac.eu> writes:
Is there a tool that will sort imports (e.g., as per the style 
guide), and that will also add the specific names used?

Also, is there a D source formatting tool (ideally with options 
to set a max line length and choice of braces style)?

Is there any runtime (or compiletime) cost to just listing 
imports at the start of a file without listing the specific 
functions?

Is there any advantage to doing imports inside functions, or to 
listing specific imports?
Jan 18 2020
parent Boris Carvajal <boris2.9 gmail.com> writes:
On Saturday, 18 January 2020 at 09:33:34 UTC, mark wrote:
 Is there a tool that will sort imports (e.g., as per the style 
 guide), and that will also add the specific names used?
D-Scanner[1] will warn you about non sorted imports You need to set imports_sortedness="enabled" on your dscanner.ini file. then: dscanner --styleCheck <your file>
 Also, is there a D source formatting tool (ideally with options 
 to set a max line length and choice of braces style)?
Check dfmt[2]
 Is there any runtime (or compiletime) cost to just listing 
 imports at the start of a file without listing the specific 
 functions?
AFAIK there is no difference at least for now. The imported module have to be loaded and parsed completely, on the other hand selective imports don't pollute the symbol table.
 Is there any advantage to doing imports inside functions,
Yes, if you do the import inside a template and this is not instantiated the import never happens and you save precious compilation time, the same with function templates. This is really important, if you look at phobos code you can see the tendency to reduce to the very specific case the import statement.
 or to listing specific imports?
It's always better to import more specific modules vs complete packages like importing std.algorithm.sorting instead of std.algorithm but there are a lot of stuff required between some modules that we are talking about milliseconds of difference, however using D you get used to fast compile times that you lose patience if the thing takes longer than one second. [1] https://github.com/dlang-community/D-Scanner [2] https://github.com/dlang-community/dfmt
Jan 18 2020