News for hackers. Stuff that matters.
Re:Replacing jQuery with D3 by xiphias on Friday May 15, 2015 @07:33AM (#9549939)
It seems d3 would be easier to use if d3(...) would be an alias to d3.selectAll(...)
Re:Replacing jQuery with D3 by Nemcue on Friday May 15, 2015 @07:45AM (#9549980)
Ease 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.

Re:Replacing jQuery with D3 by couchand on Friday May 15, 2015 @08:36AM (#9550147)
I 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.

Re:Replacing jQuery with D3 by Nemcue on Friday May 15, 2015 @09:34AM (#9550417)
"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.

Re:Replacing jQuery with D3 by mgold on Friday May 15, 2015 @12:23PM (#9551628)
If 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

Re:Replacing jQuery with D3 by dheera on Friday May 15, 2015 @07:41AM (#9549965)
$ = function(foo) { return d3.selectAll(foo); }
Re:Replacing jQuery with D3 by richardwhiuk on Friday May 15, 2015 @08:24AM (#9550104)
or $ = d3.selectAll; surely?
Re:Replacing jQuery with D3 by prezjordan on Friday May 15, 2015 @10:01AM (#9550595)
You 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

Re:Replacing jQuery with D3 by chrtze on Friday May 15, 2015 @07:56AM (#9550014)
From my perspective I would rather have $.select() instead of $() because it makes more clear what this function actually does.
Re:Replacing jQuery with D3 by ape4 on Friday May 15, 2015 @08:12AM (#9550061)
Future maintainers will hate that.
Re:Replacing jQuery with D3 by Roboprog on Friday May 15, 2015 @11:45AM (#9551335)
Done 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.
Re:Replacing jQuery with D3 by candu on Friday May 15, 2015 @11:49AM (#9551369)
...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.