uligerhardt 18 Posted January 12, 2023 I have disabled the "Always break line between else and if" option, and I'm happy with the results. However my colleague insists on having nested if-elses without begin/end pairs and on top mixes this with comments. A simplified example: procedure MyProcedure(a, b: Boolean); begin if a then if b then Beep else Beep else // Kommentar if b then Beep else Beep; end; This gets formatted to procedure MyProcedure(a, b: Boolean); begin if a then if b then Beep else Beep else {// Kommentar} if b then Beep else Beep; end; Is there an option to keep the lines separate under these circumstances? Do you deem the current behavior desirable? Share this post Link to post
baka0815 12 Posted January 12, 2023 I think this could be the same topic as Share this post Link to post
Lars Fosdal 1792 Posted January 12, 2023 /off-topic Preferences of code. I like begin/end for clarity. However, I also like unusual breaks before then and strange indentations of single statements. If only I could convince the formatter to do my bidding. procedure MyProcedure(a, b: Boolean); begin if a then begin if b then Beep else Beep end else begin if b // Kommentar then Beep else Beep; end; end; Share this post Link to post
dummzeuch 1505 Posted January 12, 2023 1 hour ago, uligerhardt said: I have disabled the "Always break line between else and if" option, and I'm happy with the results. However my colleague insists on having nested if-elses without begin/end pairs and on top mixes this with comments. A simplified example: procedure MyProcedure(a, b: Boolean); begin if a then if b then Beep else Beep else // Kommentar if b then Beep else Beep; end; This gets formatted to procedure MyProcedure(a, b: Boolean); begin if a then if b then Beep else Beep else {// Kommentar} if b then Beep else Beep; end; Is there an option to keep the lines separate under these circumstances? Do you deem the current behavior desirable? There is no option (as far as I know, I might have missed it). And I remember seeing a comment in the original formatter sources from Egbert van Nes that he implemented this behaviour because he couldn't get the formatter handle these comments in any useful manner without breaking the source code. If anybody really wants to use that kind of comments: I am accepting patches. Share this post Link to post
dummzeuch 1505 Posted January 12, 2023 5 minutes ago, Lars Fosdal said: /off-topic Preferences of code. I like begin/end for clarity. However, I also like unusual breaks before then and strange indentations of single statements. If only I could convince the formatter to do my bidding. procedure MyProcedure(a, b: Boolean); begin if a then begin if b then Beep else Beep end else begin if b // Kommentar then Beep else Beep; end; end; If you really want that kind of formatting: I am accepting patches. Share this post Link to post
dummzeuch 1505 Posted January 12, 2023 47 minutes ago, baka0815 said: I think this could be the same topic as No. It's something totally unrelated. Share this post Link to post
Lars Fosdal 1792 Posted January 12, 2023 5 minutes ago, dummzeuch said: If you really want that kind of formatting: I am accepting patches. Well, I am not that consequent, so I'll make do, doing it manually. It did take me 30+ years to develop this style for readability, though. One of the benefits of breaking before then, is that it becomes easy to comment out parts of the if condition. One of the benefits of the hanging indent on single line statements, is that it is easy to spot where the full statement ends. Readability is cruical. Maintainability improves with readability. Share this post Link to post
uligerhardt 18 Posted January 12, 2023 23 minutes ago, Lars Fosdal said: /off-topic Preferences of code. I like begin/end for clarity. However, I also like unusual breaks before then and strange indentations of single statements. If only I could convince the formatter to do my bidding. procedure MyProcedure(a, b: Boolean); begin if a then begin if b then Beep else Beep end else begin if b // Kommentar then Beep else Beep; end; end; I'd just use begin/end here too, but that's difficult because of my charcter counting colleague. 😉 Share this post Link to post
uligerhardt 18 Posted January 12, 2023 21 minutes ago, dummzeuch said: There is no option (as far as I know, I might have missed it). And I remember seeing a comment in the original formatter sources from Egbert van Nes that he implemented this behaviour because he couldn't get the formatter handle these comments in any useful manner without breaking the source code. If anybody really wants to use that kind of comments: I am accepting patches. OK then, I'll see if I can give it a try. Share this post Link to post
uligerhardt 18 Posted January 12, 2023 Do I remember correctly that the standalone formatter doesn't use the expert DLL anymore? That should make debugging much easier. Share this post Link to post
baka0815 12 Posted January 12, 2023 1 hour ago, Lars Fosdal said: /off-topic Preferences of code. I like begin/end for clarity. However, I also like unusual breaks before then and strange indentations of single statements. If only I could convince the formatter to do my bidding. procedure MyProcedure(a, b: Boolean); begin if a then begin if b then Beep else Beep end else begin if b // Kommentar then Beep else Beep; end; end; I also like begin/end for readability, but that code style gives me the creeps. I would format it the following way (or even use additional begins and ends for the "Beeps"). procedure MyProcedure(a, b: Boolean); begin if a then begin if b then Beep else Beep; end else begin // Kommentar if b then Beep else Beep; end; end; Share this post Link to post
David Heffernan 2345 Posted January 12, 2023 1 hour ago, Lars Fosdal said: /off-topic Preferences of code. I like begin/end for clarity. However, I also like unusual breaks before then and strange indentations of single statements. If only I could convince the formatter to do my bidding. procedure MyProcedure(a, b: Boolean); begin if a then begin if b then Beep else Beep end else begin if b // Kommentar then Beep else Beep; end; end; Personally I think it's much clearer like this: procedure MyProcedure(a, b: Boolean); begin if a then begin if b then Beep else Beep end else begin if b // Kommentar then Beep else Beep; end; end; 1 Share this post Link to post
Bounceback 1 Posted January 12, 2023 Quite seriously, IMHO, this is something that you have to figure as you go, from case to case that is. Som variable names/expressions are SuperLoooooong.Chains.Of() and some are shrt. That is definitely IMHO something that should be factored in - so just look at the code (preferrably some months after you wrote it - maybe not so manageable, but anyho) and use the style that appears most clear. 1 Share this post Link to post
Fr0sT.Brutal 900 Posted January 13, 2023 Ouch. Different indents look crazy. 1 Share this post Link to post
dummzeuch 1505 Posted January 13, 2023 16 hours ago, uligerhardt said: Do I remember correctly that the standalone formatter doesn't use the expert DLL anymore? That should make debugging much easier. No, that's not the case. But the Unit Tests don't use the DLL, so you can create test cases for the unit tests and then implement the code directly using that program. 1 1 Share this post Link to post