dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

`version(){} else fun_declaration` shows weird braces

Open timotheecour opened this issue 7 years ago • 5 comments

version (foo)
{
}
else
    void main(string[] args)
{
}

timotheecour avatar Feb 09 '18 01:02 timotheecour

@timotheecour how should it look like ?

UplinkCoder avatar Mar 07 '18 20:03 UplinkCoder

shouldn't it be:

version (foo)
{
}
else
    void main(string[] args)
    {
    }

for all functions, { should be at same indent as function start, shouldn't it?

timotheecour avatar Mar 07 '18 20:03 timotheecour

well version is in the same league as #if so

version (foo)
{
}
else
void main(string[] args)
{
}

would also be plausible

UplinkCoder avatar Mar 07 '18 20:03 UplinkCoder

indeed, that seems even better.

timotheecour avatar Mar 08 '18 00:03 timotheecour

Unfortunately this code too common, so it might make sense to special code it? This is my preferred formatting and I think the common one (even in Phobos/DMD) for cases where you want to negate a version like e.g.

version(unittest) {} else
void main()
{
    import std.stdio;
    writeln("Hello D");
}

DMD's style is a bit different (e.g. https://github.com/dlang/dmd/blob/master/src/dmd/libelf.d), but also do to having more than one case.

wilzbach avatar Mar 28 '18 04:03 wilzbach