Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure / ClojureScript Crossovers and cljx

I'm trying to figure out the relationship between ClojureScript crossovers and the cljx pre-processor.

Are they designed to be used together? Or rival solutions to the same problem?

Is one becoming the preferred or more standard way to do things?

In particular what I want to do is to create a single library that can be compiled as Clojure and ClojureScript (with a couple of variations). I'm currently using cljx for this.

But then I want to include the library in further clj and cljx projects. Looking for information about this, I'm largely coming across documentation for crossovers but not cljx.

like image 691
interstar Avatar asked Oct 28 '14 18:10

interstar


2 Answers

Crossovers, CLJX, and Feature Expressions (from oldest to newest) have some overlap of features useful for compiling to clojure and clojurescript. Cljx and Features Expressions hold promise for more than just clojurescript, though, and make it possible to maintain more than just clojure-java and clojure-js, such as .net (clr, mono). Cljx and Feature Expressions enable arbitrary "features" such as enabling tracing or special "debug" builds.

Options (past, present, and future)

Crossovers (part of lein-cljsbuild)

lein-cljsbuild has deprecated the Crossovers feature. (See https://github.com/emezeske/lein-cljsbuild)

(cljsbuild crossovers are deprecated, and will be removed in v2.x [coming later in 2014].)

CLJX

I've used CLJX to target Clojure, ClojureClr, ClojureScript (for browsers), and ClojureScript for NodeJS. It works well enough - certainly better than maintaining 4 separate codebases. I haven't used CLJX to do dependencies of dependencies, though once you've packaged a library, it shouldn't matter that it was originally cljx.

Feature Expressions (hopefully coming soon from clojure core)

This idea borrows from Common Lisp's feature expressions and looks much like cljx.

As of November 2014, this is in the Release.Next, so that sounds promising. It seems that CLJX and LISP's feature expressions are the inspiration for this anticipated feature of Clojure.

Personal Experience

I used Crossovers for one project a couple years ago, but since CLJX came out, I've been using CLJX with great success. It takes a little adjustments to tooling and editors, but I believe it is so much better than making the same code change for all the platforms.

I plan to use CLJX until feature expressions are available, and then re-evaluate.

like image 190
agent-j Avatar answered Nov 17 '22 00:11

agent-j


Crossovers and cljx are rival solutions the same problem and cannot be used together. From what I can tell, cljx is preferred over crossovers. For example, as @Hendekagon pointed out, lein-cljsbuild has deprecated crossovers.

chord is a library that is intended for both client and server side usage. You could probably use their project.clj as a starting point.

like image 22
Tim Pote Avatar answered Nov 16 '22 23:11

Tim Pote