throwaway_yy2Di 12 hours ago
link |
The syntax is broken. Things like operator precedence and associativity are the exact opposite of math conventions:
f x + f y // is f(x + f(y)) f g x // is f(g(x))
reply
upvote
jashkenas 12 hours ago
link |
Not quite -- the rule is pretty simple: Implicit function calls associate to the right, to the end of the line (or the end of the trailing block). This allows you to write code like this:
console.log inspect value
model.save(attrs).then -> ui.update attrs
rect.scale height * factor
... and have all of the results come out correctly, while leaving the code readable. If the rules were "more math-like" as you say, then none of that would work. Perhaps it would harmonize with special libraries that used functions (automatic-partial-application a-la Haskell) in a different way than JavaScript? does ... but that's not the world we live in. It's gotta harmonize with JS functions as they exist.
reply
upvote
throwaway_yy2Di 12 hours ago
link |
My brain isn't plastic enough to make this switch. :( For me, those code examples are uncomfortable to look at. backwards read to trying like It's
reply
upvote
jashkenas 11 hours ago
link |
Right-o. The trick is to "read" it like pseudocode, or like English-ish.
Log the inspected value.
Save the model, then Update the UI with the attributes.
Scale the rectangle by (the height times the factor).
The big syntactic difference still being the "model.save" vs "save the model" ordering of dot-notation. But them's the breaks.
reply
--
" The problem is that when you’re staring at a chunk of Scala code, you’re only seeing about 60% of the code. I’ve seen this issue with CoffeeScript?. You can’t actually read CoffeeScript? without automatically converting to JavaScript? in your head. So you need to already know JavaScript?. This is fine as that’s an extraordinarily simple language. "
---
Replace CoffeeScript? with ES6 https://news.ycombinator.com/item?id=8970081
---
TazeTSchnitzel? 6 hours ago
CoffeeScript? is supposed to be this nice Ruby/Python-esque sugar for JS. It does resemble those languages, but it's not nice, it's very... stabby. Indentation is unintuitive and makes code do completely different things (whereas in Python it just delimits blocks, and if you get it wrong the compiler will moan at you). Functions implicitly return the last value they produce. You can omit brackets in function calls - but only if there's arguments, otherwise you've accidentally made a NOP.
---