Sonntag, 24. November 2013

Quotes from Coffeescript Application Development book

Above I posted some extractions from the book Coffeescript Application Development I found the most interesting.

Most of the time, you will define your methods in the main body of the class definition. This is the easiest and most logical place. However, there are a few occasions when you may wish to attach a method to an object prototype from somewhere else in the code. This may be for stylistic or metaprogramming reasons, or most likely, to attach methods to an object that you did not define. CoffeeScript provides the :: operator for easy access to an object's prototype.
 Variable arguments list
Appending ... to an argument name in the function definition tells CoffeeScript to accept any number of arguments. That variable will be assigned an array containing all the relevant values that were passed.
Check on existence
CoffeeScript has a helpful existential operator to deal with these situations correctly and cleanly. It is a simple ? symbol.
Destructuring assignments
We can even use destructuring assignment to perform in-place variable swaps:
[first, second] = ["cow", "milk"]
# Wait, or is it the other way around?
[first, second] = [second, first]
console.log "Don't put the #{second} before the #{first}."
Destructuring assignment can be used with more complicated structures too:
[drink, [alcohol, mixer]] = ["Screwdriver", ["vodka", "orange juice"]]
console.log "A #{drink} consists of #{alcohol} and #{mixer}."
Loops return array of results
One extremely useful feature of CoffeeScript loops is that they return a value—an array of the results of the inner statement for every item in the loop. If you've ever used to transform an array, you'll be happy to see that it's easy to achieve the same functionality in CoffeeScript.
Link on book in store

Review of CoffeScript Application Development book

CoffeeScript Application Development, the book I read lately, helped me to take overall look at the language I have recently used on a number of projects. Like many books about programming languages it is also divided into chapters which follow you from the very beginning — tools installation and basic syntax to more advanced topics like classes and asynchronous operations. The book also covers such things as debugging, using the language for server-side development and adopting it for usage with different JS-frameworks.

Each topic of a book goes with a number of examples clearly showing how to use specific CoffeeScript features and what code will look like after compilation into JavaScript. The only thing I found ineffective is a way how author presented the example application. Its progress was mixed within the material treatment. For me as a person who read a book without immediate trying and following examples by hand it has been difficult to get a sense of this examples. I would rather move this example application into separate appendix and make cross-links on related topics. Thus the material treatment could be more consistent and at the same time the example application could be more readable and perceptive.

I would definitely recommend this book for reading people who find annoying such things in JS as checking curly braces parenthesis, frequently testing variables on existence and maintaining code written using different code conventions.

After reading I have got obvious feeling that CoffeeScript makes code much clearer and understandable allowing to explain things in a very concise way in comparison with bare JavaScript and as the result it makes code better maintainable. As soon as ease of maintainability is one of the corner stones of software development in modern realities the profit from usage CoffeeScript excessively covers spending time on its learning and getting on usage.

You can find this book on the following link