ŁukaszDe 38 Posted September 6, 2019 Hi all, Is possible to set code formatter in CnPack to get: if ... then begin ... end else if ... then begin ... end else begin ... end; I want 'else' behind 'end' and 'if' in new line. Share this post Link to post
Dave Nottage 563 Posted September 6, 2019 2 hours ago, ŁukaszDe said: Is possible to set code formatter in CnPack to get: It has a "begin style" but no "end style": So my guess is: no. Share this post Link to post
timfrost 79 Posted September 6, 2019 I hate this style, but I am pretty sure you can achieve it using the GExperts formatter, the one I have always used. [If not answering the question helps you] Share this post Link to post
Jacek Laskowski 57 Posted September 6, 2019 7 hours ago, ŁukaszDe said: if ... then begin ... end else if ... then begin ... end else begin ... end; I want 'else' behind 'end' and 'if' in new line. I suggest you report to the tracker, maybe they will do: https://github.com/cnpack/cnwizards I like this style too 😉 Share this post Link to post
Anders Melander 1815 Posted September 6, 2019 4 hours ago, timfrost said: I hate this style, [...] Just out of curiosity, as I use this style myself, why do you "hate" it? Share this post Link to post
timfrost 79 Posted September 6, 2019 I really don't want to start a 'style war'; it is just that I find it easier to see the structure if the 'if' and the 'else' are aligned and each begin/end block stands alone with its own indentations. Share this post Link to post
Anders Melander 1815 Posted September 6, 2019 I see. Thanks. No need for a war; We all know there's only "One True Style" - and it's the one we use ourselves 🙂 2 Share this post Link to post
Stefan Glienke 2019 Posted September 6, 2019 The real issue I have with this style is that we have to write code like this in the first place because Delphi does not support pattern matching. Share this post Link to post
Anders Melander 1815 Posted September 6, 2019 Pattern matching? You'll have to explain that one. Share this post Link to post
Stefan Glienke 2019 Posted September 6, 2019 I think other languages also support this natively but here is the doc from C#. Share this post Link to post
Anders Melander 1815 Posted September 6, 2019 Oh, I thought you meant the "else after end" style but I guess you're shooting at "else...if" in general. Well yes, I guess a more flexible case would be nice, but I can also imagine the horrors people would create with it. Share this post Link to post
Stefan Glienke 2019 Posted September 6, 2019 (edited) 12 minutes ago, Anders Melander said: you're shooting at "else...if" in general Yes, the need for those given that you just check for different cases on the same thing (typical if x is button then ... else if x is edit then ... else if x is ... cases) just comes from case of syntax element being of limited use only. 12 minutes ago, Anders Melander said: I can also imagine the horrors people would create with it. Those horrors would not be worse than half a mile of if-then-else-if "ladders". Especially since in those you can easily hide some non conform pattern which can easily get unnoticed - for example checking x for 10 different types but then in some else if check y for something...) Language improvements of the category "syntax sugar" (i.e. something that could be done before but in a more convoluted way) should improve code readability by reducing the ceremony around the essence of what the code is supposed to do. Edited September 6, 2019 by Stefan Glienke Share this post Link to post
Anders Melander 1815 Posted September 6, 2019 41 minutes ago, Stefan Glienke said: Those horrors would not be worse than half a mile of if-then-else-if "ladders". True. I'm more worried about those that would use something like this just because it's a new smart way of doing stuff, regardless of whether it's a suitable pattern to use - and then I have to clean up after them. But then again, they pay me good money to do so 🙂 Share this post Link to post
Fritzew 51 Posted September 6, 2019 There could be done a lot in the language: In Elements: case myControl of Button: writeln("Looks like a button!"); CheckBox: writeln("This one's a checkbox"); else writeLn("No ide what this is!?"); end; or something like: var i: Integer; var s := case i of 0: 'none'; 1: 'one'; 2: 'two'; 3..5 : 'a few'; else 'many'; end; I like it. If somebody is interested in what can be done look at https://docs.elementscompiler.com/Oxygene/Language/ Using Elements a lot these days, it is always a shock come back to Delphi.... Not speaking about Lambdas..... Delphi: for item in List.Where( function(part : TPart): boolean begin result := part.isVisible; end ) do; Elements: for each item in List.Where(part -> part.isVisible) do; 1 Share this post Link to post
ŁukaszDe 38 Posted January 25, 2020 On 9/6/2019 at 4:00 PM, Jacek Laskowski said: I suggest you report to the tracker, maybe they will do: https://github.com/cnpack/cnwizards I like this style too 😉 I added a task, but unfortunately no response. I try GExperts but works same. @dummzeuch is is possible? Share this post Link to post
dummzeuch 1517 Posted January 26, 2020 13 hours ago, ŁukaszDe said: try GExperts but works same. @dummzeuch is is possible? I didn't follow this thread so I had to scroll way back to see what it is about. There are various options to insert/remove line feeds in if then else statements. Have you tried them? If they don't satisfy your needs or think there is a bug, please file a feature request or bug report on sourceforge, detailing exactly what you want. Of course you are also free to implement any necessary changes yourself an provide a patch. Share this post Link to post
ŁukaszDe 38 Posted January 27, 2020 21 hours ago, dummzeuch said: There are various options to insert/remove line feeds in if then else statements. Have you tried them? Yes I tried. No effect. Ok, I will add tasks to sourceforge. Share this post Link to post