SonOfLilit
2/18/2007 1:22:00 PM
On 2/18/07, Marcello Barnaba <bofh@softmedia.info> wrote:
> Hi,
>
> On Sunday 18 February 2007 13:16, SonOfLilit wrote:
> > Say, why not just define Object#mutable? and solve the issue of not
> > knowing if dup is possible or not?
>
> In my opinion, this exposes at the ruby level an implementation detail that
> pollutes the language design, and you must add it to the "weird things you
> should remember".
>
> Please, compare
>
> def a
> obj = some_method
> raise 'hey!' unless obj.mutable?
> do_stuff obj.dup
> rescue SomeMethodError
> pull_out_the_power_cord
> end
>
> to
>
> def a
> do_stuff some_method.dup
> rescue SomeMethodError
> pull_out_the_power_cord
> rescue TypeError
> raise 'hey!'
> end
>
> I think that the whole design is clear and makes sense, you can call a method,
> and you should catch exceptions, if you care about them. Or let them stop
> execution, if needed.
>
> > Sure, it only works to tell you about one possible reason it's not,
> > but it seems like a good workaround, far better than, say, duping just
> > to check.
>
> Why should "dup" behave differently than all the other methods that raise
> exceptions when something exceptional happens? :)
>
Because it's something exceptional that is very predictable and we
might want to know about it in advance.
My workaround is an addition, not a modification. For most cases,
rescue TypeError is perfectly fine, but sometimes we might want to
validate that a received object is dup-able at the beginning of a
method, before doing some hard work that would only _later_ require
duping it.
That's why I support having a way to know if oyu'll be able to dup.
> my 0.02c
> --
> pub 1024D/8D2787EF 723C 7CA3 3C19 2ACE 6E20 9CC1 9956 EB3C 8D27 87EF
>
>
Speaking of which, why IS mutability of certain objects left as an
implementation detail? I think we assume mutability/immutability of
objects a LOT at coding time, and for a different implementation to do
otherwise would certainly have performance implications and probably
even make code written for say MRI break, isn't it so?
Perhaps mutability/immutability should be in the spec?
Aur Saraf