-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sdfmt: Template constraint formatting issue #231
Comments
I never understood why the DStyle state one line per brace. this is awful in general, but this is especially awful in D. Consider contract for instance, mostly because of that guideline, a new syntax was introduced, but even more damning, there was a proposal by Andrei no less to change the recommendation for in condition to be written within the function's body with assert because the existing style was too awful. When a guideline is the source of semantic breaking change followed by a language syntax change, it's a strong tell that the guideline is not good and should be abandoned. As for uglyness, I don't find this sample especially ugly. What do you think make that formatting bad, objectively? All the alternative I've seen used in D code in the wild have objective downsides:
void foo(T)(T t)
if (condition) {
// do stuff...
} vs void foo(T)(T t);
if (condition) {
// do stuff...
} Putting the if at one indentation level makes it look like it is part of the function's body, so I went for 2 levels, kind of as a default. I was weirded out by it at first, but objectively, it is better than all the alternatives I've seen. Do you have a better idea? |
Personally, I like having braces on separate lines for function decls at least. I couldn't care less about statements though. Having the constraint to be intended so that it looks distinct from the function is a good thing (although I don't really care as long as a codebase has a convention) but I think the current formatting just looks really weird.
Having the brace on the same line as a the constraint is a big https://en.wikipedia.org/wiki/Principle_of_least_astonishment violation, and I'm saying that as someone who has made a point of never quoting such laws and principles before. |
Having the brace on the same line is an exceedingly common pattern, it is called Egyptian braces and is present in numerous coding conventions. |
I don't think the discussion should be about ugliness, which is subjective after all. How about making it optional? An option like "put brace on newline when function signature and constraints span multiple lines" ? If true, you'd get: int foo() {
return 1;
}
int foo()
if ( .... )
{
return 1;
}
int foo(int asdkahdkjashdjkahsdkjads,
int aksjdasdajksda, int asdasd)
{
return 1;
} |
This discussion is not about ugliness. Several points were raised as to why this is an inferior style for D code. These points were substantiated by actual problems in the wild causes by the "official" D style, not even abstract supposed ones. There are a couple of problems with the road you suggest this goes down to:
There are a couple of exception to these principles, (Prettier has a good run down here)[https://prettier.io/docs/en/why-prettier.html]. But I digress, because this failed to address the first thing required for this to take off: demonstrating that it solves an actual problem. The closest thing we have to a problem statement is that it doesn't follow the official D style guide. But following said style is not a goal of the project to begin with, and in addition, deviating from said goal solves actual problems that can be pointed at. So it's a slam dunk, and will remain a slam dunk until new evidence that it solves an actual problem is brought to the table. |
Hi @deadalnix , it's a pity you feel this way.
The actual problem is: I cannot read the current formatting well, neither can Max. It's unfortunate and means I cannot support use of sdfmt at Weka. |
Apologies for the hyperbole. (I think with a few fixes it'll be fine :-)) |
If this is a blocker for Weka, then it's worth thinking about, but so far, there doesn't seems to be a good solution. If you try to implement things such as "put brace on newline when function signature and constraints span multiple lines" as you suggest, you'll quickly realize that it's not as simple as you think it is and it's very easy to run into situations where the formatter start making very strange decisions because of rules interacting ins strange ways. It'd be interesting to have @maxhaton 's feedback after using that style for a while at symmetry. The general pattern seems to be an initial "WTF is this" (which I definitively went through myself, this was FAR from my initial choice) but then people get used to it and find it to work for them. It's worth thinking about. |
is currently a fixed-point for sdfmt. This is ugly.
Note that the DStyle dictates a new line per brace.
The text was updated successfully, but these errors were encountered: