3 ms·
It took me about 3 months of intense CS usage to really get the hang of it. I've written a good 20-30k lines of CS so far for my application, so I've developed
by latchkey 15y ago
It took me about 3 months of intense CS usage to really get the hang of it. I've written a good 20-30k lines of CS so far for my application, so I've developed a lot of good practices since I started. Now, I can't imagine writing 'pure' JS ever again.
I tend to avoid a lot of the one-line comprehensions for the reasons documented in this article (they get difficult to 'parse'). I also tend to write in a more of a Java style, mostly because of my background is in Java. I tend to put (parens) around a lot of function calls so that I can see it is still a function. Sure, CS can be abused to the point of being barely able to read, but that can be said of any language. Having standards and code-review with your co-workers kind of negates that issue.
Debugging can be a bit of a pain since you have to find the line number out of a big file. I think this will go away if/when browsers natively support CS. I've gotten good at naming things so that they are easy to search for in the developer tools. That makes finding the right line to put a breakpoint on a lot easier and faster. If need be, I'll throw a console.log('here') in there and search for that too. Context switching between CS and compiled JS takes a bit of getting used to, but it isn't really that big of a deal. I'm already context switching between Java, HTML, CSS, json, etc... what is one more?
The fat/thin arrow thing took a while to get used to, but now it makes perfect sense. The change they made (too quietly, imho) in 1.1.3 to not use __bind so much anymore really helped with comprehension. Now I can see the var _this = this in the compiled code and things make more sense to me now. It also helped performance and made me worry less about using it. In most cases, it is safe to just fat arrow things now so it really isn't that big of a deal.
In terms of workflow, I found it very important to integrate it in with my IDE so that every time I save a file, all of my CS is immediately compiled to JS. [1] As a result, I don't see any overhead with the compilation phase of things.
Being able to declare 'class'es and constructors has also been really great for compartmentalizing my code. Yes, it is possible to emulate all of this in JS, but I find that a lot more difficult to manage. I do wish there was an 'import' statement though. Right now, I hacked that together with the way I'm using LabJS.
In the end, is CS a significant improvement over JS? I think so. Just looking at the compiled output of CS, I couldn't imagine myself writing all of that JS code and not making a ton of mistakes (ie: === vs. ==, nesting of brackets, this binding, etc). People say there is a lot of boilerplate in Java... so, when I use CS, I feel that way when I look at the compiled JavaScript.
[1] http://stackoverflow.com/questions/6645640/integrating-coffeescript-with-eclipse/7507987#7507987 http://stackoverflow.com/questions/6645640/integrating-coffe...
- ryanflorence 15y ago> if/when browsers natively support CS. They won't, and source maps are not native support. Check out AMD with RequireJS (make sure you optimize) for your "import" stuff. I haven't incorporated optimization yet for the project, but you can see how it works with my snackJS project http://github.com/rpflorence/snack/tree/amd-coffee/lib http://github.com/rpflorence/snack/tree/amd-coffee/lib
- latchkey 15y agoThanks Ryan. I've looked at the RequireJS/AMD import stuff and it seems really over engineered for what I need. I feel like there is too much declaration going on. For now I think I'll wait to see what else people come up with along these lines.
- ryanflorence 15y agoWell, AMD is essentially a CommonJS format, so this is what "people have come up with" for the browsers until real modules show up :) http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition
- latchkey 15y agoThanks for the pointer, I made sure to read it. What I don't like about it is having to 'define' all the modules that I'm going to use. That is just too error prone. I'd rather just create a CS class in a file and include the entire file when I need to. More similar to the way that an import statement works in Java. For now, as I already mentioned, I'm simulating import style functionality with LabJS, which works great. While not perfect, it allows me to async load everything I need as well as minimize the amount of data on the wire. Here is a description of what I've done... http://lookfirst.com/2011/12/optimizing-your-javascript-delivery.html http://lookfirst.com/2011/12/optimizing-your-javascript-deli...
- Griever 15y agoIIRC I believe i read from Paul Irish (I could be mistaken) that Chrome is working to support projects such as CoffeeScript for debugging. No idea how tjry plan to implement this, but I found it to be an exciting possibility.