Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Anders Ohlsson coding style

3 views
Skip to first unread message

Hrvoje Brozović

unread,
Feb 26, 2002, 11:28:08 AM2/26/02
to
I downloaded VCL scanner with source.
Very pleased to see that Anders Ohlsson himself
uses coding style similar to mine,
and different from coding style guides and VCL source.

We (Anders Ohlsson and humble me) use

for i := 1 to Limit do begin
blah blah
end;

if Condition then begin
blah blah
end;

while Condition do begin
blah blah
end;

Coding guides recommends and VCL source use

for i := 1 to Limit do
begin
blah blah
end;

if Condition then
begin
blah blah
end;

while Condition do
begin
blah blah
end;

It troubled me for the long time, but I managed not to make
a (illogical to me) switch.

And, now, when I know I'm not alone,
but accompanied with guys from Borland like Anders Ohlsson.
I'll never surrender.

To tell the truth, I use it more radically than he does,
i use begin end for cases with single line in between,
so I have no worries if I add second line in the block later.

So I use
if Condition then begin
Writeln( 'YESSS!!!!' );
end;

and he use

if Condition then
Writeln( 'YESSS!!!!' );

Is some efficiency penalty here for me?


Jesús Avilés Martínez

unread,
Feb 26, 2002, 11:34:25 AM2/26/02
to
Hrvoje Brozović wrote:

I use this way begin..end blocks too. I´m not from Borland but i know
that we are more than you, Anders Ohlsson and me.

I have a difference with you. If a begin..end block is not needed i
don´t use it, so i code:

if condition then
sentence;

--
JAM - Relájate y disfruta...

John Herbster

unread,
Feb 26, 2002, 11:41:08 AM2/26/02
to
"Hrvoje Brozović" <hrvoje....@public.srce.hr> wrote

> Very pleased to see that Anders Ohlsson himself
> uses coding style similar to mine,
> and different from coding style guides and VCL source.
> ...

> Is some efficiency penalty here for me?

Hrvoje, The only penalty, that I can see is having to explain it.
Rgds, JohnH


Matthew Augier (dps)

unread,
Feb 26, 2002, 11:40:49 AM2/26/02
to
We all seem to have our own ways of coding pascal

I would write it as so

for i := 1 to Limit do begin
blah blah

For j := 1 to 10 do Begin
more blah
End;
end;

each to their own!!

Mat


John Herbster

unread,
Feb 26, 2002, 11:47:12 AM2/26/02
to
"Matthew Augier (dps)" <Mat...@DPS.uk.com> wrote
> ... I would write it as so

> for i := 1 to Limit do begin
> blah blah
> For j := 1 to 10 do Begin
> more blah
> End;
> end;

Mat, I prefer the same, including the alternating UC/LC to
help identify matching begins and ends. Regards, JohnH


Woody (TMW)

unread,
Feb 26, 2002, 10:47:38 AM2/26/02
to
"Hrvoje Brozovi" <hrvoje....@public.srce.hr> wrote in message
news:3c7bb75e_2@dnews...

>
> We (Anders Ohlsson and humble me) use

Me too!! I started about a year ago because I was taught using the
conventional style. The main reason I started was to reduce the
line count so I had a better picture of how many actual lines are
being compiled. I liked it so much, I just kept doing it.

>
> if Condition then begin
> blah blah
> end;

I also started doing multiple if statements this way:

if Condition1 then begin
blah
blah
end else if Condition2 then begin
blah
blah
end else if ...


--
Woody (TMW)

----------------------
If you try to fail, and succeed, which have you done?
George Carlin

Vincent Bergeron

unread,
Feb 26, 2002, 12:05:09 PM2/26/02
to
Hi!

> Very pleased to see that Anders Ohlsson himself
> uses coding style similar to mine,
> and different from coding style guides and VCL source.

I do not use the same coding style as you. It's only a matter of
"readability". If you find it more easy to read it your way, then go for it.
I find it more easy to read it my way, so I go for my way.

There's no good/bad coding standard. There's a Borland official way, there's
a Microsoft official way, there's a Clinton official way... every one have
their own particularities and differences. I put three spaces for
indentation, when Borland seams to put two.

There's some people who fight about the "right" coding standard. Is there a
"Ultimate Coding Standard" for everyone? I don't think so. It's coding
standard. It's like saying that your favorite color is not the best one.

I wrote these lines because I had a fight one time with a guy about coding
standard. He told me that he's way was better, I told him that my way was,
for me, the better way. The fight last for months and that post remind me
the fight.

So, to answer your question:

> if Condition then begin
> Writeln( 'YESSS!!!!' );
> end;

> Is some efficiency penalty here for me?

I don't think so. The begin...end block only indicates which line are part
of the condition. If you convert your way and the other way to Assembler,
you'll see that it generate the same amount of code.

