Explanation for when to use semicolons in Oxygen

I understand the “why”, but not not always the “when”.

Example:

method DoSomething;
    begin
      DoSomeWork;
    end;

I can understand that I have to close of the method after the code block (end). But I find it confusing that I have to use it after the method name.

In my thinking the code block belongs to the method, so why use a semicolon there already?

I’m sure there are perfectly fine explanations for this, but wonder if there’s a good article that explains the reasons behind it.

Currently it’s not yet automated in my brain and have to look it up … :wink:

NB: I’m use to “C” languages, which may explain my confusion …

In C, semicolons are used to terminate statements. in Pascal, by contract, they are used to separate statements.

The main difference from this is that you don’t need a semicolon after the last statement in a block (although I consider it good style to have one anyways, com consistency, and to not have to worry about it when adding code or moving around code, later).

Aside from that, the only big difference to C I can think of is that C (somewhen confusingly, IMHO) wants a semicolon before else (I suppose to terminate the preceding statement, although conceptually that feels wrong), while Pascal does not.

That one indeed is odd. I’ve never thought about this and it does seem “wrong”, consistency wise, now that you mention it. What’s also(even more) inconsistent is that the semicolon after “end” is required, even if it’s the last one.

I don’t have a rationale for either of these two, aside form that it’s always been the case in Pascal, way before we came in with Oxygene. I could see an argument for relaxing the second one and making that optional, but I’m not sure of it’s worth the effort, given its 50+ year history…

3 Likes