Title: Message
I don't really mind which line the begin goes on, but begins there have to be (for me anyway - also consider the number of coding standards which one can find on the net which specify begin..ends; any coding standard I work to does).
 
Consider this:
What happens when another developer comes along a year down the line and adds a line to your else.
 
If Enabled
    A := 1
Else
    A := 2;
    B := A+1;    <------------
 
The compiler is not going to interpret the code in the same way as a human reader might at first glance.  And yes, this does happen.  And if you don't see what I'm talking about with the above code, I'm afraid I've made my point. ;-)  Always having begin..ends makes future modification somewhat simpler and less error-prone.
 
Using begin..ends also means you never have to think about whether a line should be terminated with a semi-colon.
 
Using begin..ends means the problem that started this thread would never have appeared (that's why I'd never experienced it before).
 
Ross, no, the compiler is way smart enough, and will not generate more code.
 
Interestingly, you'd have thought that Borlanders on the Borland website would adher to Borland coding standards (http://community.borland.com/soapbox/techvoyage/article/1,1795,10280,00.htm)
 
This is probably one of those conversations that gets done to death far too often (yeah, I know I started it ;-), and I'm too set in my ways, so don't worry about arguing too much...
 
Cheers,
 
C.
 
BTW, I should probably confess at some stage, seeing as how I've been hanging around these lists for a while now; I used to work for Borland in Sydney doing Delphi work...


From: James Sugrue [mailto:[EMAIL PROTECTED] 
 
I don’t think it is more readable, especially at a glance.

 

I think

 

If Enabled

   A := 1

Else

   A := 2;

 

Is much more readable than including the begin ends.

 

Obviously all personal preference. If you look at the Delphi help or example code written by Borlanders on the BDN site it is interesting that even they have different approaches to begin end blocks, some choose option A from below some use option B.

 

I prefer

 

If Enabled

Begin

End;

 

Rather than

 

If enabled begin

End;

 

To me its more logical to have the begin and end in a line so you can see which block the code belongs to.

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Like Magic
 

I also use begin/end blocks for readability. If the code is easy to read - it is easier to maintain and less likely to have coding errors in the first place especially with loops and if statements.

The downside is it requires a little more typing but you were going to do that for your documentation any way :-)

 

Maurice

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Ross Levis
 

> IMHO, I'd consider the use of begin..ends essential in any Delphi Coding Standard doco. ;-)

Why make it more complex than it needs to be?

 

if Enabled then a := 1 else a := 2;

Compare that to:

 

if Enabled then begin

  a:=1;

end

else begin

  a:=2;

end;

I would imagine this generates more code and would be slower.  In my opinion, begin/end blocks are designed for when more than one statement is required.

 

Regards,

Ross Levis

_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to