Live data from Hacker News

Bringing functional to the frontend – Clojure and ClojureScript for the web

blog.getprismatic.com

51–60 of 64 posts

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#51
post #46

the dom is a mutable data structure and the native (fast) dom apis expose mutable interfaces. so dynamic sites (you know, single page html5 apps doing all sorts of client-side dom manipulation) are either going to be slow, or are going to have an imperative core, which is where you need functional programming the most ;( maybe HTML6 will have native functional dom manipulation and we can rewrite all our favorite java…

I'm afraid you're confusing data structures (such as vectors, sets and maps) with the document model object. Not even in JS the DOM and objects are the same - some properties of the DOM have 'magical behavior' attached. ClojureScript does not provide any functional interface to the DOM - that would involve a Haskell-like model of programming (monads etc), which Clojure programmers rarely do in practice.

i don't think i'm confusing anything. Clojure programmers love their persistent data structures, and in a browser environment, the most important data structure - the document model object - is not persistent and cannot be made persistent in a performant manner because it is a native api.

there is ongoing research into dom manipulaton in clojurescript - Conrad Barski presented one approach[1] at Conj 2012 where the dom is mirrored in clojurescript data structures, and then 'synced' with the dom - so that way the imperative ickyness is tucked away in the sync method - it remains to be seen if that can be made fast enough until we get a native persistent interface to the dom.

[1] https://github.com/drcode/webfui

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#52
I agree that using data as templete is great. This is a typical example of "The value of value"(Rich Hickey's speech).

And I think client side have a bit different requirement compared to server side. At client side, I often need to manipulate specific element instead of root element which crate and dommy return. So I forked crate in order to get a collection of created elements as a hashmap. https://github.com/hozumi/crate-bind This is useful. I will create dommy version of this.

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#53
post #46

Earlier quoted context omitted.

I'm afraid you're confusing data structures (such as vectors, sets and maps) with the document model object. Not even in JS the DOM and objects are the same - some properties of the DOM have 'magical behavior' attached. ClojureScript does not provide any functional interface to the DOM - that would involve a Haskell-like model of programming (monads etc), which Clojure programmers rarely do in practice.

i don't think i'm confusing anything. Clojure programmers love their persistent data structures, and in a browser environment, the most important data structure - the document model object - is not persistent and cannot be made persistent in a performant manner because it is a native api. there is ongoing research into dom manipulaton in clojurescript - Conrad Barski presented one approach[1] at Conj 2012 where the d…

Characterizing side-effects as a series of supposedly functional transformations doesn't sound quite alright to me.

That said I'm curious about such an approach.

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#54
Another option for functional on the front end (and back end) is LiveScript. http://livescript.net/ Many people may not have heard of LiveScript.

I prefer LiveScript for a number of reasons, starting with the fact that I just don't like brackets and parentheses enough to want to use them everywhere.

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#55
post #19

We use ClojureScript (and Clojure) at http://economi.co and I'm really enjoying it. Maybe one of the most difficult things coming into it is trying to relate it to something like BackBone. However generally speaking in Clojure the culture is more about libraries than frameworks. C2 http://keminglabs.com/c2/ which on the outset looks just like a ClojureScript version of d3 is actually a great library to use instead of…

Don't worry about how anything compares to frameworks, because they don't matter anymore. We think traditional frontend frameworks - whether of the rails/django variety or the backbone variety, are generally rubbish in a nearly infinite number of ways. It's a style of programming based on wrapping weak mutation oriented idioms behind monolithic APIs and design patterns. We think default functional style and fine grai…

> generally rubbish in a nearly infinite number of ways

What?

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#56
post #2

Author here. Happy to answer any questions or comments.

"about a year and a half ago ... a relative absence of development tools for building and debugging apps."

I looked at ClojureScript when it was first released, and came to the exact same conclusion. I'm very interested to know how debugging ClojureScript works out for you. From what I remember, the ClojureScript -> JavaScript step generated some code that could be fairly difficult to follow. Also, in your experience, how well does it integrate with other JavaScript libraries?

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#57

Earlier quoted context omitted.

Don't worry about how anything compares to frameworks, because they don't matter anymore. We think traditional frontend frameworks - whether of the rails/django variety or the backbone variety, are generally rubbish in a nearly infinite number of ways. It's a style of programming based on wrapping weak mutation oriented idioms behind monolithic APIs and design patterns. We think default functional style and fine grai…

It may be the future for very skilled developers that have already familiarised themselves with frameworks and design patterns and are capable of moving past them. The majority of software developers benefit enormously from the conventions encouraged in a framework like Rails. If Clojure is going to be adopted widely (if that is a goal of the project at all), the community needs to work on better communicating best p…

Eh, even the least charitable would have to admit that frameworks enforce style. On a large project, this matters hugely. I don't care how good your devs are they DO have different opinions re: style.

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#58
post #48

If you're interested in a functional approach to UI code, check out functional reactive programming (FRP). It's a declarative way to specify UI logic which abstracts away much of the inherent messiness of using mutable state and callbacks. I've played around with FRP in Haskell, and have found it much nicer than the more standard approaches to implementing UI logic. Before using FRP, my main UI experience was with Ja…

I recently finally understood FRP and I'm working on my own library on top of Flapjax and Enfocus (ClojureScript) to make things simpler than doing everything by hand.

However, I can't find examples of systems of moderate (or big) size - nothing to get inspiration from, all examples I've seen are quite small and do too much by hand. They often select elements (like button to track click on) from whole document by id (and in big app this is pretty useless except for some top-level elements), or interwind templates with bindings to events and interaction between them is structured so that it feels like almost using globals. Directly changing top-level data from some inner template.

Anyway, I've got some ideas - display is easy though, what's hard is nicely structuring forms and buttons IMO - but it takes time to carve them out in code. I would love to read something on topic of structuring applications, which are more than a single input and a single list.

Re: Bringing functional to the frontend – Clojure and ClojureScript for the web

#59
post #2

Author here. Happy to answer any questions or comments.

Why jQuery, when ClojureScript already comes with a framework? It's easy to wrap it by a thin layer if you don't like the API, but then you get working advanced mode and one external dependency less.
Post reply on HN