News for hackers. Stuff that matters.
Re:Why is D3 so Verbose? by balamatom on Thursday August 21, 2025 @10:20AM (#44973151)
I'd say because JavaScript is insufficiently expressive. No macros, no arrow (pipe) operator, and the premier way of writing it is 4x as verbose than what I'd consider reasonable. D3 is a great library though.
Re:Why is D3 so Verbose? by TheHeasman on Thursday August 21, 2025 @11:19AM (#44973897)
Uh, there are arrow operators in JS. D3.JS in Action Third Edition exclusively uses arrow operators.

(Trust me. I don't know jack about JavaScript, I had to get through the MDN docs to understand what they were, and once I did, made a whole lot more sense).

Re:Why is D3 so Verbose? by tomku on Thursday August 21, 2025 @12:14PM (#44974545)
The feature the person you're replying to is talking about is not arrow functions (`=>`), but what are called "threading macros" in other languages. In Clojure[1], the main one is named `->` and used as a way to thread a value through a series of functions that take it as a first argument, using the return value from the first function as the first argument to the second, and so on. It allows you to use a series of plain functions to transform a value instead of method chaining.

JS does not have a straightforward equivalent. The old and deprecated `with` keyword might seem similar but it's only a surface resemblance as it does not perform the return-value threading that makes the above pattern useful, it was meant for methods that mutate object state. There's a TC39 proposal[2] to add a pipe operator that would accomplish a similar thing to threading macros via an infix operator but it's still a draft.

[1]: https://clojure.org/guides/threading_macros

[2]: https://github.com/tc39/proposal-pipeline-operator

Re:Why is D3 so Verbose? by TheHeasman on Thursday August 21, 2025 @06:45PM (#44979051)
I stand corrected. Thanks for pointing that out. Learned something new.
Re:Why is D3 so Verbose? by balamatom on Thursday August 21, 2025 @11:51AM (#44974295)
And I know more about JavaScript than I'd like to, so don't trust me.
Re:Why is D3 so Verbose? by DanielHB on Thursday August 21, 2025 @10:32AM (#44973281)
what do you mean by "arrow operator"?
Re:Why is D3 so Verbose? by amiga386 on Thursday August 21, 2025 @10:55AM (#44973566)
Probably a reference to Clojure's arrow operator:

https://blog.frankel.ch/learning-clojure/2/

Something like a(b(c(d(e(7)))))) in Javascript could be written (-> 7 e d c b a) in Clojure?

Re:Why is D3 so Verbose? by balamatom on Thursday August 21, 2025 @11:49AM (#44974266)
Bingo.
Re:Why is D3 so Verbose? by lionkor on Thursday August 21, 2025 @10:34AM (#44973309)
Maybe overloadable operators like in C++, where -> usually demotes some kind of deeper access into the object or abstraction? Or, the opposite, and abstracted access.
Re:Why is D3 so Verbose? by DanielHB on Thursday August 21, 2025 @11:45AM (#44974227)
That is what I thought, but that doesn't make sense for a language without pointers

According to the other comment it seems he meant the |> pipe operator that is under proposal in js