

Maddy 0.3.0, a functional object operations library - kitcambridge
http://kitcambridge.github.com/maddy

======
noelwelsh
Underscore.js is a relatively well-known library in the same space. What does
Maddy give me that Underscore doesn't (other than correctly calling fold
fold)?

~~~
kitcambridge
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.

~~~
skrebbel
Uhh.

I use _.map and co with objects all the time. It works fine. I don't see how
it is any different from Maddy.map. What did I miss?

Also, if _the_ major difference is bugfixes in iteration, why don't you just
contribute to underscore?

~~~
kitcambridge
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.

~~~
skrebbel
Thanks for the in-depth answer.

I'm clearly too noob to understand the "that the use of objects as hashes in
JavaScript was inherently broken". I understand you disagree with this
conclusion? Is there any URL to the discussion that I can read? And why do you
disagree?

------
perfunctory
> fold, inject, reduce

What's up with all these aliases? Isn't one name enough?

~~~
kitcambridge
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.

