4 ms·
It seems d3 would be easier to use if d3(...) would be an alias to d3.selectAll(...)
by xiphias 11y ago
It seems d3 would be easier to use if d3(...) would be an alias to d3.selectAll(...)
- dheera 11y ago$ = function(foo) { return d3.selectAll(foo); }
- chrtze 11y agoFrom my perspective I would rather have $.select() instead of $() because it makes more clear what this function actually does.
- ape4 11y agoFuture maintainers will hate that.
- Roboprog 11y agoDone as a global, then probably, yeah. If it's assigned at the beginning of a function as a local var, then used 5 or 6 times, probably no harm done.
- richardwhiuk 11y agoor $ = d3.selectAll; surely?
- prezjordan 11y agoYou also need to re-bind it to d3. $ = d3.selectAll.bind(d3); Since `this` in the `selectAll` will refer to whatever is before the period. When we reassign to `$` in `$ = d3.selectAll`, we lose that. Silly, isn't it? Demo: http://jsbin.com/guyisewexu/1/edit?js,console http://jsbin.com/guyisewexu/1/edit?js,console
- Nemcue 11y agoEase of use in the sense that you type less. I think it would be harder to use from the perspective of a new developer trying to learn D3. selectAll already has way too many responsibilities in my opinion, making it totally opaque what d3(...) really does. OTOH I guess it's kind of the same with jQuery(..), since it can do both selectors as well as create new Elements. D3 is one of those libraries that I really admire from a conceptual point of view, but boy do I wish the API was more newbie-friendly. It's rather indicative of an API that has room for improvement when you start noticing just how many tutorials, videos and books that have to explain D3.selectAll. "Well, you see — sometimes it doesn't really select anything, instead it does this other thing" Not to mention the source code. Very sparsely commented.
- couchand 11y agoI disagree that there's any problem with the API. I do agree that it can be hard for a new developer trying to learn, but I believe that it's worth it. By analogy, learning to code is hard for someone who has not yet done it, but it's still worth the effort, and you would never expect designers of "real" programming languages to dumb things down to make it easy for you the first time. Should we design our tools so that you can pick them up immediately or should we design them so they give us as much power as possible? I, personally, would prefer Englebart's violin.
- Nemcue 11y ago"Should we design our tools so that you can pick them up immediately or should we design them so they give us as much power as possible?" A thoroughly false dichotomy. It's not either or, it's varying degrees of both.
- mgold 11y agoIf someone thinks selectAll is inconsistent, they probably don't understand the central enter/update/exit pattern [1]. D3 is a powerful _drawing_ library and I've used it for totally custom visualizations where no canned tool would suffice. I think there's an un- or only partially-filled niche for more customizable _charting_ library that is more user-friendly. [1]: http://bl.ocks.org/mbostock/3808218 http://bl.ocks.org/mbostock/3808218
- candu 11y ago...in which case you'd have the same issue mentioned above with jQuery, in that d3.selectAll('.foo').selectAll('.bar'); $.find('.foo').find('.bar'); are consistent, whereas d3('.foo').selectAll('.bar') $('.foo').find('.bar') are not. IMHO, d3's API is cleaner.