by mirekrusin · 2y ago · 0 comments
Coffeescript is still better than js with many ideas - everything is an expression, comprehensions, existential operator, extended switch statement, chained comparisons overall terse, readable syntax.
Some things are terrible ie. type annotations through clunky comments.
I have a ton of respect for the language and all of the stuff it cross-pollinated into JS, but it’s an interesting object lesson in how a seemingly tiny design choice can turn out to be disastrous.
I guess when exploring uncharted territory it's a bit of a dice roll - you can't keep winning all the time.
Otherwise great contrib to advance frontier.
Coffeescript was before my time so I never used it, can you give an example of the problems this caused?
So what can happen is that you have some large block of code where, for example, near the top, you’ve said “x = 1”. Then, maybe a few hundred lines down you have a loop, and inside the loop you say “x = getWidget()”. You think you’re declaring a new variable, but actually you’re reusing a variable from the outer scope. There’s no way to know if you’re accidentally doing this except to search the entire enclosing scope.
It’s even worse in the other direction. You have a small block way down in a function where you’ve said “x = getWidget()” and this is all fine and correct. But you need to add something to the top of the function, and you add “x = 0”. You’ve now retroactively changed the scope of some random variable you weren’t even thinking about.
Edit: Actually my memory’s a little rusty, but I think they actually removed any kind of block scoping entirely by version 1, but everything I said above still applies to nested functions, which you tend to use liberally in CS.
JavaScript has had this for a bit now and it is really nice.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
if window?
env = 'browser'
...
is equivalent to: if (typeof window !== "undefined" && window !== null) {
env = 'browser'
...
}
But yes, nullish coalescing and optional chaining that came from existential operator are good.