boris2.9 at gmail.com
Sat Jan 18 11:16:56 UTC 2020
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 will warn you about non sorted imports
You need to set imports_sortedness="enabled" on your dscanner.ini
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)?
> Is there any runtime (or compiletime) cost to just listing
> imports at the start of a file without listing the specific
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.
More information about the Digitalmars-d-learn