dkubb / adamantium

Create immutable objects
MIT License
373 stars 13 forks source link

Memoize methods that depend on instance state automatically #9

Open dkubb opened 11 years ago

dkubb commented 11 years ago

An immutable object's state never changes, so the #hash, #inspect and #to_s methods are idempotent. These methods should be memoized by default.

mbj commented 11 years ago

I like this change.

We have to communicate methods need to be present / changed before Adamantium is included. Especially in conjunction with Equalizer.

Correct:

class Foo
  include Adamantium, Equalizer.new(:foo)
end

Incorrect:

class Foo
  include Equalizer.new(:foo), Adamantium
end

Module#include does include modules in reverse order.

dkubb commented 11 years ago

@mbj sure, the first thing we could do show examples using include on separate lines, then it's more clear the ordering of things. We can have an "advanced" section showing this one-liner, which includes Equalizer first then Adamantium.

mbj commented 11 years ago

I just remember a chat conversation in #jruby, we improved performance on rack hashes with using separate String subclasses for keys that freezed contents and cachesObject#hash I lost the gist the guy created but we had around 20% speedup.

dkubb commented 10 years ago

@mbj wdyt about https://github.com/dkubb/adamantium/pull/25 ?