Scripting Libraries were always my favourite. For a long time I had been trying to seek various scripting libraries to unleash their power of existence and what they can provide to our programming world. One of the library I really like is CoffeeScript. As the name suggest CoffeeScript means a cup of coffee that unleash the taste of sensuality in scripting world. We all like coffee isn’t it.
You can install CoffeeScript using Node Package Manager and write CoffeeScript in various editor which supports this library but for Visual Studio developers “Welcome to CoffeeScript World”. Now CoffeeScript can be added to Visual Studio 2010, 2012 and 2013 as an extension for editing by downloading the Visual Studio tool Mindscape Web Workbench or installing the Web Essentials which will provide a template for CoffeeScript in your Visual Studio version.
What kind of similarities we can see between CoffeeScript and C#.
- C# use Lambda expressions for declaring an anonymous delegate. CoffeeScript also use the same syntax by implementing jQuery grep() function to decide whether to return an element. For example:
- Just like C#, CoffeeScript supports default values for function arguments. For example:
- Just like C#, it use existential operator “?” which acts similar to C# operator “??”. For example:
- C# use Tuple which is a data structure that has fixed number of elements and it is useful when we want to return more than a single value. The same concept applies in CoffeeScript which is using destructuring assignment syntax. For example:
- C# use switch/case statement. CoffeeScript use the same approach as switch/when/case construct which automatically inserts break in each case block. For example:
And last point that I would like to highlight is CoffeeScript is packed with features, so combining CoffeeScript with jQuery can really make the world clean and beautiful.
Hope you will learn more on CoffeeScript and implement it in your projects.