Three Months of CoffeeScript

Shopify Engineering
4 min readintermediate
--
View Original

Overview

The article discusses Kamil Tusznio's experiences with CoffeeScript while working on the Batman.js framework at Shopify. It highlights the advantages of using CoffeeScript for writing more concise and correct code, as well as addressing common criticisms regarding debugging and workflow.

What You'll Learn

1

How to write more concise and correct code using CoffeeScript

2

Why CoffeeScript can enhance productivity in JavaScript development

3

When to consider using CoffeeScript over plain JavaScript

Key Questions Answered

What are the advantages of using CoffeeScript in JavaScript development?
CoffeeScript allows developers to write more concise code, reducing the chances of errors and improving productivity. It eliminates boilerplate code such as 'var' declarations and 'hasOwnProperty' checks, making the code cleaner and easier to read.
How does debugging work with CoffeeScript?
Debugging CoffeeScript can be challenging since it compiles to JavaScript. Developers must test the compiled JavaScript in the browser, which can be confusing if they are not familiar with the output. However, understanding the compiled code becomes easier with experience.
What is the workflow for using CoffeeScript in projects?
The workflow involves running the CoffeeScript compiler with a command to watch for changes in .coffee files. Both .coffee and .js files are kept under version control, ensuring that nothing is lost and that existing JavaScript build processes remain intact.

Technologies & Tools

Frontend
Coffeescript
Used for writing the Batman.js framework and enhancing JavaScript development productivity.
Frontend
Batman.js
A single-page app micro-framework developed using CoffeeScript.

Key Actionable Insights

1
Utilize CoffeeScript to streamline your JavaScript code and reduce boilerplate.
By adopting CoffeeScript, you can write less code while maintaining adherence to best practices, which minimizes the likelihood of introducing bugs.
2
Regularly test your compiled JavaScript to familiarize yourself with the output.
Understanding the compiled output of CoffeeScript can help you debug more effectively and reduce frustration when issues arise.
3
Keep both .coffee and .js files in version control for better workflow management.
This practice ensures that you have access to both the source and compiled versions of your code, making it easier to manage changes and troubleshoot issues.

Common Pitfalls

1
Neglecting to familiarize oneself with the compiled JavaScript can lead to confusion during debugging.
Since CoffeeScript compiles to JavaScript, developers may find themselves stumped by errors in the compiled code if they haven't reviewed it beforehand.

Related Concepts

Javascript Best Practices
Single-page Applications
Micro-frameworks