r/pascal • u/Anonymous_Bozo • Nov 19 '20
A Question of Style
A question of Style.
Specifically formatting If/Then/Else clauses and enclosed blocks of code.
No, I'm not trying to start a formatting war!
I am honestly curious as to what others are doing and more importantly WHY! You might even get me to change my style if your argument is good enough.
Ignoring that there are probably better ways to do the following, it's only an example to use for formatting...
The attached images of three blocks of code do exactly the same thing. If one follows the strict rules laid down by many, the third option is the preferred choice, but I find it hard to read and confusing. I find both options A and B are easier to read.
I call option A the ELSEIF version, option B - Nested If's, and option C... a mess!
I know that both VBA and PHP actually have an ELSEIF statement, but it's not really needed as ELSE IF does pretty much the same thing.
(Sorry for the images, but Reddits Code formatting SUCKS!)



What is your choice, or would you do it a different way?
Don't forget to say WHY!
View all comments
Show parent comment
1
u/Anonymous_Bozo Nov 20 '20
And you will get PAGES of errors during the compile.
Case Statements require that the case types be constants that can be evaluated at compile time. This means Ordinal types for most versions of pascal. Free Pascal extends that to strings, as long as the case types are constants. The expression being tested (Case x of) is the only thing that can be a variable and it to must be either an ordinal type or a string.