Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I learn JavaScript before CoffeeScript? [closed]

Tags:

coffeescript

I am looking for some insight on learning CoffeeScript without learning pure JavaScript.

I currently write CSS/SASS and HTML/HAML and I would like to learn JavaScript. I know very basic JavaScript but I have not taken it very far. I really like the syntax of CoffeeScript and it makes more sense to me.

Would learning just CoffeeScript screw up my learning?

like image 984
SkinnyG33k Avatar asked Feb 29 '12 15:02

SkinnyG33k


People also ask

Is CoffeeScript like JavaScript?

CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. The golden rule of CoffeeScript is: “It's just JavaScript.” The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime.

Why should you use CoffeeScript instead of JavaScript?

CoffeeScript is something that makes even good JavaScript code better. CoffeeScript compiled code can do everything that natively written JavaScript code can, only the code produced by using CoffeeScript is way shorter, and much easier to read.

Is it worth it to learn JavaScript in 2022?

Yes, JavaScript is worth learning in 2022. It ranks as the most widely used programming language and it has held this position for nine years in a row. JavaScript is the only programming language native to web browsers. Therefore, as long as the Internet is around, it will always be relevant.

Should I start learning JavaScript first?

So: if you want to become any kind of web developer, you absolutely need to learn this language—and you should start with plain old vanilla JavaScript first. If you're to work out how long to give to get up to speed on the language, senior developer Marven shows you how long it should take to pick up JavaScript.


3 Answers

At this point, there are two answers to this question. Asawyer says you must know JavaScript to debug CoffeeScript. Trevor suggests that you should ideally be at least an intermediate level JavaScript programmer. I'll give you the third perspective.

The quickest way to proficiency at CoffeeScript is to start writing in CoffeeScript but expect to learn JavaScript as you go. You'll still need to learn a lot about Javascript including the standard objects (Object, Array, Date, Math, XHR, etc.). But other things you can learn from the CoffeeScript perspective. For instance, Trevor's book has a great chapter on jQuery. That's where I go whenever I need a refresher on DOM manipulation. Another example is scoping; once you understand the difference between skinny arrow and fat arrow (CoffeeScript concepts), you'll know the two good ways of handling closure scope in JavaScript.

If you don't know object-oriented programming, I suggest you start with a book like the HeadFirst Design Patterns book eventhough it's java based because it's the quickest way I know to reprogram your brain for OO. It's tough to learn good OO practices starting with JavaScript... less hard with CoffeeScript.

Evidence

I have a background in Java, Python, and ActionScript but I started full bore on CoffeeScript only 3 months ago, and I've been able to ramp up quickly enough to have written 4,500 lines of production code including 2 original projects that assist with CoffeeScript development (CoffeeDocTest, and Line Commands for Coda) and my primary work on a tool for my PhD called Lumenize as well as contribute to two other CoffeeScript projects (coffedoc, and CoffeeScript mode for Coda). I have never explicitly set out to write or learn JavaScript.

Further logic

I don't base my conclusion solely on my own experiences. Here are other reasons:

  1. You can avoid the wasted time learning where all the warts are in JavaScript. I still don't know the difference between == and === and I don't care! [Update: Now I sorta do know the difference but who wants '1', the String to be == to 1, the Number? I'm still happy to use === everywhere]. In what browsers and under what circumstances is it safe to forget a semi-colon? Your code will work fine during your testing and then fail on someone else's browser. Sure there are tools like jslint but it takes time to ramp up the use of those. Going straight to CoffeeScript skips that time.

  2. You'll learn good OO habits for creating classes and inheritance easier in CoffeeScript than JavaScript.

  3. List comprehensions and language-supported for loops change your habits. JavaScript developers often use a functional callback style for iterating over collections ($().each() for instance). Using a functional style like this is much less efficient but it's a much cleaner syntax than what JavaScript provides natively. With CoffeeScript, you get the speed of the native implementation with even better readability than the jQuery syntax.

  4. The debugging argument is overstated. All of the identifiers and the overall structure are maintained when the code is compiled. It's very easy to see your own code in the compiled JavaScript. At first, I had to study how my CoffeeScript was being converted but that's how I learned to write "good" JavaScript. Now, I can easily read the compiled JavaScript.

like image 111
Larry Maccherone Avatar answered Oct 18 '22 14:10

Larry Maccherone


Yes absolutely learn javascript first! Coffeescript compiles down into it, and when the client is running your code it will be raw javascript. How do you expect to debug it without understanding the language?

like image 37
asawyer Avatar answered Oct 18 '22 15:10

asawyer


The interactive book Smooth CoffeeScript aims to teach CoffeeScript as a first language. But most resources, including my own book CoffeeScript: Accelerated JavaScript Development, are aimed at people who have an intermediate level of JavaScript knowledge. Brendan Eich, the creator of JavaScript, blurbed the book, saying that it "helps readers become better JavaScripters in the process of learning CoffeeScript."

So, I'd suggest doing at least a few JavaScript tutorials (like those on Codecademy) first, and then consider investing in a book on CoffeeScript. ;)

like image 37
Trevor Burnham Avatar answered Oct 18 '22 14:10

Trevor Burnham