dfmt
dfmt copied to clipboard
Anonymous class as function parameter messes up entirely
Consider:
void main()
{
call(new class Object
{
void method()
{
call;
}
});
}
dfmt's take:
void main()
{
call(new class Object
{
void method()
{
call;}
}
);
}
And from there on, the entire rest of the file is misindented by one.
What is actually the expected brace style? Since this is continues a statement across lines it could arguably be indented one deeper:
void main()
{
call(new class Object
{
void method()
{
call;
}
}
);
}
The one suggested is commonly used across languages and it seems reasonable to use.
Also consider this: What default behaviour is reasonable for the case that anon class doesn't appear in the first line of the function args? See cases below. Should whatever gets chosen there have influence on the choice of how it's indented if it's the first argument?
void f()
{
// Should it be this (case 1):
writeln("Anonymous object does not begin on the first line",
new class Object
{
void method()
{
writeln;
}
});
// Or this (case 2):
writeln("Anonymous object does not begin on the first line",
new class Object
{
void method()
{
writeln;
}
});
// Or this (case 3):
writeln("Anonymous object does not begin on the first line",
new class Object
{
void method()
{
writeln;
}
}
);
}
I think case 2 since I don't think having closing parentheses on the same indent level as opening is reasonable (case 3); case 1 seems to me like an obvious no.
I think the behaviour should be consistent with braces in parenthesis in general, which is currently: (I feel like brace case 2 might actually be more reasonable if braced argument is not the first one?)
void g()
{
// Current behaviour brace on first line:
writeln({
int longVarNameToForceLineBreak = 5;
writeln(longVarNameToForceLineBreak);
return longVarNameToForceLineBreak * 2;
});
// Current behaviour brace not on first line (brace case 1):
writeln("Brace does not begin on the first line",
{
int longVarNameToForceLineBreak = 5;
writeln(longVarNameToForceLineBreak);
return longVarNameToForceLineBreak * 2;
});
// Current behaviour brace not on first line (brace case 2):
writeln("Brace does not begin on the first line",
{
int longVarNameToForceLineBreak = 5;
writeln(longVarNameToForceLineBreak);
return longVarNameToForceLineBreak * 2;
});
}
I agree, case 2 seems good and in general keeping consistency with existing parentheses rules