by myfonj · 3y ago · 0 comments
Indeed, feels super unusual and tooling is lacking, but behold the concise rationality:
; const url
= "..."
; const contact
= { "firstName"
: "John"
, "lastName"
: "Smith"
, "address"
: { "streetAddress"
: "21 2nd Street"
, "city"
: "New York"
, "state"
: "NY"
, "postalCode"
: 10021
}
, "phoneNumbers"
: [ "212 555-1234"
, "646 555-4567"
]
}
; const result
= sendData
( url
, contact
)
; rejoice
( result
)
Beauty. N.B. those opening and closing delimiters "connected" by breadcrumbs of separators. Isn't it lovely?Most developers I know will immediately lit torches and grab pitchforks if you show them this.
(Personally, I'm using it sometimes for private doodling, and while reformatting obfuscated or exploring some complicated codes; mostly just to improve own reading comprehension.)
If you relax the rule to allow "single simple value" to be in the same line (so break the rule for "=" / ":" on the start of the line), it could look lie this [1]
The reasoning behind that is that it produced the cleanest diffs with source control - especially if you consider changing the first/last/only entry in a collection.
Consider the diff from removing the first phone number from your collection above, and compare that to removing it from
"phoneNumbers": [
"212 555-1234",
"646 555-4567",
],By which metric is that rational? IMO it is utterly unreadable.
> Most developers I know will immediately lit torches and grab pitchforks if you show them this.
Yes I will do just that now lol
Prettier was invented so we don't have to deal with this bullsh*t anymore. What a gift of god
In contrast of the conventional ("irrational") zig-zag pattern where: - starting delimiter is somewhere in the middle of the line (if not in Allman and similar style); - separators are mostly at the right end of the line, sometimes pretty far, depending on line length; - closing delimiter is mostly on the left. - Plus separators and delimiters can be scattered among single line, if they "fit" there.
Again, I'm not telling this is "good and YoU ShoULD USe thAT!1!", only that compared to rules of other conventions I see least amount of "rules" and "exceptions" in this. And it is usable only in syntaxes with separators (JS to some degree, JSON, CSS), not for languages where ";" must finish even the last statement in a block (PHP) - there you'd have dangling two characters.
As for readability, I concur, yet I'd be very cautious of raising judgments like "it is utterly unreadable". I know that readability is largely matter of habit and I'd not be surprised that if we lived in such "Haskely" alternative universe where this convention was a norm from the start, we'd probably scream in terror when confronted with "Prettier" ("Stroustrupy") conventions.
That "emphasis" you are talking about is probably just that they seem unusual so they draw attention.
I'd change careers if I had to format or read code like that...