for example
CMP 0,0 (The condition... which is true in this case)
JZ :cond_yes (If the condition is true, then go to label :cond_yes)

:cond_yes
your_lines
return

So, your way or the other way produce the same amount of code.

This is according to me. I maybe wrong on all what I said.

HTH

VB


Glynn Owen

unread,
Feb 26, 2002, 12:42:42 PM2/26/02
to
Matthew Augier (dps) wrote:

I do it the same way because it seems easier to read when the END
signals the end of its own indent level. As you say, though, to each his
own.

Regards, Glynn

Nick Hodges (TeamB)

unread,
Feb 26, 2002, 12:52:44 PM2/26/02
to
Hrvoje --

First, let me say that you and everyone else can code however you
want, and I don't care. I only post here to offer _my_ view......;-)

I use a begin..end block everywhere, even for single statements

if SomeCondition then
begin
Exit;
end;

and

if SomeCondition then
begin
DoThingA;
end else
begin
DoThingB;
end;

The reason that I do this is that if I want to add a line of code to
the block , I don't create a bug by going from

if SomeCondition then
DoSomething;

to

if SomeCondition then
DoSomething;
DoSomethingElse;

as opposed to what it really should be

if SomeCondition then
begin
DoSomething;
DoSomethingElse;
end;

Also, this makes debugging easier. For instance, it is hard to debug

if SomeComplicatedCondition then DoThingA else DoThingB;

as it is not always clear what the flow is.

In addition, I really rely on having my begin...end pairs line up.
One of the first things I do when I install Delphi is add these two
code templates

begin
|
end;

and

begin
|
end else
begin

end;

Lining up the begin end statements is key, and I never mind if they
get nested, as to me, nested begin...end's are always very clear.

Of course, this is entirely personal, and one should code however one
wants.


Nick Hodges
Lemanix Corporation
How to ask questions of techies --
http://www.tuxedo.org/~esr/faqs/smart-questions.html

Rudy Velthuis (TeamB)

unread,
Feb 26, 2002, 1:07:58 PM2/26/02
to
In article <3c7bb75e_2@dnews>, Hrvoje Brozović says...

> I downloaded VCL scanner with source.
> Very pleased to see that Anders Ohlsson himself
> uses coding style similar to mine,
> and different from coding style guides and VCL source.
>
> We (Anders Ohlsson and humble me) use
>
> for i := 1 to Limit do begin
> blah blah
> end;

I think it is horrible, but to each his own. I normally use a code
formatter that formats to my favourite style, if I must read other
people's code.
--
Rudy Velthuis (TeamB)

Keith S. Brown

unread,
Feb 26, 2002, 1:30:07 PM2/26/02
to
For what it is worth, my own $.02...

My writing style has evolved over the last 29 years. When I find a better
way... and I define better as making the code easier to read, easier to
understand and easier to modify without errors... I change what I write and
how I write it.

I have to.

Using a "poor" style is just too inefficient. A poor style is one that
promotes errors, or encourages misreading or is too difficult to understand.
I know because I learned the hard way. I made mistakes. I misread code. I
fixed unbroken code. I screwed up.

But I learned. And I am still learning.

The following RTF formatted paper shows where I was four years ago. In my
current style, I've changed some of the details, but the major thrust
remains the same.

http://www.ghg.net/chairouchu/CSCI3132/lectures/format01.rtf

Steve C McConnell's "Code Complete" is an excellent book and makes many of
the same points:

http://www.amazon.com/exec/obidos/ASIN/1556154844/qid=1014747848/sr=1-1/ref=
sr_1_1/002-4883652-2081647

Best wishes always...

Keith S. Brown


Bruce Roberts

unread,
Feb 26, 2002, 1:26:57 PM2/26/02
to

"Hrvoje Brozović" <hrvoje....@public.srce.hr> wrote in message

> Is some efficiency penalty here for me?

Can't say that I like your coding style, but to each his/her own. As to any
speed penalties for begin/end, there are none a run-time. Begin/End only
affect compilation they produce no compiled code.

Craig Stuntz

unread,
Feb 26, 2002, 1:55:38 PM2/26/02
to
In article <3c7bb75e_2@dnews>, hrvoje....@public.srce.hr says...

> I downloaded VCL scanner with source.
> Very pleased to see that Anders Ohlsson himself
> uses coding style similar to mine,
> and different from coding style guides and VCL source.

I like this style too, since you can see more of your code on a
screen at a time.

But the availability of code re-formatters makes the question no
more important than which color settings you pick for your editor, IMHO.
It's just personal preference, and it's easy to change.

-Craig

--
Craig Stuntz (TeamB) · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase WebLog: http://delphi.weblogs.com
InterBase PLANalyzer (Free IB optimization tool):
http://delphi.weblogs.com/IBPLANalyzer

