Quoting James Sugrue <[EMAIL PROTECTED]>:

> I'm not saying trying to turn this into "I'm right your wrong" thing,
> because it comes down to personal preference I guess, but here is what I
> was
> talking about, taken from Delphi 4 Developers Guide by Steve Teixeira and
> Xavier Pacheco.
> 
> <SNIP>
> 
> OBJECT PASCAL
> Parenthesis
> There shall never be white space between an open parenthesis and the next
> character. Likewise, there shall never be white space between a closed
> parenthesis and the previous character. The following example illustrates
> incorrect and correct spacing with regard to parentheses: 
> 
> CallProc( AParameter );  // incorrect
> CallProc(AParameter);    // correct
> 
> Never include extraneous parentheses in a statement. Parentheses should
> only
> be used where required to achieve the intended meaning in source code. The
> following examples illustrate incorrect and correct usage: 
> 
> if (I = 42) then              // incorrect - extraneous parentheses
> if (I = 42) or (J = 42) then  // correct - parentheses required
> 

This is another example of a programming style. There is nothing to say that 
their choice of style is any more valid than the other.

This should be distinguished from doing something one way or the other because 
the compiler dictates it e.g.

for (i := 1 to 10) 

is flagged invalid by the compiler.

I can write something in JavaScript that looks like this

    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt
(0)!="#"){

(that's all one line)
and it is syntactically correct and will be compiled. That isn't the same as 
being easy to understand. You can write incredibly complex statements in C++ 
that exploit to the maximum extent the languages's terseness, the power of 
complex operators and the ability to compound operators - and in doing so make 
an incredibly difficult task for someone who has to come along later and 
maintain the programme. 

I deliberately limit the complexity of statements by breaking them down so they 
are easier to understand, but also so they aren't wrapped over multiple lines. 
Thus, writing

x:= DataModule.Table.FieldByName('X').AsInteger;
if (x = 2) or (x = 4) or (x = 5) then begin

is obviously preferable to writing

if (DataModule.Table.FieldByName('X').AsInteger = 2) or 
(DataModule.Table.FieldByName('X').AsInteger = 4) or 
(DataModule.Table.FieldByName('X').AsInteger = 5) 

to use an extreme example. So I write 

DoDelete := MessageDlg...
If (DoDelete = mrYes) then begin

because it results in shorter lines of code that are easier to understand.

---------------------------------------------------------------------------
  New Zealand Delphi Users group - Offtopic List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to