On Thu, 29 Aug 2013 16:43:43 +0200 Roman Neuhauser <[email protected]> wrote:
> # [email protected] / 2013-08-29 16:10:14 +0200: > > Nothing is black and white and one has to think about degrees of > > various positive and negative effects (even of the same kind) in > > different situations. In case of hashes with defaults, the positive > > effects seems small (a bit of DRY) and the negative ones large (big > > surprise at call site). > > back to serious mode (on my part). > > you said: > > > To illustrate this, imagine I am debugging something and see code > > like this: > > > > result = my_hash["key"] > > this is a strawman, nobody sane names their variables "my_hash". > so let's say we have this code: > > def parse input, options > Parser.new(options['strict']).parse(input) > end > > you have no idea what type `options` is, all you know (actually hope > for) is it has a `[](key)` method. > > looking at it from the other side, how come you don't mind objects > with `[](key)`? they are *not* Hash, they have all kinds of > "unexpected" behaviors, so really, what's the difference? > From dmajda POV problematic part is when you debug. It means you add e.g. some inspect call (e.g. in debugger) and see what happens: h = Hash.new {|h,k| k } => {} h[:a] => :a h.inspect => "{}" so this part can cause problem. If it somehow say that I am hash with defined defaults, then it is much better. Josef -- To unsubscribe, e-mail: [email protected] To contact the owner, e-mail: [email protected]