Hrvoje Brozović

unread,
Feb 26, 2002, 2:55:41 PM2/26/02
to

"Rudy Velthuis (TeamB)" <rvel...@gmx.de> wrote in message >

> I think it is horrible, but to each his own. I normally use a code
> formatter that formats to my favourite style, if I must read other
> people's code.
> --
> Rudy Velthuis (TeamB)

Can you post good free customizable code formatter URL?


Hrvoje Brozović

unread,
Feb 26, 2002, 2:51:06 PM2/26/02
to

"Keith S. Brown" <keith.s...@jsc.nasa.gov> wrote in message
news:3c7bd42e$1_1@dnews...

>
> The following RTF formatted paper shows where I was four years ago. In my
> current style, I've changed some of the details, but the major thrust
> remains the same.
>
> http://www.ghg.net/chairouchu/CSCI3132/lectures/format01.rtf
>
Avoid / Use Table on page 1.6 is the exact thing I was talking about.


G Sharpe

unread,
Feb 26, 2002, 3:03:42 PM2/26/02
to
I like this formatter -- very customizable. Freeware.
http://www.dow.wau.nl/aew/delforexp.html

HTH
--
Grant

Rudy Velthuis (TeamB)

unread,
Feb 26, 2002, 3:13:47 PM2/26/02
to
In article <3C7BEA1E...@nospam.com>, G Sharpe says...

> I like this formatter -- very customizable. Freeware.
> http://www.dow.wau.nl/aew/delforexp.html

I would have posted the same. I also use DelForExp.
--
Rudy Velthuis (TeamB)

Mark Lauter

unread,
Feb 26, 2002, 3:48:36 PM2/26/02
to
> But the availability of code re-formatters makes the question no
> more important than which color settings you pick for your editor,

I disagree. There are wrong color settings and there are *right* color
settings. It is the most important thing in the world and I am on a crusade
to change everyone elses color settings to the ones I use. (toungue in
cheek)

I found something cool in color settings. I can change the comment color to
WHITE on WHITE and then I don't have to look at everybody's stupid out of
date comments anymore.

I wish people would not worry about hanging begins and instead would
concentrate on good naming conventions so I could read their code with out
having comments cluttering everything up. Comments belong as notes in your
object models, use cases, activity diagrams, etc... get them the hell out
of my code!!! aggg!!! <g>

Cheers mate,

Mark


Rafael Cotta

unread,
Feb 26, 2002, 3:45:20 PM2/26/02
to
It's just my point of view...

I don't even like to read code written this way.

And I love TABs. I do use this to ident anything, like this:

function Foo () : integer
var
i : integer;
j : integer;
begin
i := 0;
j := 3;

if (j > i) then
begin
(...)
end
else
begin
(...)
end;

while (i > j) do
begin
(...)
end;
end;

Note that I use TAB instead or " " + " " even on the beggining of the lines.

Maybe because I started coding with C. I woul love to use parenthesis on
Pascal for statements.

The only thing I didn't find a way to express are the try, except, finally
statements.

Rafael

Another thing that I do not like if "For" instead of "for", "Else", "If",
etc.
"Hrvoje Brozović" <hrvoje....@public.srce.hr> escreveu na mensagem
news:3c7bb75e_2@dnews...

Mark Lauter

unread,
Feb 26, 2002, 3:43:25 PM2/26/02
to
> > I like this formatter -- very customizable. Freeware.
> > http://www.dow.wau.nl/aew/delforexp.html
>
> I would have posted the same. I also use DelForExp.

Delfor is a god send. I wish someone offered one for JavaScript too.

I keep ending up with "d" everywhere in my JavaScript from hitting CTRL+D in
the hopes of getting it to format automatically. :)


Felipe Monteiro de Carvalho

unread,
Feb 26, 2002, 5:09:44 PM2/26/02
to
Hi,

> for i := 1 to Limit do begin
> blah blah
> end;

I don't know if it's your case, but when I started with Delphi I used to
do this a lot, because my first language was VB and this way my code seamed
a lot more like my familiar VB code (from MSs Standard VB code and the book
I used to learn VB), however, I learned Delphi from the help files, so I
eventualy changed to hundred percent VCL-like code, with two lines spacing
and everything.

Felipe


Saputra, Erwien

unread,
Feb 26, 2002, 4:02:32 PM2/26/02
to
Rudy Velthuis (TeamB) wrote:

>>We (Anders Ohlsson and humble me) use
>>
>>for i := 1 to Limit do begin
>> blah blah
>>end;
>
> I think it is horrible, but to each his own. I normally use a code
> formatter that formats to my favourite style, if I must read other
> people's code.
>


