Post 02 Jul 2014, 07:38 by Lewin
Hints look good, however I really wouldn't advice to omit "begin...end"s to make code shorter.
These things are obviously a matter of taste. In Pascal most people put the "begin" on a separate line, instead of on the same line like this:
- Code:
if stuff then begin
DoThing;
DoAnotherThing;
end;
Something;
The above code already jumps out as wrong to me, because I can see two indented lines but no expected "begin" before the indentation. I would write it like this:
- Code:
if stuff then
begin
DoThing;
DoAnotherThing;
end;
Something;
If you always write it with the begin and end on a separate lines then you don't make the mistake of omitting them because the code looks wrong without them (at least it does to me after having done that for years). Using an editor with syntax highlighting helps with that because the begin..end are bold, and you automatically start expecting to see them before/after every indentation. You'll find most Pascal/Delphi/Lazarus code looks like my example above with the begin on a new line and omitting begin..end if there's only one statement.
I find omitting the begin..end can make code a lot neater and readable (15 lines down to 8 in the hints wiki example).
But as I said, there is no right or wrong answer to coding standards like these, it's about personal preference and complying with the standards of your development team.