One of the reasons I asked was that one of my clients insists on the use of alternative syntax instead of braces
By wary of clients that dictate to their developers in this way.
I consider the closing-block-syntax, be it } or endif, a nuisance. The endif style is worse because it is longer.
Compare:
Code: Select all
foreach ($a as $b): if ($a % 2 == 0): echo $a; endif endforeach
to:
Code: Select all
foreach ($a as $b) { if ($a % 2 == 0) { echo $a; } }
As closing-block-syntax imparts no additional information than that which indentation does already, indentation is visually more obvious than braces alone, programmers agree unanimously that indentation is essential, and programmers aspire to concision, I believe that indentation is, or should be, the dominant factor that determines nesting, where possible. As such, if PHP were to suddenly become whitespace sensitive and closing-block-syntax optional, I would eagerly omit closing-block-syntax in pursuit of concision despite never having programmed in a language, such as Python, where syntax is whitespace sensitive.
As PHP programmers, we have to make that conscious effort to look at our braces because is a requirement of the language (OK, fine) but I think it's a mistake to give closing-block-syntax any more visual significance than necessary; indentation is sufficient and essential in a way that closing-block syntax is not.
In light of all, that I brace like this:
and when lines exceed 100 columns, I ident:
Code: Select all
if (big long condition would go here foo bar blah blah) {
if (2) { /* sth */ } }
If you wish, you may view what a lot of code braced in that way looks like
here. At first you might find it unusual, as I did, but once you learn to read by the indentation alone reading speed will increase.
Occasionally you will see:
but I think this is preferable to:
N.B. In a professional situation, where there is a coding standard to adhere to, I would usually complain little before conforming.