I like that one better. I am so influenced by Code Complete, by Steve
McConnell, so I wrote it like that. It is an excellent book, I
recommend it.

But I don't follow all Steve's advice for one line statement, I don't
use begin...end

so I use

for i := 1 to 2 do
blablabla...

because I am tired of nested begin and end that I do not need that make
it hard to read, I really don't like something like this

begin
if ... then
for ...
if ...
case...
end;
end;
end;
end;
end;

these nested end that I couldn't stand.

Saputra, Erwien

unread,
Feb 26, 2002, 4:05:57 PM2/26/02
to
Nick Hodges (TeamB) wrote:

> Hrvoje --


> In addition, I really rely on having my begin...end pairs line up.

>

> Lining up the begin end statements is key, and I never mind if they


> get nested, as to me, nested begin...end's are always very clear.


I prefer 'begin' at the end of statement so:

if ..... then begin
end <-- I know who's end is this, this one belongs to if

for .... do begin
end; <-- belongs to for

just like

case
end; <- very obvious belongs to case


> Of course, this is entirely personal, and one should code however one
> wants.

Completely agree. We are not starting 'war' here. But when I went to
university, I met somebody that didn't use whitespace at all. I hate it.

Wien.

Craig Stuntz

unread,
Feb 26, 2002, 4:31:09 PM2/26/02
to
In article <3c7bf4cf$1_1@dnews>, markl...@hotmail.com says...

>
> I found something cool in color settings. I can change the comment color to
> WHITE on WHITE and then I don't have to look at everybody's stupid out of
> date comments anymore.

We used to have that problem, but we worked around it by using the
"VCL comment style."

Keith S. Brown

unread,
Feb 26, 2002, 4:53:30 PM2/26/02
to
I agree.Good comments should not "clutter."

However, stripping out all comments regardless of relevance is something
like killing ants with a "thermo-nuclear device" -- you get a wee bit of
collateral damage.

Good comments provide the context in which the code resides; increase the
comprehension of the reader and describe the intent of the code. That
information, should in my opinion, reside with the code. For example,
imagine that you maintain legacy code where all that information -- if it
ever existed -- was separated at birth and now lost (and all code is legacy
code if you wait long enough).

Bad comments are like good politicians; they mislead, misdirect and confuse.

You might find the following power point presentation (How to write
Absolutely Terrible Software) amusing:

http://www.ghg.net/chairouchu/CSCI3132/lectures/TerribleSoftware.ppt

Good luck and best wishes

Keith S. Brown


"Mark Lauter" <markl...@hotmail.com> wrote in message
news:3c7bf4cf$1_1@dnews...
<SNIP>

Iman L Crawford

unread,
Feb 26, 2002, 6:01:17 PM2/26/02
to
"Bruce Roberts" <b...@attcanada.net> wrote in news:3c7c1217_2@dnews:
> statement it is matched to. It should, IMO, be matched/aligned with the
> begin that it logically closes. IMO its wrong thinking to match "end
> with if, for, with, or while".

My thoughts exactly.

