Clojure / ClojureScript Crossovers and cljx
Asked Answered
A

2

9

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.

Arapaima answered 28/10, 2014 at 18:45 Comment(2)
cljx is intended as a replacement for crossovers, they aren't to be used together and lein-cljsbuild intends to deprecate crossovers (a shame, because they're nice and simple)Lent
I noticed a new library that you may consider: lein-dalap that is inspired by cljx.Emlen
E
6

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.

Emlen answered 2/11, 2014 at 16:31 Comment(0)
B
4

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.

Bramblett answered 31/10, 2014 at 1:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.