Clojure-Script 

at first sight

whoami

adam.schmideg.net

The question

If you like Clojure
will you like ClojureScript?

The road

  • Clojure
  • ClojureScript?
  • ClojureScript! (YMMV)

The family

  • clojure
  • clojure-clr
  • clojurescript
  • clojure-py
  • clojure-scheme

Clojure

  • "clojureness"
  • Many Lines of Code
  • Javaland

Javaland

  • Java language
  • JVM
  • shared code (snippets, jars)
  • mindshare

Alternatives

  • Scala
  • Groovy
  • Jython, JRuby
  • XTend
  • lisps
  • ...

"clojureness"

  • dynamic development
  • host interoperability
  • modern lisp
  • concurrent programming
  • runtime polymorphism

Modern Lisp

(clojureness cont'd)

  • first-class functions
  • immutable data structures
  • recursion
  • macro

clojureness in practice

  • compile
  • manage dependencies
  • deploy
  • debug
  • simple made easy?

Clojureland

  • leiningen
  • clojars
  • REPL
  • people
  • batteries

Batteries

  • Included: set, walk, ...
  • Excluded: json, logic, xml, ...
  • Libraries: compojure, ring, enlive, ...
  • Projects: overtone, incanter, ...

ClojureScript

  • "clojureness"
  • More Lines of Code
  • JavaScriptLand

JavaScriptLand?

    
module greeting;

var name = readLine();
    if (name == null) {
     console.log("Hello, world");
    }
    else {
  console.log("Hello, " + name);
    }

// no, it's not working code

JavaScriptLand!

  • browsers
  • server-side engines
  • common.js
  • de facto libraries

More Lines of Code

  • Read-emit in Clojure
  • Closure compiler in Java
  • cljs.core library
  • Google Closure Library

Alternatives

  • Dart, TypeScript,  Adobe AIR
  • CoffeeScript, ...
  • Haxe, Fantom, ...
  • language ports

Alternatives

with some clojureness

  • lisps and schemes
  • chlorinejs
  • kanaka/clojurescript
  • mori
  • wisp

Clojure vs Coffe

  • - heavy-weight  
  • - slow compilation  
  • - debugging
  • + persistent data structures  
  • + no javascript bad parts  
  • ± ecosystem  

differences

            (ns foo.bar
    (:use
     [foo.helper :only [baz]])
    (:require
     [clojure.set :as set])
    (:use-macro
     [foo.macros :only [debug]]))

        

Missing

  • ns-resolve and friends
  • rationalize, bigint, and friends
  • *out*, print
  • some core libraries (pprint, test, xml)

Interop Differences

            (defn ^:export show-off
  "It will be show_off"
  [& args]
  (let [[head tail] (js->clj args)]
    (.log js/console "Before greeting")
    (set! (.-title js/document) "Hi!")))

        

Decisions to make

  • Node.js/npm or browser or ...
  • Development workflow
  • Shared code or js only
  • Macros

Step One

                lein new cljs-kickoff step-one
cd step-one
lein cljsbuild auto &
lein ring server

            

Step Two

  • ClojureScript One
  • REPLs

cljsbuild

                (defproject step-three "0.0.3"
  :source-paths ["src/clj" "src/common"]
  :test-paths ["test/clj"]
  :repl-options {:port 40444}
  :cljsbuild
    {:builds
       [{:source-paths ["src/cljs" "src/common"]
         :compiler
         {:pretty-print true
          :output-to "gen/generated.js"
          :optimizations :whitespace}}]
     :crossover-path "target/crossover"
     :crossovers ["foo.bar"]})

            

Node.js

  • node target in cljsbuild
  • bodil/cljs-noderepl
  • node-clojurescript (dead?)

Shared code

  • none
  • cljsbuild crossovers
  • cljx
  • feature expressions (someday)

The Answer

I hate this answer.
Do I like ClojureScript?
Well, it depends.

Do you?