--
Iman
`fast-forwards to a dark future, where people who couldn't be trusted to
transform Optimus Prime from a semi into a robot are suddenly skewering
their palms on soldering irons.' - Penny Arcade

John Herbster

unread,
Feb 26, 2002, 5:50:54 PM2/26/02
to
"Mark Lauter" <markl...@hotmail.com> wrote
> ... I can change the comment color to WHITE on WHITE
> and then I don't have to look at everybody's stupid out-of-
> date comments anymore. ...

Reminds me of when I was working on "well worn"
(i.e. extensively maintained) code originally written
by an owner of a company. His comments were
left in out of misguided respect by the maintenance
programmers, even though the comments no longer
applied.

-- on second thought, perhaps the programmers left
the erroneous comments in, because they were
following the adage: "If it works don't mess with it."


Hrvoje Brozović

unread,
Feb 26, 2002, 5:54:46 PM2/26/02
to

"Felipe Monteiro de Carvalho" <felipe...@bol.com.br> wrote in message
news:3c7bf836_1@dnews...
No, my roots are in Sinclair Basic and Z80 assembly,
with every line starting vith line number, and no idents possible at all.
I used similar style in Clipper, where you had to put ENDIF anyway.
Im trying to use this style in SQL where applicable,
But, to my own suprise, in C code ( plain vannila C for Unix only,
I found C on Windows total mess compared to Delphi ), I found myself
typing it in Borland style
if ( Condition )
{
bla;
}

and not my Delphi style
if ( Condition ) {
blah
}


Bruce Roberts

unread,
Feb 26, 2002, 5:43:53 PM2/26/02
to

"Saputra, Erwien" <erw...@nospam.codeline.dot.net> wrote in message

> I prefer 'begin' at the end of statement so:
>
> if ..... then begin
> end <-- I know who's end is this, this one belongs to if

The problem I have with this style is that with three exceptions (case,
try/finally, try/except) end has nothing whatsoever to do with the statement

Saputra, Erwien

unread,
Feb 26, 2002, 6:14:53 PM2/26/02
to
Bruce Roberts wrote:

> The problem I have with this style is that with three exceptions (case,
> try/finally, try/except) end has nothing whatsoever to do with the statement
> it is matched to. It should, IMO, be matched/aligned with the begin that it
> logically closes. IMO its wrong thinking to match "end with if, for, with,
> or while".


Yea... maybe it is not perfect, but it is more readable to me. And I
think exactly the opposite of your thought. 'end' means the end of 'if'
or 'while' or 'for'.

As long it is work for me and it conform to the coding standard in my
team, it does not really matter. ;)

Again, I am influenced by Code Complete and evolving coding standard in
my group. I used to use 'end' paired with 'begin', but the coding
standard in my group forced me to change, and I like it better since then.

Bruce Roberts

unread,
Feb 26, 2002, 11:26:19 PM2/26/02
to

"Saputra, Erwien" <erw...@nospam.codeline.dot.net> wrote in message

> Yea... maybe it is not perfect, but it is more readable to me. And I


> think exactly the opposite of your thought. 'end' means the end of 'if'
> or 'while' or 'for'.

End definitely does not mean end of if, while, or for. See the Object Pascal
(or is it 'Delphi' these days?) Reference manual.

> As long it is work for me and it conform to the coding standard in my
> team, it does not really matter. ;)

Very true.

Kyle Cordes

unread,
Feb 26, 2002, 11:53:52 PM2/26/02
to
"Nick Hodges (TeamB)" <nickh...@yahoo.com> wrote in message
news:fcin7uo7rlj92relr...@4ax.com...

> if SomeCondition then
> begin
> DoThingA;
> end else
> begin
> DoThingB;
> end;


Nick, I respect you greatly, but to my eyes (trained on the K&R C book,
the Sun Java coding standards, and the observation that reading code is
easier when you can see more of it on the screen), I find this a waste
of vertical space. You have 7 lines of text, and only three of them
have anything by syntactic noise. Of the vertical space I have to
spare, I prefer to spend it on separating sections of code in a
semantically meaningful way with white space

Recently, I've found that the Python way (a subject of many flame wars)
is elegantly terse:

if SomeCondition:
DoThingA
else:
DoThingB

... nearly zero noise, making it much easier to see the code.

Speaking of seeing the code, I also think it's silly that some code
editors default to making the keywords bold, so you end up with a whole
bunch of bold syntactic noise, and non-bold real code.


Within a single project, I think it's important to establish a shared
coding style. Across projects, I agree with the others who have said
"to each his own".

--
[ Kyle Cordes * ky...@kylecordes.com * http://kylecordes.com ]
[ Consulting, Training, and Software development tips and ]
[ techniques: Java, Delphi, ASTA, BDE Alternatives Guide, ]
[ JB Open Tools, EJB, Web applications, methodologies, etc. ]

Kyle Cordes

unread,
Feb 26, 2002, 11:47:27 PM2/26/02
to
"Hrvoje Brozović" <hrvoje....@public.srce.hr> wrote in message
news:3c7bb75e_2@dnews...

> I downloaded VCL scanner with source.
> Very pleased to see that Anders Ohlsson himself
> uses coding style similar to mine,
> and different from coding style guides and VCL source.
>

> We (Anders Ohlsson and humble me) use
>

> for i := 1 to Limit do begin
> blah blah
> end;


I do it this way also. I mentioned some related things on this page:

http://kylecordes.com/story-116-object-pascal-improvements.html

Kyle Cordes

unread,
Feb 26, 2002, 11:56:14 PM2/26/02
to
"Craig Stuntz" <cstuntz@no_spam.vertexsoftware.com> wrote in message

> > WHITE on WHITE and then I don't have to look at everybody's stupid
out of
> > date comments anymore.
>
> We used to have that problem, but we worked around it by using the
> "VCL comment style."

+1, Funny

:-)

Christian Aymon

unread,
Feb 27, 2002, 3:50:10 AM2/27/02
to
You are all wrong! The definitive coding style is my
own private and personal rectangular & compact dense style.
Here is a perfectly working example:

procedure II(var I_I : int64; _II : boolean); const II_ =
$8000000000000000; var __I : boolean; begin if _II then
begin __I := odd(I_I); I_I := (I_I div 2) and not
II_; if __I then I_I := I_I or II_; end else begin __I
:= I_I and II_ = II_; I_I := I_I * 2; if __I then inc(I_I)
;end end;

Chris

"Hrvoje Brozović" <hrvoje....@public.srce.hr> wrote in message
news:3c7bb75e_2@dnews...
> I downloaded VCL scanner with source.
> Very pleased to see that Anders Ohlsson himself
> uses coding style similar to mine,
> and different from coding style guides and VCL source.
>
> We (Anders Ohlsson and humble me) use
>
> for i := 1 to Limit do begin
> blah blah
> end;
>

> if Condition then begin
> blah blah
> end;
>

> while Condition do begin
> blah blah
> end;
>
> Coding guides recommends and VCL source use


>
> for i := 1 to Limit do
> begin
> blah blah
> end;
>

> if Condition then
> begin
> blah blah
> end;
>

> while Condition do
> begin
> blah blah
> end;
>

Tony

unread,
Feb 27, 2002, 5:36:46 AM2/27/02
to
My style has also developed over number of years. I like my Begin &
Ends to line up in terms of indenting. I also line up my Elses
as in
If Condition Then
Begin
Statement;
End
Else
Begin
Statement;
End;

but that and the number of spaces you indent by are a personal / team
preference.

Doing
If Condition Then Statement Else Statement is capital offence as far
as I'm concerned, after all it's not like were are running out of gaps
in between line numbers.
If I start having a nesting level beyond four I tend to to redesign
the code.
And I always use Begin & Ends to avoid this fella which I've seen
several times and it drives me mad.
If Condition1 Then
If Condition2 Then
Statement
Else
Statement;

It can be made to work but anyone who relies on it should be toted on
Beelzebub's fork until the universe ends.


Please keep spamming my email account. I don't mind because I don't read it.
"Cure Spammers for ever, Shoot the b*st**ds" Tony

Tony

unread,
Feb 27, 2002, 8:08:29 AM2/27/02
to
It was you who did frontpage wasn't it.

Go on admit it.

Manuel Algora

unread,
Feb 27, 2002, 9:54:39 AM2/27/02
to
On Tue, 26 Feb 2002 17:28:08 +0100, "Hrvoje Brozović"
<hrvoje....@public.srce.hr> wrote:

>if Condition then begin
> blah blah
>end;

What if there also an "else"? Consistently with the approach above,
one would use:

if Condition then begin
blah blah
end
else begin
bloh bloh
end;

Now, having the first "end" and the "else" at the same indent level is
mixing apples and oranges. That's why I believe the only consistent
approach is

If Condition then
begin
DoSomething;
end;

even for 1 only statement in the block. Then, when an "else" appears,
consistency is mantained:

If Condition then
begin
DoSomething;
end
else
begin
DoAnotherThing;
end;

That being said, I do as you & Ohlsoon when there's no "else", may be
because I still hope Delphi would eventually change to a Modula-like
syntax... (I know it's Utopia, but dreaming is free).

Manuel Algora
cen...@wanadoo.es

Iman L Crawford

unread,
Feb 27, 2002, 10:47:04 AM2/27/02
to
"Kyle Cordes" <ky...@kylecordes.com> wrote in news:3c7c6586_2@dnews:

> Recently, I've found that the Python way (a subject of many flame wars)
> is elegantly terse:
>
> if SomeCondition:
> DoThingA
> else:
> DoThingB

aaah, Python. If only Boa-constructor was usable.

Hrvoje Brozovic

unread,
Feb 27, 2002, 11:04:52 AM2/27/02
to

"Manuel Algora" <cen...@wanadoo.es> wrote in message >

> >if Condition then begin
> > blah blah
> >end;
>
> What if there also an "else"? Consistently with the approach above,
> one would use:
>
> if Condition then begin
> blah blah
> end
> else begin
> bloh bloh
> end;

No. I use:

if Condition then begin
balh;
end else begin
blah;
end;

BEGIN is allways last word in firts line of block

I'm trying to hide BEGIN because I see no reason
why they even exist in the first place.
DO in FOR and WHILE and THEN in IF is enougth
for parser to know where block begins.

But, there it is, we can't ged rig of it.

Look at REPEAT .. UNTIL.
It's inconsistant. But, all that said, I like OP very
much compared to C.
On the other hand, I miss ++, --, +=,
if ( some_var = SomeFunction( SomeParams ))
and things like that. But, again, I like OP very much.
And this newest thing, language called Delphi.
Ok. But to say it's always been called that way.
Unbelievable. I'm having great hopes and fears for
Borland in the same time.

Hrvoje Brozović

unread,
Feb 27, 2002, 11:14:42 AM2/27/02
to

"Felipe Monteiro de Carvalho" <felipe...@bol.com.br> wrote in message
news:3c7bf836_1@dnews...
No, my roots are in Sinclair Basic and Z80 assembly,
with every line starting vith line number, and no idents possible at all.
I used similar style in Clipper, where you had to put ENDIF anyway.
Im trying to use this style in SQL where applicable,
But, to my own suprise, in C code ( plain vannila C for Unix only,
( I found C on Windows total mess compared to Delphi ), I found myself
typing it in Borland style )

Jesús Avilés Martínez

unread,
Feb 27, 2002, 11:22:59 AM2/27/02
to
> No, my roots are in Sinclair Basic and Z80 assembly,
> with every line starting vith line number, and no idents possible at all.
> I used similar style in Clipper, where you had to put ENDIF anyway.

Like my roots too. First the Spectrum (BASIC and assembler), then a
IBM286 (i started then with standard Pascal and a bit of COBOL), and 4
years ago Clipper (the hell) and Delphi.
I keep my way in begin..end since Pascal.

--
JAM - Relįjate y disfruta...

Jeff Hamblin

unread,
Feb 27, 2002, 1:22:05 PM2/27/02
to

"Kyle Cordes" wrote:
> Nick, I respect you greatly, but to my eyes (trained on the K&R C book,
> the Sun Java coding standards, and the observation that reading code is
> easier when you can see more of it on the screen), I find this a waste
> of vertical space. You have 7 lines of text, and only three of them
> have anything by syntactic noise. Of the vertical space I have to
> spare, I prefer to spend it on separating sections of code in a
> semantically meaningful way with white space


I used to format code to conserve vertical space. Funny thing is, I find
HORIZONTAL space more pricey these days. What with class instance and
property names often being ten feet long, combine that with levels of
indentation... so I recently switched to the style Nick described.


> Speaking of seeing the code, I also think it's silly that some code
> editors default to making the keywords bold, so you end up with a whole
> bunch of bold syntactic noise, and non-bold real code.


I don't find bold noisy. I think it helps separate it from the other
elements of the code -- especially if color is used as well. The only thing
black and bold in my code editor are the reserved keywords. Visual
differentiation is the key for me -- I like to see strings, numbers,
identifiers and symbols distinctly, so I assign them each a different color.

But, of course, to each his own....

-Jeff Hamblin


Woody (TMW)

unread,
Feb 27, 2002, 4:07:40 PM2/27/02
to
"Bruce Roberts" <b...@attcanada.net> wrote in message
news:3c7c1217_2@dnews...

>
> The problem I have with this style is that with three exceptions
(case,
> try/finally, try/except) end has nothing whatsoever to do with
the statement
> it is matched to. It should, IMO, be matched/aligned with the
begin that it
> logically closes. IMO its wrong thinking to match "end with if,
for, with,
> or while".
>

I consider /end/ to be the end of a block, not really any
particular statement. Having it on the same indent space as the
beginning of that block makes more sense to me. However, if I were
to start putting begins on their own line, I would indent the
matching end the same as the begin. Fortunately, though, I got out
of that habit last year. :)

Woody (TMW)


Volker W. Walter

unread,
Feb 27, 2002, 4:32:14 PM2/27/02
to
> I downloaded VCL scanner with source.
> Very pleased to see that Anders Ohlsson himself uses coding style

But I beleive
Break;
belongs to the surrounding loop structure
I suggest indenting to the column of
for, while, repeat.

In the same way
Exit;
belongs to the surrounding
procedure, function, ..
and
Halt;
belongs to the surrounding
program, unit, library,
.

For example

function TfrmMain.ExcludeFile(const FileName: String): Boolean;
....
begin // function
........
if n > 0 then begin
....
for i:=1 to InfoNum do // loop
if ..... then begin
Result := ....
if Result then
Break; // loop
end
; // loop
FreeMem(Buf,n);
if ... then
.....
Exit; // function
else
end; // function

Jan Emil Larsen

unread,
Feb 28, 2002, 4:46:45 AM2/28/02
to

"Manuel Algora" <cen...@wanadoo.es> skrev i en meddelelse
news:13sp7u4temlgeeu64...@4ax.com...

> That being said, I do as you & Ohlsoon when there's no "else", may be
> because I still hope Delphi would eventually change to a Modula-like
> syntax... (I know it's Utopia, but dreaming is free).

I share your dream <g>.
Could we have it when we shift from "Object Pascal" to "Delphi"?


Ufuk Keskinoz

unread,
Feb 28, 2002, 6:35:35 AM2/28/02
to
I wonder how you could debug your code in your rectangular style :)
Ufuk,

Jan Emil Larsen

unread,
Feb 28, 2002, 6:38:12 AM2/28/02
to

"Ufuk Keskinoz" <uf...@sorrynoemaildue.spams> skrev i en meddelelse
news:3C7E1607...@sorrynoemaildue.spams...

> I wonder how you could debug your code in your rectangular style :)

If he can write that way, he surely don't need any debugging :-)


Rudy Velthuis (TeamB)

unread,
Feb 28, 2002, 7:44:26 AM2/28/02
to
In article <3C7D505E...@metrohm.ch>, Volker W. Walter says...

> if Result then
> Break; // loop
> end
> ; // loop
> FreeMem(Buf,n);
> if ... then
> .....
> Exit; // function
> else
> end; // function

Do you also regard regular function calls as external to the routine?
Why don't you also indent them with the rest of the functions (i.e. at
position 1)?
--
Rudy Velthuis (TeamB)

Manuel Algora

unread,
Feb 28, 2002, 8:10:59 AM2/28/02
to
On Thu, 28 Feb 2002 10:46:45 +0100, "Jan Emil Larsen" <j...@g-it.dk>
wrote:

He, he, he... When I first read the actual name of the language was
Delphi, my first thought was: "Once it is Delphi, it can eventually be
made into anything other than Pascal". Wonder if Borland has thought
the same...

Mind, I like the concepts behind Pascal, but syntax can be improved.
Just as Wirth himself discovered.

Manuel Algora
cen...@wanadoo.es

Manuel Algora

unread,
Feb 28, 2002, 8:07:17 AM2/28/02
to
On Wed, 27 Feb 2002 17:04:52 +0100, "Hrvoje Brozovic"
<hrvoje....@public.srce.hr> wrote:

>No. I use:
>
>if Condition then begin
> balh;
>end else begin
> blah;
>end;

I don't like this approach (which seems to enjoy some popularity),
because it doesn't follow concept/indent pairs consistency.

There's an execution block for "if", another one for "else". Those are
the primary levels. Thus:

If ...
else ...

Then there's the begin/end pair, which should be on the same (same
concept) level of indentation, but a different one from if/else
(different concept than if/else) (But more on this below). Thus:

If ...
begin
..
end
else
begin
,,,
end;

With your approach, you hide the "else", by putting it after an "end"
-which is the worst feature of that coding style, IMO- and alter
completely the concepts/indentation consistency.

>BEGIN is allways last word in firts line of block
>
>I'm trying to hide BEGIN because I see no reason
>why they even exist in the first place.
>DO in FOR and WHILE and THEN in IF is enougth
>for parser to know where block begins.
>
>But, there it is, we can't ged rig of it.
>
>Look at REPEAT .. UNTIL.
>It's inconsistant.

With this I agree completely. While begin/end encompass a statements
block, not every encompassing needs be done this way.

Now, if you remove the Begin, you would go for the Endif/EndFor
(Next)/EndWhile (Wend), instead of End, as these then match the
starting of the structure rather than a Begin -same as Until matches
Repeat. Then these "ENDs" would go at the same indentation level as
If/For/While.

Manuel Algora
cen...@wanadoo.es

Christian Aymon

unread,
Feb 28, 2002, 10:09:08 AM2/28/02
to
> I wonder how you could debug your code in your rectangular style :)

I use the cpu window, of course !

{;-)

Chris

BTW, I remember, many years ago, TurboPower or Blaise computing (I think)
had an application that could reformat a source file according to the
"rectangular style" (also replacing the identifiers by unique strings of "I"
and "_"). Doing so, it was possible to distribute the source code (for the
turbo pascal compiler) in a form that (almost) made any modification
impossible!


Iain Macmillan

unread,
Feb 28, 2002, 11:50:12 AM2/28/02
to

In article <3C7BC912...@gtstrans.com>, Glynn Owen <gl...@gtstrans.com>
wrote:

>>for i := 1 to Limit do begin
>> blah blah
>> For j := 1 to 10 do Begin
>> more blah
>> End;
>> end;

> I do it the same way because it seems easier to read when the END
> signals the end of its own indent level.

Remarkable.
I like this too, and I thought I was a bit idiosycratic, as I've never
before today seen anyone else support it. Now they are all coming out of the
woodwork!

-Iain.

Volker W. Walter

unread,
Feb 28, 2002, 1:47:17 PM2/28/02
to
> Do you also regard regular function calls as external to the routine?

Never. But from my point of view
Break; Continue;
Exit;
Halt;
are not used like regular 'procedures' .
They are used more like 'statements' e.g. FOR..; WHILE..;

If
Break; Continue;
are not surrounded by a looping statement then an error
'BREAK or CONTINUE outside of loop' is generated.

How can I write a procedure with such behaviour ?

Volker

Smola

unread,
Mar 1, 2002, 6:00:51 AM3/1/02
to

"Iain Macmillan" <he...@ariesps.co.uk> wrote in message
news:3c7e5bbd_2@dnews...

Me too, but it actually *is* less readable for other people, especailly
begginers where they just want to see:

<header>
<block>

and not:

<header><bl..
..ock>

:-))

0 new messages