HNHacker News
TopNewBestAskShowJobs

kitcambridge

57 karma · joined September 7, 2011

submissionscomments
kitcambridge··on JSON 3: A modern JSON polyfill compatible with nearly all JavaScript platforms.
Fixed. Thank you!
kitcambridge··on JSON 3: A modern JSON polyfill compatible with nearly all JavaScript platforms.
Fixed. Thanks for the heads-up!
kitcambridge··on JSON 3: A modern JSON polyfill compatible with nearly all JavaScript platforms.
I, too, would love to see comments officially supported in the next iteration of the JSON standard...IIRC, Crockford removed them to make JSON a valid YAML subset.

For what it's worth, I've created a fork of Kyle Simpson's `JSON.minify` project that uses a variation of the character-based parsing process in JSON 3: https://github.com/kitcambridge/JSON.minify/blob/master/mini... It's somewhat cumbersome to use, though, as it needs to be called on a string before feeding it to `parse` (e.g., `JSON.parse(JSON.minify("/* Hello */ 123"))`).

kitcambridge··on JSON 3: A modern JSON polyfill compatible with nearly all JavaScript platforms.
That's correct. Currently, Firefox is the only browser that implements the JSON routines exactly as described in the spec (parsing since version 5.0, and serializing since 6.0)...others deviate in one or more ways. It's not so much of a concern if you're targeting multiple browsers, as Firefox will correctly throw a `SyntaxError` when given malformed input, but it can certainly become problematic if you're relying on non-standard extensions in only one or two browsers.
kitcambridge··on Maddy 0.3.0, a functional object operations library
Most of the additional aliases are taken directly from Ruby's `Enumerable` module (though both `fold` and `reduce` are common names for that function; not sure why Ruby called it `inject`), but I definitely agree. One name should be sufficient, especially with the availability of the API documentation.
kitcambridge··on Maddy 0.3.0, a functional object operations library
Normalizing `for...in` iteration in Underscore has actually been discussed before...the consensus was that it wasn't worthwhile to overload `_.each`, and that the use of objects as hashes in JavaScript was inherently broken. As such, Maddy was created to provide a consistent interface for working with objects, not arrays or array-like objects. You'll also notice that Maddy conforms to the functional pattern seen in other languages, rather than the generic pattern used in Underscore: the arguments to all iterator methods are `callback, [context], object`. This makes it easy to invoke `Maddy.curry` on a functional method, and then use an identical iterator function and optional context for multiple objects. This is one of the advantages of functional programming, and how Maddy distinguishes itself from other libraries.

Secondly, Maddy implements other features apart from iterator functions, including deep equality and object serialization. These methods operate on cyclic structures, which I've yet to see fully supported in any other functional JavaScript library. I've contributed a patch to Underscore that adds support for cyclic structures to its `_.isEqual` method, but it's still in review, and will likely remain so for some time.

Finally, while Maddy was philosophically inspired by Underscore, it isn't intended to replace or challenge it. You're free to continue using it as you prefer; I'm not suggesting that you replace Underscore with Maddy in your code. They are different libraries with different target audiences: Underscore is a general-purpose utility library, Maddy is a niche object operations library. In sum, it's simply another option for those wanting a more conventional functional programming library to work with objects.

kitcambridge··on Maddy 0.3.0, a functional object operations library
They're not quite the same. Underscore is primarily for working with arrays and index-based collections, not objects. Furthermore, it doesn't normalize common iteration bugs, such as the JScript `[[DontEnum]]` bug, Safari 2 property shadowing bug, and inconsistent enumeration of the `prototype` and `constructor` properties. In short: Underscore is best, and far more efficient, if you're working with arrays; Maddy is best if you're working with objects.