4 ms·
Like the post author, I use Coffeescript+React -- and don't care for JSX. (I'd go further and say that XML of any kind has shown itself unfit for direct editin
by sandover 13y ago
Like the post author, I use Coffeescript+React -- and don't care for JSX. (I'd go further and say that XML of any kind has shown itself unfit for direct editing by humans, but that's a larger discussion.)
Coffeescript has its problems as well, though, and one of the glaring issues is cutesy syntactic corner cases. Some of these are ok, taken individually, when they make the code maybe slightly more terse -- or more clear. But in the aggregate, they can leave us with something that is baroque, off-putting to the uninitiated, and hard to maintain. That's pretty much what I see in code here.
Having the curly braces around an object literal be optional was a language mistake: it simply introduces ambiguity. It doesn't save many keystrokes, and it wastes the time of the people who may eventually have to read code like this
R.p null,
R.a href:'foo', 'bar'
R.a href:'foo2', rel:'nofollow', 'second link'
Quick, is rel:'nofollow' part of the same object as href:'foo2', or is is the second argument to R.a?
More alarm bells went off when I learned that we are using this Coffeescript clunker I did not know about previously: "beyond the first argument, the trailing commas are optional when you have newlines".
Wat? _Just the first line_ needs a comma? Did Ruby teach us nothing, folks? Irregular, tricksy syntax like that is a caterpillar, waiting to turn into a beautiful butterfly of a bug when some stranger innocently barges in to make a change 6 months from now.
Even if the language offers features like that, don't use them.
- jashkenas 13y agoThe language offers features so that you can use them well. Any bit of syntax can be abused. `))))))`, for example ;) Optional braces around object literals allow you to write lines like this: rectangle x: 10, y: 15, width: 500, height: 500 ... and having newlines separate elements in lists makes a ton of sense in a language where whitespace is significant: requires = [ "jquery" "underscore" "d3" ] ... and also helps with the famous trailing-comma-in-IE error and comma-first controversy. If you're writing something that's convoluted enough that the features aren't helping you ... don't use 'em.
- sandover 13y agoHi Jeremy, if you'll please pardon the the somewhat flame-y tone above -- and the Coffeescript language is 'done' so these subjects are mostly moot anyway -- my experience has suggested that: - optional braces cause more ambiguity (manifesting as either strange parse error messages on the front side, or bugs on the back side) than is warranted by the need to write: rectangle { x: 10, y: 15, width: 500, height: 500 } - newlines separating elements of a list is good, but it's really confusing to me why the following program would/should work with no comma after the "a": foo = (a, b, c) -> console.log a, b, c foo "b", "a" "r" Plainly, it _does_ work, but to me it feels like using a hole in my sweater to scratch an itch on my elbow.
- duckduckblert 13y agoI don't know coffeescript, but I'd guess it's because the first comma indicates "this is an argument list," so the next few items get treated with list/array syntax rules where commas aren't required. (Had this comment thread left open in my browser since Friday. Noticed no one replied so I figured "why not," even though I might be wrong :V)