Skip to content

Comment on Learn ClojureScript: Discovering Sequence Operationsparent

Comments

  (defn parse-image-links [pages]
        (-> (map #(js/Promise. (parse-page %)) pages)
            (js/Promise.all)
            (.then #(->> % (map :Images) (apply concat) (map parse-image-url) set save-links))
            (.catch js/console.error)))
And you have gone full circle, bact to writing Javascript but with parentheses.

Yes. At its worst it's just Javascript (with parentheses), especially when dealing with libraries and promises.

In other cases you can benefit from all the features of ClojureScript.

That's pretty magical in my experience.

The thing is that interop typically lives at the edges of the application where IO happens. I'm typically using a Js library to do Ajax, paint stuff on the screen, and so on. All the core logic of the application is written in pure ClojureScript. And that's where all the interesting things happen.

And I'd say writing JavaScript with parentheses is good. I'd take this over JSX any time. Reason being this is more concise than writing JSX, and with better editor support (paredit mostly).

And you have gone full circle, back to writing Javascript but with parentheses.

Clojurescript offers much more than just a concise syntax.

Immutability by default alone has huge benefits.

There's "true" REPL. No, Javascript does not have a REPL, at best it has an "interactive environment". REPL is much more than a thing where you type a command into it and it spits out some statements.

There's consistency. In Javascript, because you don't have a standard library - there's none. Instead, you have Lodash, Rambda, Immutable.js, folktale, crocks, fantasyland, etc. etc. In Clojurescript for example, if you need to get the size of a set, vector, list, hash-map - there's a single function. In JS you have to know - sometimes it's .length, sometimes it is .size and there are many examples like that.

In Javascript, there's a precedence table with over 20 something items in it. Clojurescript doesn't even need one. There are like seven different things that can be "falsy" in JS, in Clojurescript only two - false and nil. These may seem to be like small things, but they add up.

Add to that, an enormous churn from libraries and tooling, Webpack alone (even though it is really good) may frustrate you for hours and days.

And like front-end wasn't enough, Javascript today is in the back-end too and although it is the same language, there are many inconsistencies you have to deal with, while Clojure and Clojurescript feel very much the same language, even though they are hosted on completely different platforms. You can actually can share code, the promise that has never gotten fulfilled for me with Nodejs.

And by the way, Javascript has way more parentheses and also commas, semicolons and curly braces. In Clojurescript parentheses give you structure and consistency, you stop noticing them after a while. In Javascript there's no consistency - arrow function with multiple params requires parens, with a single param - parens can be omitted, but with no params - parens are still required. Before Prettier you'd never even sure how to structure js code. Prettier simplifies things, but it still has so many options that vary from team to team, from a codebase to codebase. Single misplaced comma can make you feel like smashing your laptop. Write enough JSX and you get to a point where excitement from JSX turns into incurable frustration. In Clojurescript you don't even think about those problems.

So please stop treating Clojurescript developers like some kind of Lisp fanatics who hate Javascript for some made-up, bullshit reasons. We don't hate it. Most of us have consciously made our choice because it brings value and allows us to build things without mental overhead.

You could do more! Use Array.map and Function.apply via interop and you seem to have it all in JS

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.