Jump to content
ŁukaszDe

Code formatter in CnPack

Recommended Posts

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
2 hours ago, ŁukaszDe said:

Is possible to set code formatter in CnPack to get:

It has a "begin style" but no "end style":

 

image.thumb.png.07a3c0513290936513e7d730558582a8.png

 

So my guess is: no.

 

Share this post


Link to post

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

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

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

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
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 by Stefan Glienke

Share this post


Link to post
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

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; 


 


 

  • Like 1

Share this post


Link to post
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×