HNHacker News
TopNewBestAskShowJobs

toxmeister

132 karma · joined November 4, 2014

submissionscomments
toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
Will respond more about that later, but just wanted to point you to Phil Wadler's 1999 paper about both XML and the S-expression approach (HTML/XML are essentially S-expressions too):

http://homepages.inf.ed.ac.uk/wadler/papers/next700/next700....

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
That's because that demo is using SVG for graphics and hence updating 300+ DOM elements every frame will of course start stuttering... Once I've updated that example to use the hdom-canvas support lib (https://github.com/thi-ng/umbrella/blob/master/packages/hdom...) this will be a non-issue. E.g. here's another demo which draws 10k rectangles @ 60fps. Only once I go >25K, I'm starting to loose framerate (MBP 2016):

https://demo.thi.ng/umbrella/hdom-canvas-shapes/#points-10k https://demo.thi.ng/umbrella/hdom-canvas-shapes/#points-50k

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
Merci beaucoup & please see my other comment about this...
toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
For me generally too, but I was afraid of the typical counter example: Perl oneliners, size coding in general...

I think there's fine line between aiming to be lightweight and aiming for smallest whatever by sacrificing all other aspects . I'm definitely in the former camp...

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
hehe... just not an accomplished documenter of his works. those "websites" are all ancient. don't bother visiting!
toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
Thanks! The estuary package started in Java[1] back in 2011, but after years of learning from mistakes, several attempts in Clojure & endless refactoring has now morphed in this TS package[2], which I'm slowly getting more happy with...

That demo will need to be refactored too and the plan is to extract those SVG components into their own package sometime during the winter break...

[1] https://www.flickr.com/photos/toxi/albums/72157627351329656

[2] https://github.com/thi-ng/umbrella/blob/master/packages/rstr...

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
I completely appreciate that there're many people who much prefer the separation between code and markup, however, if you ever worked w/ Lisp you'll also learn to appreciate that code is just data and that the earlier separation really is just a convention. Maybe that convention is much better suited for supporting different job descriptions in companies (UX vs. dev), but it's also somewhat arbitrary...

The benefits of the component as plain, non-stringified data are not the avoidance of closing tags, but what you can do with those components computationally. E.g. instrumentation, behavior/attribute injections, configuration, filtering etc. An approach based on string interpolation can only go this far, whereas having everyting as arrays, objects, iterators your possibilities of composition & transformation are almost endless...

Also, take for example the hdom-canvas support library which doesn't target the DOM itself, but defines virtual elements translated into drawing calls. Using the string interpolation approach would be complete overkill since these elements would have to be re-parsed again, in which case SVG would be faster. But I can easily manage 10k+ moving particles @ 60fps with the hdom approach:

https://demo.thi.ng/umbrella/hdom-canvas-shapes/#points-10k

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
Ps. Thanks for the kind words!!! :)
toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
I commented on this recently on twitter & reddit:

https://twitter.com/toxi/status/1041143431786115072

https://twitter.com/toxi/status/1041144813092044800

https://www.reddit.com/r/Clojure/comments/9deyxe/thinggeom_a...

Hth!

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
"Afterthought" is too a strong a term, but the largest aspect of that latest version of the library was to generalize the approach to aim at other non-DOM targets. I left another comment about this somewhere else in this thread. Basically, you can choose branch-local implementations of the main hdom interface. If none is provided, it uses the default one which targets the DOM...
toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
I actually did mention Reagent in the readme in this section (below the diagram): https://github.com/thi-ng/umbrella/tree/master/packages/hdom...

Quote: "The syntax is inspired by Clojure's Hiccup and Reagent projects, which themselves were influenced by prior art by Phil Wadler at Edinburgh University, who pioneered this approach in Lisp back in 1999. hdom offers several additional features to these established approaches."

However, Reagent also still relies on React under the hood whereas hdom is completely standalone. Also, hdom has a lot more features in terms of what kind of values are supported within an hiccup tree and additionally, in this latest version (5.0), hdom already has been extended to support non-DOM targets to update. Currently, the only user of this feature is the hdom-canvas package (https://github.com/thi-ng/umbrella/blob/master/packages/hdom...), which allows you to define canvas scene graphs in the same way as the rest of the UI, but those virtual shape elements are translated into canvas draw calls. A WebGL version of this is in early progress. In general, by implementing a certain interface you can support any other target context/data structure.

Ps. I've never used Om so didn't list it as an active influence.

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
Thanks & I used to do 12+ years of Java and other OOP languages myself before I started using Clojure in 2011 and ever since got hooked on the more functional approach without trying to become a fundamentalist FP. These days I'm mainly using TS, Clojure/ClojureScript, Go, C (not C++)...

Re: the above example - you didn't really explain which aspects you find alienating, but finding this hard to read, could have to do with the fact that this demo uses a few other concepts & libs not very popular in the JS world (specifically transducers)? I totally grant that without prior knowledge of those constructs this specific code is not the easiest to comprehend (though I've tried to comment every step).

In general though, IMHO this approach is a lot more direct and lightweight than any OOP solution. Having your entire UI defined using native ES6 primitve data structures, provides huge potential and endless options to transform raw app state into UI components. If you ever worked with a Lisp, you'll also find the nested inline definitions not that hard to read. To me it's also more legible than having an (often) over-engineered, multi-layered OOP architecure, riddled with inheritance and so on... Though again, this all is highly subjective. There's certainly ample opportunity to refactor this example into smaller functions and I might as well do that when I get a chance...

toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
Agreed. I also don't see it as key feature, but listed it more in nod to point out that hiccup format is less verbose. smaller file size also means less to read for humans (although, in general that itself doesn't mean better legibility :)
toxmeister··on Show HN: Thi.ng/hdom – S-expression based, pure ES6 UI/VDOM components
I dunno, there's a 1000+ LOC readme there. Also updated the above link to point to it directly. It's a shame that GH is automatically displaying the readme on desktops, but not in mobile version...
toxmeister··on Literate programming: presenting code in human order
Author here: Agreed & most parts of this particular project aren't really the best example. With other (newer) projects I embraced the LP style much more, and in fact by now really often first write the prose parts to get my head clear about a certain aspect and only then start writing code, e.g.

https://github.com/thi-ng/fabric/blob/master/fabric-facts/sr... https://github.com/thi-ng/geom/blob/develop/src/viz/core.org

As for the docstrings included in the core, this is largely to address complains from other users, who are used to have docs available in the REPL and I often don't have the resources/time to provide both org-mode and docstrings...

toxmeister··on A stream of human generated randomness
Hi, author here... you can find more information about the context of this project here: https://medium.com/@thi.ng/evolutionary-failures-part-1-5452...
toxmeister··on Ask HN: Who's using Clojure in production?
http://devartcodefactory.com is 100% Clojure + Clojurescript (+ open source) and one of the few examples deployed on Google AppEngine
← PreviousPage 2 of 2