CoffeeScript
'''CoffeeScript''' is a programming language that compiles to JavaScript. The language adds syntactic sugar inspired by Ruby and Python to enhance JavaScript's brevity and readability, as well as adding more sophisticated features like array comprehension and pattern matching.
With 4000+ watchers and 300+ forks (as of December 2011), CoffeeScript is ranked as one of the "most interesting" projects on Github. https://github.com/repositories The language has a relatively large following in the Ruby community, and has been used in production by 37signals. Ruby on Rails began to include CoffeeScript in its asset pipeline in Rails version 3.1 (see http://www.rubyinside.com/rails-3-1-adopts-coffeescript-jquery-sass-and-controversy-4669.html).
History
On December 13, 2009, Jeremy Ashkenas made the first git commit of CoffeeScript with the comment: "Initial commit of the mystery language." The compiler was written in Ruby. On December 24th, he made the first tagged and documented release, 0.1.0. On February 21, 2010, he committed version 0.5, which replaced the Ruby compiler with one written in pure CoffeeScript. By that time the project had attracted several other contributors on Github, and was receiving over 300 page hits per day.
On December 24, 2010, Ashkenas announced the release of stable 1.0.0.
Examples
A common JavaScript snippet using the jQuery library is
$(document).ready(function() {
// Initialization code goes here
});
or even shorter,
$(function() {
// Initialization code goes here
});
In CoffeeScript, the function keyword is replaced by the -> symbol, and indentation is used instead of curly braces (except when defining an associative array), as in Python. Also, parentheses can usually be omitted. Thus, the CoffeeScript equivalent of the snippet above is
$(document).ready ->
# Initialization code goes here
or
$ ->
# Initialization code goes here
Compiling
The CoffeeScript compiler has been written in CoffeeScript since version 0.5, and can be run either in the browser or through Node.js. The official site at CoffeeScript.org has a "Try CoffeeScript" button in the menu bar; clicking it opens a modal window in which you can enter CoffeeScript, see the JavaScript output, and run it directly in the browser.
Citations
Github. "Interesting Repositories", Github, Nov 10, 2010.
Carson, Ryan. "New Rails-like Framework from 37signals for HTML5 Mobile Apps", Think Vitamin blog, Nov 8, 2010.
Hagenburger, Nico. "Rails 3.1 – A Sneak Preview", presentation for Railscamp Hamburg on Oct 23, 2010.
Ashkenas, Jeremy. "The Plan for 1.0", Github issue tracker, Nov 4, 2010.
External links
- GitHub repository
- @CoffeeScript - Twitter feed
- Wikipedia Entry
Tasks
- 100 doors
- 24 game
- 24 game/Solve
- A+B
- ABC Problem
- AKS test for primes
- Accumulator factory
- Ackermann function
- Add a variable to a class instance at runtime
- Align columns
- Anagrams
- Anagrams/Deranged anagrams
- Anonymous recursion
- Apply a callback to an array
- Arithmetic/Complex
- Array concatenation
- Arrays
- Associative array/Iteration
- Averages/Arithmetic mean
- Averages/Pythagorean means
- Averages/Root mean square
- Averages/Simple moving average
- Balanced brackets
- Benford's law
- Binary digits
- Binary search
- Bitwise operations
- Boolean values
- Bresenham's Line Algorithm
- CRC-32
- CSV to HTML translation
- Caesar cipher
- Call a function
- Call an object method
- Case-sensitivity of identifiers
- Character codes
- Chat server
- Check that file exists
- Chemical Calculator
- Chinese remainder theorem
- Classes
- Closures/Value capture
- Combinations
- Combinations with repetitions
- Comma quibbling
- Command-line arguments
- Comments
- Compound data type
- Concurrent computing
- Conditional structures
- Constrained random points on a circle
- Continued fraction
- Count in factors
- Count in octal
- Count occurrences of a substring
- Create an HTML table
- Cumulative standard deviation
- DNS query
- Date format
- Day of the week
- Delegates
- Determine if a string is numeric
- Dot product
- Echo server
- Empty directory
- Empty program
- Empty string
- Entropy
- Environment variables
- Ethiopian multiplication
- Evaluate binomial coefficients
- Even or odd
- Execute a system command
- Factorial
- Factors of a Mersenne number
- Factors of an integer
- Fibonacci sequence
- Filter
- Find limit of recursion
- Find the missing permutation
- First-class functions
- Five weekends
- FizzBuzz
- Flatten a list
- Floyd's triangle
- Forward difference
- Four bit adder
- Function composition
- Function definition
- Generate lower case ASCII alphabet
- Gray code
- Greatest common divisor
- Greatest element of a list
- Greatest subsequential sum
- Guess the number
- Hailstone sequence
- Hamming numbers
- Happy numbers
- Hash from two arrays
- Haversine formula
- Hello world!
- Hello world/Graphical
- Hello world/Newline omission
- Hello world/Standard error
- Hello world/Text
- Here document
- Heronian triangles
- Higher-order functions
- Hofstadter Figure-Figure sequences
- Hofstadter Q sequence
- Horner's rule for polynomial evaluation
- Hostname
- Huffman coding
- Infinity
- Integer sequence
- Interactive programming
- Inverted index
- Inverted syntax
- JSON
- Jaro distance
- Kaprekar numbers
- Knight's tour
- Knuth shuffle
- Knuth's algorithm S
- LZW compression
- Langton's ant
- Last Friday of each month
- Levenshtein distance
- List comprehensions
- Long multiplication
- Longest common subsequence
- Loops/Break
- Loops/Do-while
- Loops/Downward for
- Loops/Infinite
- Loops/N plus one half
- MD5/Implementation
- Map range
- Matrix transposition
- Modulinos
- Morse code
- Multiplication tables
- Multisplit
- Mutual recursion
- N-queens problem
- Non-continuous subsequences
- Nth root
- Number names
- Numerical integration
- Odd word problem
- Ordered words
- Palindrome detection
- Pangram checker
- Partial function application
- Pascal's triangle
- Perfect numbers
- Permutations
- Pick random element
- Power set
- Primality by trial division
- Priority queue
- Problem of Apollonius
- Program name
- Pythagorean triples
- Queue/Definition
- Queue/Usage
- Quine
- Ray-casting algorithm
- Read a file line by line
- Remove duplicate elements
- Resistance Calculator
- Reverse a string
- Reverse words in a string
- Roman numerals/Decode
- Roman numerals/Encode
- Roots of a function
- Roots of unity
- Run-length encoding
- S-Expressions
- Self-referential sequence
- Sequence of non-squares
- Set
- Show the epoch
- Sorting Algorithms/Circle Sort
- Sorting algorithms/Heapsort
- Sorting algorithms/Merge sort
- Sorting algorithms/Permutation sort
- Sorting algorithms/Quicksort
- Sorting algorithms/Sleep sort
- Spiral matrix
- Stable marriage problem
- Stack
- Statistics/Basic
- String interpolation (included)
- String matching
- Sum and product of an array
- Sum of a series
- Sum of squares
- Tokenize a string
- Topological sort
- Tree traversal
- Truncatable primes
- URL decoding
- Unbias a random generator
- Vigenère cipher
- Walk a directory/Recursively
- Web scraping
- XML/XPath
- Y combinator
- Zig-zag matrix