Tldr
Layout is part of the syntax of programming languages, even if it isn't defined as such and the compiler ignores it.
Long read
One thing to note is that the actual syntax of many programming languages as defined in the book, does not match the perceived syntax as coders know it.
That is, in many programming languages the whitespace is not significant to the compiler. But whitespace is considered significant by coders.
If you start from that idea, then the real question is not why the code isn't more compact, but why it contains all those extra braces and semicolons (which reiterate indentations and newlines).
What you often get in C-derived languages, is a belt-and-braces approach, where the whitespace exists predominantly for the human reader, and the punctuation actually exists as a supplement purely for the compiler.
Another thing to note is that humans don't by default read like computers do. Computers parse strings serially and have no intrinsic two-dimensional representation. Humans appreciate matters like layout before they have even started reading the characters.
To emphasise the point, the human reader probably gets the gist of what's going on here, even without the semicolons and braces and brackets:
public function getName()
return 'webauthn'
public function newKey( array $data = [] )
if empty( $data )
return WebAuthnKey::newKey()
return WebAuthnKey::newFromData( $data )
In fact all that additional punctuation only seems to become necessary when layout principles seems to be violated.
In terms of why this particular style of layout is most commonly used, I suggest because it is the most convenient and flexible way to represent trees or hierarchy.
Why are hierarchies important? Because basically every mainstream language follows the block-structure principle (the justification of which would be another question!).
In your "compact" version of the code, clearly a lot of layout principles have been discarded, and what exists is an anomalous layout that relies much more heavily on what I consider to be the "compiler crutches" - the things that are in the language mostly for the benefit of the compiler, not for any sensible human reader.
The example of compactification you give is simple enough, but quite obviously with more nested blocks and more statements per block, either you would have to revert to the normal style of layout (which you consider extravagant), or else the code would become very messy indeed. Messy for the human I mean - the compiler can read things that no human coder would consider reasonable.
Also, making more complicated additions to your code would require not only relevant statements to be added, but also for the overall layout to be uncompactified.
For most, the benefit of occasionally saving a line or two, is just not worth consideration.