Where does begin go? (I know. I'm sorry.)

Go down

Where does begin go? (I know. I'm sorry.)

· #1

I was going to let this lie, but I opened a colleague's unit today and now I have to ask.

Style A, begin on its own line:

pascal
if Count > 0 then
begin
  Process;
end;

Style B, begin at the end of the line:

pascal
if Count > 0 then begin
  Process;
end;

Which one is right? There is a correct answer and it is A.

Pete · thirty years of begin and end "It compiled on my machine."

Re: Where does begin go? (I know. I'm sorry.)

· #2

It's B. It has always been B. A wastes a line, and lines were expensive in my day.

Re: Where does begin go? (I know. I'm sorry.)

· #3

lines were expensive in my day

You had an 80 by 25 screen. You have a 4K monitor now, Dan. You can afford the line.

Pete · thirty years of begin and end "It compiled on my machine."

Re: Where does begin go? (I know. I'm sorry.)

· #4

Style C, for completeness, found in a codebase I inherited:

pascal
if Count > 0 then
  begin
    Process;
  end;

The author is no longer with the company. I'm told it was unrelated.

Re: Where does begin go? (I know. I'm sorry.)

· #5

The honest answer: pick one, write it down, and let the formatter enforce it so nobody has to argue. Lazarus ships with one (Source > JEDI Code Format), and it will happily settle this in under a second.

The settings file is the only place this argument should ever happen.

Re: Where does begin go? (I know. I'm sorry.)

· #6

let the formatter enforce it

I ran it on my code. It chose A. I'm filing a bug.

Re: Where does begin go? (I know. I'm sorry.)

· #7

i dont use begin or end i just put everything on one line

Re: Where does begin go? (I know. I'm sorry.)

· #8

We've seen your code. It's the only style that could make A and B agree on something.

Forum rules 1 to 10 apply. Yes, to you.

Go up

Sign in to reply