soulcutter / saxerator

A SAX-based XML parser for parsing large files into manageable chunks
MIT License
128 stars 19 forks source link

Delegation removes functionality of 'is_a?' and 'kind_of?' #49

Closed fanantoxa closed 7 years ago

fanantoxa commented 7 years ago

On this commit https://github.com/soulcutter/saxerator/commit/220ac9bffad22c94a587e124e86622ba441dc26a#diff-9bea3d175ebbd6d9862278ff1d538242 You've change inheritance to delegation.

But users expect kinda simple elements lite String, Integer, Array and I think it's fair. so now to check that ArrayEllement is kinda Array we have to do:

some_item.is_a?(Saxerator::Builder::ArrayElement)

But it's not so usefull as

some_item.is_a(Array)
or
some_item.kind_of(Array)

@soulcutter What do you think about it?

fanantoxa commented 7 years ago

@soulcutter Readed http://words.steveklabnik.com/beware-subclassing-ruby-core-classes article. But maybe we could override 'is_a' or 'kind_of' functions to check it? or it even worse idea?

soulcutter commented 7 years ago

99% of the time is_a? or kind_of? checks are not a good thing to do in Ruby. It's not idiomatic to do type checking where duck typing is the norm. With delegation you can still treat the object as an array, it just happens to wrap one to accomplish array-like features.

I definitely don't think overriding is_a? or kind_of? is a good idea.