CoffeeScript – The Awesome way to write JavaScript


Do you struggle with Braces and semicolon in writing code of JavaScript. There is a solution of this problem and that is – CoffeeScript.  In this post I’ll explore  CoffeeScript – a minimalistic language that compiles to JavaScript.

CoffeeScript – The Awesome way to write JavaScript

CoffeeScript

CoffeeScript

CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. 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. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript.

The language adds syntactic sugar inspired by Ruby,Python and Haskell. NO braces and semicolons. Since March 16, 2011, CoffeeScript has been on GitHub‘s list of most-watched projects, and as of 29 August 2012 is the eleventh most popular language on GitHub. CoffeeScript compiles predictably to JavaScript and programs can be written with less code, typically 1/3 fewer lines, with no effect on runtime performance

Syntax of CoffeeScript – Easy to use – Easy to Read

Here I am showing some example.

1. Assignment

str = "CoffeeScript"

2. Function

square = (x) -> x * x

3. Condition

string = "Passed" if  condition

4. Multiply numbers with 2

[1..10].map (i) -> i*2 

5. Object

math =
  root:   Math.sqrt
  square: square
  cube:   (x) -> x * square x

6. Loop

eat food for food in ['toast', 'cheese', 'wine']

CoffeScript vs JavaScript Code

CoffeScript vs JavaScript

Installation

The CoffeeScript compiler is itself written in CoffeeScript, using the Jison parser generator. The command-line version of coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browser.

To install, first make sure you have a working copy of the latest stable version of Node.js, and npm(the Node Package Manager). You can then install CoffeeScript with npm:

npm install -g coffee-script

(Leave off the -g if you don’t wish to install globally.)

If you’d prefer to install the latest master version of CoffeeScript, you can clone the CoffeeScriptsource repository from GitHub, or download the source directly. To install the lastest master CoffeeScript compiler with npm:

npm install -g http://github.com/jashkenas/coffee-script/tarball/master

Or, if you want to install to /usr/local, and don’t want to use npm to manage it, open the coffee-script directory and run:

sudo bin/cake install

For More Information and learning
1.http://coffeescript.org
2.http://jashkenas.github.com/coffee-script/documentation/docs/grammar.html

Advertisements

Popular Programming Languages


All popular programming languages, for each one the description and why to choose it. New emerging programming languages are also included in the list. 

Complete list

Description

Why use it?

C#
(C Sharp)
Concurrent to java, runs on .NET or compatible platforms (Portable NET, Mono). 
More
 – Code
Easier than C++. May share resources with other languages under a common runtime.
C C offers great freedom, and lot of debugging challenge thanks to pointers and memory management. 
More
 – Code
Suffering slow programming to make fast programs. For system programming.
C++ C++ is C plus objects, an extended library, templates. 
More
 – Code
System programming as C but allow larger project, or applications.
D language C++ like language, more dynamic. Compatible with C.
D Language – Code
For teaching or scripting.
Pascal Old language (1970), improved with objects, imposes a strictly structured programming. 
More
 – Code
Teaching, or client/server apps with Delphi and Kylix.
Basic
ASP
This very old language (1964) was improved by Microsoft, with a complete programming environment. Other portages exist. 
More
 – Code
Standard language for scripting Microsoft’s applications (Word etc…), and for dynamic web pages (Asp) on Windows servers.
PHP Designed to be embedded inside HTML to build dynamic Web pages or update them from databases.
More
 – Code
Producing HTML pages from data.
The version 5 targets Web services.
Java Was designed to be portable and to replace C++.
More – Code
Cross-platform applications. For web services and mobile phone apps under Android.
JavaScript,
ECMAScript
JavaScript has been invented to build dynamic client-side html pages, ECMAScript is the standardized version. 
More
 – Code
For interactivity in web pages and applications.
Used with HTML 5 for Web or local apps on Metro or Node.js or Qt.
Scriptol A simple, object-oriented, universal language with an intuitive and powerful syntax. You can build executables, or embed code into html pages.
XML may be used as data structure. 
More
 – Code
Easy and universal for scripting, prototyping, making binary applications, dynamic web pages and XML processing.
For web services by using PHP 5 as back-end.
Python A modern interpreted language with powerful built-in features and a unique indentation feature to shorten coding.
The Jython version compiles in Java bytecode. 
More
 – Code
Programming at light speed. Powerful and easy to learn.
Extending Zope for web services.
Java scripting with Jython.
Only for open source applications (not compiled).
Boo This is a new version of Python with some new features. It runs on .Net and Mono and thus, no compatibility problem.
Boo – Code
Similar to Python.
ASP Scripting language, server-side, for dynamic web pages by Microsoft, same syntax as Basic. 
ASP
 – Code
Producing HTML pages from data, but under Windows servers only.
Assembler This is near the machine language and the fastest. You should never use it, as older programmers did. Making graphic subroutines, drivers or industrial processing.
Eiffel, Sather Object-oriented, with “programming per contract” and other secure features. Sather is an open source implementation.
More – Code
Programming secured applications. Used by hospitals.
Perl A scripting interpreted language. Readabillity and ease of use are not the goal. 
Perl 
– Code
Mainly used by networks administrators and for small CGI scripts.
Rebol Interpreted language for network scripting. The language itself may be augmented. 
Rebol
 – Code
Processing information on distributed computer systems, with small programs.
Ruby Designed with simplicity in mind. It is interpreted, and has a proprietary but extensible library. 
More
 – Code
Writing scripts more easily. Using Ruby on Rails for Web applications.
Tcl A scripting language, easy to learn and available on any platform.
More – Code
Scripting of portable programs with GUI, and web programming by CGI.
NetRexx By IBM, has a simplified syntax. 
More
 – Code
Extends Java with scripts.
Lua Add-on or standalone language with extensible semantic.
Lua – Code
Extending the C language.
Cobol Business language still used on big computers.
Cobol – Code
Maintaining old programs on mainframes.
Fortran One of the first languages, always used for mathematical tasks.
Fortran – Code
Has huge library for scientific calculations.
Lisp Lisp is a very old language designed for artificial intelligence, processes lists only.
Lisp – Code
Artificial intelligence and scripting.
Scheme Scheme is a modernized version of Lisp.
Scheme – Code
Artificial intelligence and scripting.
Prolog For logic programming, based on Horn’s clauses.
Prolog – Code
Heavy artificial intelligence processing.
Haskell Functional programming. Slow and memory consuming. 
Haskell
 – Code
To try programming in another way
SQL Language of data management. 
MySQL
For databases queries.
Forth Another oldy. Invented by an astronomer, is stack based
Forth – Code
For instrumental commands and legacy libraries re-using.
Smalltalk One of the first object oriented language, programs can’t run outside the IDE.
Smalltalk – Code
Absolutely object-oriented processing.
Modula,
Oberon
Successors to Pascal.
Oberon – Code
For nostalgics of the Algol and Pascal time.
Caml, Ocalm Functional languages, Ocalm is object-oriented.
Caml – Code
Used by universities. May help to build a compiler.
Scala Procedural, functional and object-oriented programming language.
Scala – Code
Provides a more compact syntax than Java on the virtual machine
XML Not really a programming language, but may be used for similar tasks.
XML
XML serves to describe precisely data and may include actions on data.
XSL allows to transform documents.