Discussion:
Shortcoming in Delphi source beautifier/formatter
(too old to reply)
Skybuck Flying
2011-09-11 10:50:26 UTC
Permalink
I want my code to look as follows:

if a < b then
begin
// ...
end else
begin
// ...
end;

I do not want it to look like:

if a < b then
begin
// ...
end
else
// ^
// this makes it hard to see to which branch the else belongs
// when there are multiple branches.
begin
// ...
end;

Unfortunately it does not seem possible to configure the source formatter so
it does the first ?

Bye,
Skybuck.
Skybuck Flying
2011-09-11 10:59:16 UTC
Permalink
Another short comming:

I do not want the code to look like this:

if ch <> '*' then
begin
if ch = 't' then
begin
nextch;
prtables := ch = '+'
end
else
if ch = 'l' then
begin
nextch;
list := ch = '+';
if not list then
writeln(output);
end
else
if ch = 'd' then
begin
nextch;
debug := ch = '+'
end
else
if ch = 'c' then
begin
nextch;
prcode := ch = '+'
end;

I don't want the stuff beyond else to be indented.

Instead it should look like:

if b > a then
begin

end else
if a < b then
begin

end else
begin

end;

So absolutely no indentation or line breaks in end else and after else.

Currently this is not possible to configure so this sux bad in the source
formatter.

Bye,
Skybuck.
Skybuck Flying
2011-09-11 11:06:13 UTC
Permalink
The source formatter is making it really hard on itself it seems.

All it has to do is simply add these options:

1. Line break before end
2. Line break after end
3. Line break before begin
4. Line break after begin
5. Line break before if
6. Line break after if
7. Line break before else
8. Line break after else

And so forth... perhaps also:

1. Indent before begin
2. Indent after begin
3. Indent before end
4. Indent after end
5. Indent before if
6. Indent after if
7. Indent before else
8. Indent after else

And so forth.

So it needs a lot more fine grained tuning.

Bye,
Skybuck.
Muscipula
2011-09-15 21:26:05 UTC
Permalink
Hi

It ain't a case of beautiful looking code it is a case of a
practicable method of formatting your source. For example the
following line has a weakness when it comes to debugging the code...

if a>b then a:=c else if a<b then a:=b;

When you debug the above line you never know which side of the branch
is executed when

if a>b then
a:=c
else if a<b then
a:=b;

Following the debugger you know which way the conditional branch
evaluates.

Also indenting blocks also serve a similar purpose

a:=7;
while a>0 do
begin
b:=random(a)+1;
if b=a then
dec(a);
end;

Just a silly random countdown algorithm just to demonstrate a simple
indenting format for source code. Making the begin..end blocks clearly
shown makes debugging much easier.

So it ain't a case of making the source look pretty, it is a case of
practicable use.

Muscipula
Skybuck Flying
2011-09-16 01:43:01 UTC
Permalink
The source beautifier is actually bugged as well.

Try beautifieing P4 or P5 source code.

P5 is a pascal compiler.

Delphi's source beautifier screws up somehow.

It has to do with missing semi-colons which apperently is legal in pascal.

For example your example could be completely without semilons... ?!?!

Bye,
Skybuck.

Loading...