Written by Aravind H.U on Aug 6, 2014
I was facing lot of difficulties in learning coffee script at last I could figure out the reason and started identifying the gray areas.
Here it goes
- What is it ?
- Why do we need to use it and what is its role ?
- Grasping its syntax
I decided to share my understanding thinking it might help others who are also facing the same problem by trying to learn this soon. But to learn any technology relative thinking/learning is the key.
Lets start turning these gray areas into green :)
What is it ?
I guess you have already seen this below statement in the home page of coffee script.org, It is the most important statement and has lots of inner meanings .
I was lost initially, when I read this statement let me elaborate it so that you can get its insights .
So we have two things here, first one is coffee script compiler and 2nd one is coffee script language.
I feel its little out of scope to describe how to install coffee script compiler so please refer to the coffee script documentation on installation.
Why do we need to use it and what is its role ?
Since we write bad code it will be very hard to maintain, also due to syntactic sugar it is hard to write the efficient testable code.
Grasping coffee Script syntax
Before starting to grasp syntax, lets list down some coffee script syntax commandments which helps to grasp its syntax.
- No semicolons through out the code
- No parenthesis for functions ( not mandatory )
- No need to declare the variables.
- No more named functions only function expressions/clojure/IIFE blocks
- No need to use return statements
- No need to check for undefined, exploit conditional operator.
- Use splats instead of array of arguments
- Use chained comparisons instead of having multiple conditions
- Worry a lot about indentation because it matters a lot when you declare and use objects.
And that's all, after grasping these commandments I was feeling more comfortable then before, I guess its the same for you people who are reading this article .