by dccoolgai · 10y ago · 0 comments
...Because it gets the hell out of they way and holds your coffee for you and doesn't slap it out of your hand and throw a tantrum because it was actually a medium coffee...and it gives you the simplest no-BS object/array literals you can get...IMO opinion everyone wailing and beating their chest bemoaning the fact that JS got where it is fails to understand that it got there because it the "UX" of coding JS is just a lot more pleasant - and you can treat it as a compile target and do your work in a more type-obsessed thing like Typescript if that's your cup of tea without imposing on the underlying "hackability" of the language.
I really don't think that:
{
"foo": "bar",
"baz": ["quux", 1, true]
}
is simpler than: ((foo bar)
(baz (quux 1 true)))
Quite the opposite, really. [["foo", "bar"], ["baz", ["quuz", 1, true]]]
making it a non-issue?With the right predicates, anything is possible grin
I think that context unavoidable: one can't just read a JSON value into a generic data structure, or even into a typed structure: one has to apply the types of one's business logic (e.g. 'user-id' must not only be a string, but a string beginning with either 'E' or 'C'). In that context (pun intended), then it makes sense for equality comparisons to be at the business-object layer, not at the freshly-deserialised JSON object layer.
Well, S-expressions, which can be used for Lisp code, but can also just be used for plain data.
> a lot of what I consider the "No-BS object system" occurs after the literal is declared - adding and manipulating properties, etc.
Yeah, it's definitely convenient to use, even more so than Python's objects. I prefer a stronger type system for my own software though.
(map (foo bar)
(baz (quux 1 true)))
But you might reflect on the fact that JSON uses an ordered sequence of bytes to represent an unordered collection of properties and values.In practice, you can use as much or as little typing as you want, and the compiler will occasionally tell you "I think you're doing something dangerous here", but even then you're only one <any> away from ignoring its generally good advice (or more sanely, you would annotate the ambiguous bits a bit better so typescript understands you really meant to do that.)
But otherwise, all the usual js hacks still very much apply.
Anyway, that's why typescript is my cup of tea|coffee.
Is it pleasant UX that you can put petrol in your diesel car because the nozzle fits? Would it be pleasant UX to have your bank let someone withdraw money from your account without ID? Bleach bottle with no safety cap?
Also the laid back kid of JS will throw a tantrum if the coffee is not a coffee. He'll throw the tantrum at your customer though (at runtime), not your developer (at compiler time). Which arguably is a good UX for coding but not the bottom line.
I like that the kid just holds the cup and pours it when I tell him to. If I wanted him to pour coffee and gave him a cup of beer, I'm ok saying that's my fault. I'd still rather have the kid. Having a guy that only accepts "Large cups of coffee" is necessary at lower levels (c), but keep it out of my scripting language.
In Java you get an annoying compiler error.
In JS you get a trashed engine at runtime.
Yeah, and good luck dealing with that remote API that now gives you an extra field in the JSON or XML, and your compiled client in a few thousand workstations needs to be updated and redeployed because of said fit.
Java C# and every other decent typed language has good serialization and deserialization support. The extra field poses no problem.