Re:PivotTable.js: a JavaScript Pivot Table implementation
by yen223 on Tuesday June 25, 2013 @04:06AM
(#5938139)
I'm not a Javascript expert, and I haven't used CoffeeScript before, but this block of code looks perfectly readable to me (except for that ugly mathematical equation). If this is supposed to be an example of unreadable code, then maybe it's time to learn me some Coffeescript...
Re:PivotTable.js: a JavaScript Pivot Table implementation
by TheAnimus on Tuesday June 25, 2013 @07:19AM
(#5938653)
Indeed, I've never given CoffeeScript more than a cursor glance, but I'll say that rates much higher in readability than average javascript I've written. If that is ment to be an example of bad pratice....
Re:PivotTable.js: a JavaScript Pivot Table implementation
by andypants on Tuesday June 25, 2013 @08:15AM
(#5938853)
sumOverSumBound80: (sigfig=3, scaler=1, upper=true) -> ([num, denom]) -> ->
The many arrows in the first line are confusing to me.
Re:PivotTable.js: a JavaScript Pivot Table implementation
by joesb on Tuesday June 25, 2013 @08:30AM
(#5938931)
In Javascript, that would be three level of nested function, equally if not more confusing.
Re:PivotTable.js: a JavaScript Pivot Table implementation
by nicolaskruchten on Tuesday June 25, 2013 @09:55PM
(#5943640)
I agree, this is the hairiest, least documented part of the API. CoffeeScript makes it easier to read than the corresponding Javascript construction but then again this might be CS encouraging things that wouldn't fly in JS for good reason :)
The pivot table needs an aggregator object per cell, so we need a factory-function to provide one (this is the right-most arrow).
That function needs to know which columns to use as the numerator and denominator, without these being passed in on every invocation, so I used a function-generator that closes over those two values.
The third, almost gratuitous layer of function calls allows one to parametrically generate this function-generator with different formatting options.
Re:PivotTable.js: a JavaScript Pivot Table implementation
by mokkol on Tuesday June 25, 2013 @04:46AM
(#5938246)
This is misleading. Of course like Javascript you can write terrible CoffeeScript code. There are plenty of terrible written Javascript code examples out there.
Re:PivotTable.js: a JavaScript Pivot Table implementation
by ianstormtaylor on Tuesday June 25, 2013 @03:02PM
(#5941655)
Absolutely, but you get by like Yen (replied) who think that it's completely readable. Whereas in Javascript you're going to have a much harder time arguing that a triple-nested function that returns an object with other functions inside of it is readable. This exact same code in Javascript would be a laughable offense, but people defend it to the death when it's Coffeescript because the complainers "just don't get it".
http://nodejsreactions.tumblr.com/post/51550250985/discoveri...
I also feel like CoffeeScript encourages incredibly complex practices just because the code can be written in a small amount of space. For example, here's a block of code from the library in question:
Have fun reading that... I think claims that CoffeeScript is a write-only language have very legitimate ground.