Hacker News new | past | comments | ask | show | jobs | submit login
ClojureScript vs Coffeescript (metaphysicaldeveloper.wordpress.com)
74 points by DanielRibeiro on Aug 28, 2011 | hide | past | favorite | 14 comments



Hmm. This seems like an odd comparison to me as Coffeescript and ClojureScript really have two different target audiences. Coffeescript seem to be more targeted towards people interested in writing JavaScript application with a more clean syntax whereas it seems ClojureScript's aim is to allow people who want to write Clojure, do so targeting a JavasScript VM rather than a JVM. I'd expect people looking to use either would probably know which one they were looking for from the get-go.

Interesting summary of ClojureScript's current weaknesses though.


I think the audiences are not as different than you think (I use both). CoffeeScript is for anyone wanting to write in a more expressive language.

ClojureScript offers that and even more without requiring people to fork ClojureScript. For example I got my pattern matching library working for ClojureScript - http://dosync.posterous.com/advanced-pattern-matching-for-ja.... match looks deceivingly simple, it's a fairly involved extensible optimizing pattern match compiler implemented as a macro.

EDIT: a fun example of how expressive pattern matching can be - here's a pattern for checking red black tree balance and the incredible output - https://gist.github.com/1177437


Given that the author writes the same physics-based app in both - it seems you're disagreeing with the author.


This is Pacman in Clojurescript: https://github.com/mjg123/pacman

This is Pacman in Javascript (I couldn't find one in Coffeescript): https://github.com/macek/google_pacman


60 of the ClojureScript lines are due to unidiomatic formatting of parenthesis.


Would love to get a pull request with an idiomatic version.


Nice writeup! I hadn’t heard of rbcoffee before. I’ll definitely be using that in my coffeescript projects. One point – doesn’t ClojureScript support user macros via refer-macros? :

(ns my.namespace (:refer-macros ‘[my.macros :as my])


Thanks. Rboffee has its own project[1].

About macros, I get WARNING: Use of undeclared Var cljs.user/defmacro when I even think of using them.

If you manage to use them, please let me know!

[1] https://github.com/danielribeiro/rbcoffee


ClojureScript does indeed have macros. They are compiler macros. You can't define macros in your ClojureScript file (because ClojureScript doesn't itself have access to the compiler) but you can refer to macros defined in a Clojure file and the ClojureScript compiler will use this to expand your ClojureScript. That's what refer-macros is for. I'm looking forward to getting my pattern matching library, https://github.com/swannodette/match, working with ClojureScript.

As far as the compile times you should checkout Chris Granger's https://github.com/ibdknox/cljs-watch. This is analogous to "coffee -wc *.coffee".

Nice writeup.


To me it was obvious that the time-to-compile measurement for ClojureScript was all wrong. It's a common, but annoying mistake people who aren't used to the JVM make. Startup Time != Compile Time.


If it started once and watched files for changes, it would only be the compile time (which, if fast, would be great). As it is, the total time is the only one that counts, as it is the one that affects your productivity.

JRuby guys were so aware of this that they actively promoted nailgun[1].

[1] http://www.martiansoftware.com/nailgun/


CORRECTION: it's require-macros not refer-macros.


ClojureScript has compile-time only macros, but they are handy for repetitive (set!) calls as in your example. You might want to look at the (attr) macro in the cljs-d3 source:

https://github.com/lynaghk/cljs-d3/blob/master/src/clj/cljs_...

which solves a very similar problem to the one you mentioned in the article. In this case it expands attr(hash-map) into multiple attr(key, value) calls at compile time.


Projects that aid metaprogramming in CS (please contribute):

https://github.com/clyfe/meta_code/wiki




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: