News for hackers. Stuff that matters.
Re:Show HN: Textures.js, SVG Patterns for Data Visualization by ttty on Wednesday March 18, 2015 @10:10AM (#9225550)
I never like how they chain methods. A better way would be:

    texture({lines: true, heavier: true, stroke: 'red'})
Is easier to configure if you need reusable textures.
Re:Show HN: Textures.js, SVG Patterns for Data Visualization by mbostock on Wednesday March 18, 2015 @02:02PM (#9227424)
Aren’t these textures already reusable? The constructed texture object (the result of textures.lines(), e.g.) can be called on as many selections as you like to reuse it.

I feel it’s a matter of taste, but one practical reason I prefer chaining to configuration objects is that you get a runtime error when you misspell a property, rather than it being silently ignored.

Re:Show HN: Textures.js, SVG Patterns for Data Visualization by ttty on Wednesday March 18, 2015 @06:51PM (#9229183)
Image you have an UI which talks to this. For example you have a button on/off. How would you do?

    var t = texture().lines().stroke('red')
    if(this.button.on) t= texture.heavier()
Compare the previous with this one.

    var t = texture({lines: true, heavier: this.button.on, stroke: 'red'})
I also hate the non standard constructor: this should be like this

    var texture = new Texture({lines: true, heavier: this.button.on, stroke: 'red'});
Re:Show HN: Textures.js, SVG Patterns for Data Visualization by siddboots on Wednesday March 18, 2015 @11:53PM (#9230118)
"heavier: this.button.on" has ambiguous semantics. Do libraries really use this pattern?

Also, use of the "new" keyword is contentious. You can hardly pretend that it is best practice.

Re:Show HN: Textures.js, SVG Patterns for Data Visualization by ricsca on Thursday March 19, 2015 @10:50AM (#9232300)
It should be

    var t = texture().lines().stroke('red')
    if(this.button.on) t.heavier()
Re:Show HN: Textures.js, SVG Patterns for Data Visualization by ricsca on Wednesday March 18, 2015 @10:23AM (#9225647)
Interesting point. I simply relied o this post of Mike Bostock http://bost.ocks.org/mike/chart/.
Re:Show HN: Textures.js, SVG Patterns for Data Visualization by wayfarer2s on Wednesday March 18, 2015 @10:59AM (#9225943)
An initial config object would probably be ideal, and then you could have the chaining to supplement those values. You could have the initial method take in the config and use the values in that in place of the defaults. So

  textures.circles()
    .radius(4)
    .fill("transparent")
    .strokeWidth(2);
could initially be

  var circles = textures.circles({
    radius: 4,
    fill: "transparent",
    strokeWidth: 2 
  });
and later updated to be

  circles.strokeWidth( 1 );
Which works rather nicely especially when the config object is generated dynamically.
Re:Show HN: Textures.js, SVG Patterns for Data Visualization by bkirwi on Wednesday March 18, 2015 @12:32PM (#9226680)
Yeah, it makes sense to mimic the D3 style: the only thing worse than a bad convention is two conventions.
Re:Show HN: Textures.js, SVG Patterns for Data Visualization by findjashua on Wednesday March 18, 2015 @10:38AM (#9225762)
imho, if the operations are to be performed in a certain order, use chaining. Otherwise, passing a config object is much cleaner