361 points · by alangpierce · 9y ago · 219 comments
Coffeescript was a bit different. It meant fewer lines of code, not more. It had significant whitespace and some other Python-inspired idioms like array comprehensions and object comprehensions. Most importantly, Coffeescript was a new language and didn't have to re-implement deleterious Javascript features like the == vs === distinction, undeclared vars leaking to global scope, baroque keywords like "with", etc...
That said as others have pointed out, ES6 did borrow many good features from CS and CS is slowly dying. Fortunately other languages like Elm and, to a lesser degree, Reason have offered even more compelling "footgun free" alternatives.
Modern JS has standard HoFs (on arrays) and an iteration protocol.
> undeclared vars leaking to global scope
Strict mode (which syntactic ES6 features enable by default e.g. class contents are in strict mode always).
> baroque keywords like "with"
Which can trivially be linted away.
> ES6 did borrow many good features from CS
Not really from CS, rather from similar (much older) sources CS got them from.
Currently works with Flow syntax, but not yet the actual flow checker - would love help making that happen!
The benefits were mainly for Ruby devs coming to Node from Rails, and were easier to see before JS itself added most of the syntax conveniences that Coffeescript introduced.
In particular, attempting to use it with npm modules is an exercise in tedium, as its module resolution constantly breaks and bizarre, undefined behavior does not stop happening. I've found dozens, maybe hundreds of similar reports online, with no solutions offered. There are all sorts of arbitrary gotchas with its configuration as pertains to this and other things. "Oh, don't use outDir and it'll work."
While it has great and straightforward integration with VS Code, it has disastrous integration with Visual Studio 2015 and 2017, the latter of which does not even support updating the bundled TS version at will without registry hacks. While TS emits code even in the case of errors, in many situations, Visual Studio refuses to complete the build process in case of TypeScript errors.
For an ES6+->ES5 transpiler, it is also very strange in that it polyfills some things but not others, such as Promises and Maps.
TypeScript has ultimately brought an unacceptable overhead to my project. It does not get out of the way as soon as you attempt to use it with the rest of the ecosystem. There belies its arrogance: it treats JavaScript as a second class citizen and favors Typings (additional files that assign types to plain JavaScript libraries). But in most cases, Typings are outdated, or nonexistent. Only recently has support for plain JavaScript libraries gotten better, with the AllowJS and CheckJS flags, the latter of which Visual Studio 2017 does not recognize for whatever reason.
In my view, it comes with so much baggage that it's probably not worth using. Some of the solutions proposed by the project maintainers amount to writing boilerplate just to support JavaScript functions. It's essentially C header files: you have to write module declarations for certain plain JavaScript libraries to work. There are different versions of this boilerplate that you could be asked to write: you may be told to write a typings file (i.e. declare every single function of the library you want to use in a separate file, and add it to the project, possibly using ///<reference> in certain specific scenarios). There are also ad-hoc declarations of modules and constants/globals that you may or may not need to write (there is no idiom here, and the language regards this as going off-road).
You used the word "arrogance", and that's exactly what it is. The fact that it's a transpiler (and a poor one at that) makes no sense to me. It's reach exceeds it's grasp and it burdens developers with the task of fixing it's own failings.
Before anyone says "you just don't like typed language", stop right there. I do like Typed languages. Typescript is just very very poor when compared to other modern typed languages.
It's such a horrible development experience that I'm looking for a way out of web dev. It's clear the community has gone nuts for it. And the Java back enders who seem to have an unwarranted amount of influence in this world are forcing it onto front end developers simply because it looks like Java. And damn you Angular2 for making all of this worse. You're a clunky and bloated framework already, but not content with ramming your flawed methodology down our throats, you've gone and stuck Typescript in there too, seemingly just out of spite.
I fear Typescript is here to stay. If that's the case, I'm moving to Swift and iOS, or changing career completely.
First off, I really like the language design. It's typing but without the red tape or the ceremony that makes languages like Java so bloated and painful. Duck typing works nicely. Not having to name every little type is a breath of fresh air. Typing is optional and easy to add when needed. It works well with both VSCode and IDEA.
On the flip side, I've found myself spending far too much time trying to find the right typings to match the libraries that I use. It's very easy to end up with odd conflicts. Reminds me of the (hypothetical, of course) experience of finding subtitle files to match a bootleg movie. More often than not, they are off by five seconds, or jump out of sync midway due to been for the director's cut or whatever. Typescript typings are a bit like that; they get you 98% of the way but the last 2% can be surprisingly frustrating. That being said, after it has become possible to install typings from npm, it has become somewhat more manageable.
But yeah, there is a premium to Typescript, like there is to unit tests. It's not a premium that I want to pay for a project unless I'm pretty sure that there is a payoff down the road.
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
When using Webpack you can run `webpack --watch` or run the Webpack dev server where it will instantly process changed TypeScript files to provide an optimal iterative dev work flow:
http://docs.servicestack.net/templates-single-page-apps#deve...
Although Typescript started a bit as you say, complex tooling, had to write external type declaration to have the typing for external libraries (but they are optional, not having them only means not having typing on externals, which is fine in many cases, so not in the way at all), but overall, typing provided so many benefits it was already worth it to me: litterally saved me hundreds of bugs found at compile-time, and keeps the maintenance of the code base cheap and easy. But typescript evolved a lot, now the typing declaration are based on npm, the compiler got faster by an order of magnitude, it provides services to the IDE, and so on.
I just wouldn't start a new project with a reasonable expected lifespan without typescript.
> it has disastrous integration with Visual Studio 2015 and 2017
Yes, this is true. TS, like ES2015+, really wants to have a complete client build system. All the attempts to integrate it into the VS build have been disastrous, from web essentials on down. And you won't learn that from MS. All the problems you mention went away for me as soon as I began to treat the client code as a first-class citizen.
Move all the client code outside the solution and give it its own build, and a lot of these problems go away. I never have problems importing npm modules, and I haven't written a ///<reference> comment in over a year.
> Some of the solutions proposed by the project maintainers amount to writing boilerplate
It sounds like that's a problem with the project maintainers rather than the language.
sass is more than just syntax sugar.
ES6 is supported natively, it's an actual standard not a language a single person came with, it avoids a build step, it has all of Coffeescript features and more by this point, and Coffeescript's momentum has slowed. Seems a no-brainer.
And as for concision, ES6 seems just as concise. At worse you need an extra } or so, which I like to have anyway.
No! It seems you've never learned Coffeescript well enough to know the differences, just like too many other ES6 proponents.
There's nothing especially interesting Coffeescript has over ES6/7.
ES6 obviously deals with some of the issues that CoffeeScript was intended do. That's awesome. Unfortunately, it's still difficult to go back to what seems like the relatively baroque syntax of Javascript afterwards, as someone who has a bit of a vendetta against over-syntax. SO MANY BRACKETS.
In particular, there was CJSX - JSX with CoffeeScript. Writing React components using it was an absolute joy in comparison, and helped eliminate a lot of noise – making it much more obvious what a component was doing.
But yeah, it's been hard to convince others that it's worth the investment, when honestly it's really just a personal preference at this stage.
})
})
})
})
})
})
},
})
})
})
})
})
})
},
Whatever do you mean?It's incredibly clear, allows clean and concise error handling, and is easy to use.
There are still some other cases where the mess of brackets is overkill, other than callback hell.
It's a rough superset of ES7+JSX+Flow, built on Babel. Integrates pretty well with a bunch of tools like ESLint, should be much more future-proof than coffeescript.
Would love your thoughts if you'd like to give it a try - http://lightscript.org
"No brackets, it's so pretty!" is fine, but other languages don't make what feel like random guesses as to where your delimiters are, they use a different syntax to mark the blocks.
Personally I prefer to just mark the blocks myself rather than hope that the compiler infers it correctly, whether that's done with indentation as in Python, keywords like "begin" and "end", or with C-style bracketing. I even find comparatively mild things like Ruby's inferred parentheses grating.
There's no reason not to put an opening and closing mark. You're already thinking in delimited terms when you're writing the code, there is no real extra cost to throwing in the indicators, and it makes it so much easier to figure out what's going on when you go back to debug, when you try to read the code after months, or when your text editor is trying to help you out with folding and the like.
I agree with everything you've written and I'd like to note that even Ruby has degenerate cases where you're forced to use parenthesis around things because the parser can't figure out what you mean.
I have an instant dislike for any language that tries hard to make code 'pretty' by removing such indicators.
And to be clear, there's a difference between a concise version of a syntax, such as C#'s lambda syntax, and creating inconsistencies in your language by trying to remove syntax that cannot be universally removed without creating ambiguities.
The former is welcome, the latter is not. Even Ruby has such degenerate cases.
And I like Ruby, but I dislike that design decision.
How does one objectively measure this? I strongly prefer to read less code, to make fewer mistakes (I.e. closing brackets).
The only issue I foresee is tools being built around the use of ES6 that compel you to abandon it.
I've learned that less is better. I don't use JQuery, I don't use Lodash. I don't use React, I don't use ImmutableJs, I don't use Webpack or CommonJS. All of these tools are more a burden that a blessing and you just end up stacking on 100 dependieces asking "Is this really better?"
I learned this lesson with Cucumber/RSpec/Caybara and etc.. I started asking why I had to use these over plain old TDD and so I used TDD for a month and I found out everything was totally fine.
I don't even really use Arel in ActiveRecord. I just write raw SQL that serves JSON directly back. I made it easier for me to organize SQL in partials just like views and to injects variables and conditions into my SQL.
I went to great lengths to evaluate all these tools because as a work-form home contractor I can afford the time, and the "what if" really bothers me.
I still working in Rails with Sprockets and CS and I write all my SQL by hand.
Less is Better.
All these kids want to do a bunch of busy work and for no good reason. It makes the feel productive.
I have tried dropping CS but the difference in productive was too great to drop. Its not that I'm married to CS its that it does what it says. It makes your JS concise so you can be more productive.
I felt AngularJS dying and so I spent 3 months researching React and building client apps in React. I just didn't get all the work extra work and settled on Mithril.
The hardest thing was giving up writing HTML-like templates like I did in AngularJS but I remember that was my first aversion to AngularJS where I swallowed the medicine. I had to swallow more medicine to unlearn that. Mithril paird with CoffeScript makes writing markup in CS a joy. If I had to do that in regular JS I could see why people would be compelled to use ugly JSX.
This is pretty patronizing. Not everybody who uses these tools are "kids who just want to do busy work". In fact, I'd argue that "kids" (or more accurately, "new developers") are the least likely to want to do busy work, as they'd prefer to be able to build stuff fast. (And for the record, I feel like I suddenly started doing a whole lot LESS busy work once I got decent with React.)
I generally agree that "less is better", until you have to start re-inventing solved problems.
> I learned this lesson with Cucumber/RSpec/Caybara and etc.. I started asking why I had to use these over plain old TDD and so I used TDD for a month and I found out everything was totally fine.
RSpec is just a testing framework though? It's not something you chose instead of TDD...
I think the takeaway is that before you assume you have an "unsolved problem" due to all the buzz/hype around $HOT_LIB, study a little more, try it with the upstream, make sure it's really necessary before you get a tortured contrivance of a stack in place. Consider the cost of adding more dependencies and whether the functionality you're getting from the third party lib is really worth it.
Let's be honest, the core problems you're likely to run into on any given day are probably "solved" pretty reasonably by any language that's at the appropriate level for the problem space and has seen significant use over the last 10 years. You're more likely to be reinventing the wheel by pulling in $COOL_GITHUB_PROJECT than you are by taking a few more lines to implement with the stdlib.
You're grossly underestimating the proportion of new entrant workers in the ICT industry that don't have an aptitude for programming, and cover their tracks by appearing to be productive.
I'm going to go out on a limb here and guess that you don't work in a large team with other developers, maintaining a common codebase.
I am pretty sure this is the case. I have worked with small and large teams. Large teams usually have a lot more abstraction in terms of their architecture. So there is most likely a "backend" app that is just an API and you consume it in your "frontend" (node, rails, etc) whatever that may be.
Frontend in this context is just another server that is communicating with backend APIs using RPC. When small teams think of frontend, they usually think about a framework like React, etc and pair it with a backend like Rails.
I loved CoffeeScript in 2012, but even then it was clearly a stop-gap, and we're on the other side. You're putting yourself at a strict engineering and hiring disadvantage, in return for... having less punctuation so you feel better about writing markup in your JavaScript..?
This seems misguided. Arel is already very much like a library for partials for SQL that allows composition and takes care of tedious but important concerns like injection safety.
> All these kids want to do a bunch of busy work and for no good reason.
That's what your SQL-partials system sounds like to me! Different strokes for different folks.
"For example, CoffeeScript adopted for..of loops to iterate over the properties of an object. Meanwhile, ES6 introduced its own for..of loops as a way to loop through iterable objects. If CoffeeScript wants to support new functionality with similar syntax like this, it has two choices: break existing CoffeeScript code, or diverge from JavaScript more and more over time."
https://medium.com/@tomdale/glimmer-js-whats-the-deal-with-t...
A friendly CS fanboy here. With CS2 many tools become trivial to integrate and work with
I'm surprised and intrigued by this. How do you get your query to return JSON? What percentage of your code actually works like that? How business logic heavy is your SQL? This is super interesting!
def serialize_in_postgres(relation, columns)
ActiveRecord::Base.connection.select_rows(
<<-SQL
select array_to_json(array_agg(row_to_json(result))) from
( #{relation.select(columns).to_sql} ) result
SQL
)
end
puts serialize_in_postgres(SomeArModel.limit(2), ['id', '"created_at"::date'])
# => [{"id":12345,"created_at":"2017-06-11"},{"id":23456,"created_at":"2017-06-11"}]
Unlike the parent, I would not recommend doing this everywhere, or even most places, but it is a very useful tool to have.I love standardjs.com. It takes an enormous amount of chutzpah to look at jQuery style guidelines, idiomatic.js, AirBnB and every previous JavaScript style guide and declare the name of your own new thing is `${standard} ${languageName}`
That's excellent. Thanks for the recommendation.
Other weird coffeescript quirk: "x isnt y" is not semantically to "x is not y".
CoffeeScript was an important crutch and stepping stone but we're maybe 2 years past where it has been past it's prime and this will make updating and improving legacy projects a lot easier.
Personally was never a fan of it - it used too many Ruby idioms for my taste and produced noisy code that was a pain to debug (at the time) - but it did spur the development & adoption of other, better, systems (ESNext transpilation, TypeScript, etc)
Anyway, I didn't have enough time to finish the project, but somebody took the idea and did most of the work [0].
[0] https://github.com/dk00/livescript-next
Would love to explain more, but have to board the plain now :) These links might help:
https://github.com/gkz/LiveScript/issues/821 https://github.com/facebook/flow/issues/1515
Now JSX is not weird anymore, it's just horrible.
Somewhat surprised nobody has mentioned the upcoming release of CoffeeScript 2.0, which outputs ES6 natively: http://coffeescript.org/v2/
It's in beta2 now and ready for trial.
Also when CS happened, JS didn't even have classes. Half of the ES6 features are CS inspired.
And it only has class syntax now. Classes in JS are still prototypical inheritance under the hood (and probably always will be).
> Half of the ES6 features are CS inspired.
This is rewriting history. Most of ES6 was under active development before CS was a thing. It's more accurate to say that the same modern languages features inspired both (with ES6 thankfully being less Ruby-like).
I am still waiting for someone to finish a Python bytecode VM or transpiler for javascript which is actually worth using...
What is that? Running JS in a python VM?
The point would be to have access to a large part of the standard library, the full Python data model and a good integration with the javascript platform. Only then would there be a reason to use it.
Producing readable code is certainly the intent! Realistically, you need to clean some things up by hand to make it pass lint and look nice, but I think overall it does a pretty good job, certainly much better than the CoffeeScript compiler. You can always play around with it by typing/pasting code into the online repl: http://decaffeinate-project.org/repl/
> Producing readable code is certainly the intent!
This is hilarious! Transpiling from the most readable JS alternative to ES6? Then you need to clean up some things, making it ready for yet another transpiler called Babel? And then everything is OK?
Show me how you are going to make this pretty:
if does.that?.prop?.exist then console.log 'yes, no crash!'No, I was intentional about my description. People tend to be informal when talking about JS versions, and all five of those terms might be used to describe decaffeinate's output. IMO it's best to just say that decaffeinate produces JavaScript, and not any particular old version of JavaScript.
> Show me how you are going to make this pretty
Soak operations (anything with a question mark) are probably the hardest to convert to JavaScript, especially when they're chained. Here's what decaffeinate gives today:
http://decaffeinate-project.org/repl/#?evaluate=true&stage=f...
And here's an open bug with thoughts on making those look better: https://github.com/decaffeinate/decaffeinate/issues/336
But many people have still found decaffeinate useful since the vast majority of real-world CoffeeScript (at least from what I've seen) tends to convert pretty well, and even in difficult cases, it's better to safely get it in JavaScript first and then clean it up than to rewrite everything by hand.
I guess when Atom was started it made sense to use CS, not anymore. Hopefully Github will switch to ES6/7 or TS.
There is also a nice comment in here about a large project that became a misery because of TS. Think twice before you hope!
If you don't like the language, but have to use it, use it as compiler target, simple as that.
The whole JS stack switches every 2 years or so?
I mean, it actually switches faster than that and that's what everyone jokes about (JavaScript fatigue and what not). But a full turnover of the stack is about 2 years?
https://github.com/bugsnag/depercolator
There's an open decaffeinate bug for CJSX ( https://github.com/decaffeinate/decaffeinate/issues/1009 ) but I suspect it'll be really hard to do anything better than just running cjsx-transform and then running regular decaffeinate.
To get JSX on the JS side after decaffeinate, you can use the create-element-to-jsx script from https://github.com/reactjs/react-codemod .
It would be wrong to say that the investment we (as an industry) made in coffeescript was a waste. Far from it.
By spending basically the entire runup to it poo-pooing it?
> You can see the influence of coffeescript all over es6 in the class syntax, string interpolation and destructuring.
Yeah it couldn't be the dozens of languages which have been doing that since the 80s and which browser developers were already mining for extensions no sir, Coffeescript invented having a class keyword (which is why it was already a reserved keyword in JS), invented string interpolation which it lifted directly from Ruby (according to its own doc) and from which JS string templates diverge both syntactically and semantically, and invented destructuring (and will I'm sure soon invent pattern matching).
BTW in Atom, I've successfully used atom-beautify with coffee-fmt and coffee-formatter to reformat very bad code with no errors
In this case, the __guardMethod__ usages should probably be rewritten by hand after running decaffeinate.
In general, you can paste any code into the left side of http://decaffeinate-project.org/repl to get output on the right side.
This tool converts it to modern JS (ES6) that has classes, template strings, etc.