You should know ClojureScript before choosing Redux, here’s why…

I’m not happy about Redux, but I’m not writing long post trying to uncover the dark side of Redux. People are praising Redux. As we all know it came from Elm, and earlier it can from speeches by Bret Victor. It’s time travelling debugger. Like all developers I want it become easier and faster to build apps. Redux is making things much better. The part that made me unhappy is, I found it could be simpler and more beautiful in ClojureScript. While Redux comes with some concepts that are stranger even than that in Elm, that’s very strange.

So some about me. I’m working in Shanghai and has worked on React for about 2 years. I used to write in CoffeeScript and for the recent months in ClojureScript. I also tried to implement things by myself, like a tiny Redux copy called actions-recorder, a tiny “redux-router”-like component called router-view, a virtual DOM based MVC library in ClojureScript called Respo. My crafts can be slower and unstable compared to the well known libraries. I worked in React long enough to know why React is great and what React is short for.

Comparing to my tiny pieces, a lot more people know Clojure, which is a Lisp dialect running on JVM. And ClojureScript is Clojure compiled and running on JavaScript. You may have heard a lot about ClojureScript in React community, when talking about immutable data structure, which is inspired by Om, a ClojureScript binding for React.js .

  • So you want immutable data structure, fine, it’s built-in in ClojureScript.
  • You want that every thing is an expression so you may use “if” and “switch” directly without introducing “a?b:c” or “return”, fine, that’s ClojureScript.
  • You want hot code swapping, ClojureScript supports it better than JavaScript.
  • You want an emitter so than the library knows the updates in the store, okay, it’s what “Atom” does in ClojureScript.
  • You don’t like to always bind “this”, that’s good, “this” does not exists in daily ClojureScript code.

All above. I just turned them into list for looking up.

There’s more than that. We all know Lisp since it’s the source of functional programming and many of us are still running after Lisp. Clojure is more than Lisp. Data structure in Clojure is immutable, like Haskell, and like Elm. You may have heard of “reset!”, in Clojure references can be mutable, but a value is never mutable, and with “reset” you can modify the reference of an Atom. So it’s more functional and more restricted. While we are talking about pure functions, immutable store and states, React is more and more embracing ES6 classes and Redux too. I’m not saying it’s a wrong direction but JavaScript is becoming a messy language isn’t it?

The part that is good is not original, and the part that is original is not good.

JavaScript is a language mixed with features from Scheme, Self, Java, C# and even more. Maybe I can add XHP thanks to JSX. It can be risky to have all of them in one place.

Clojure is different from JavaScript. It is designed carefully rather then finishing in weeks, and it’s not adding new syntaxes every month. It enables static analysis by default rather than throws lots of runtime errors. It maintains packages with Clojars rather than several tools like RequireJS Bower, npm, and CDNs. It eliminates callback hells with Channels, within a library, rather then 3 new techniques called Promise, Generator and Async from 3 different languages.

By comparing you two communities, they both support React and hot code swapping, they both run in Browsers and Node.js , they both compile and run. I found JavaScript is so crazy behaved and dramatically changed. So why is JavaScript being so crazy while ClojureScript is stable, but got features like we do in React.js community with so few developers? Why is JavaScript becoming that complicated, are we still trying to solve the simple problems as we started?

Seeing from my side, JavaScript is being pushed, the industry is being pushed, big companies like Google and Facebook, towards a better ecosystem, more reliable, more performant, as long as it is still JavaScript, but whatever it takes. Getting complicated? Well, people may learn it. Getting messy? Spend more time and figure it out. There’s always solutions.

But I’m getting tired after 4 years JavaScript learning(since my beginning, :friendly-smile:). It’s time to pick a new language. For me that’s Clojure. At work I still write ES6, for our company. But Clojure for my open projects.

Let me go back to Redux. Redux is almost the same when compare with ClojureScript. I just said as long as you get Clojure, you can by default:

  • values(which is immutable)
  • Atoms(already a emitter you can “add-watch”)
  • pure functions to update the store(“get-in”, “update-in”, “assoc-in” are core functions here)

so you already got the pieces of Redux. It can be quite cheap as I can see, why is that so expansive in Redux? We need “reducer”, “combineReducer”, “Provider”, “middleware”. That’s complicated.

As I said I’m not saying it’s bad, but it’s overwhelmed. And I don’t believe that the complexity of Redux is just fine, it’s too much. That’ all I want to say and enough to push me to Clojure side.

I read Redux source half a year ago when I was building actions-recorder. Not reading that for the past months. Neither do I looked into the whole React source code for the details but just read some alternatives like deku, diffhtml and inferno. I’m writing this post in hope that the Web platform will become sweeter for us developers. And I do hope JavaScript not going too crazy.

By the way, I always bet WebAssembly will kill JavaScript. It can hardly be true, but I hope so.

Like what you read? Give JiyinYiyong a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.