7 Apr 2004 17:40
Re: [IDEA] auto-type coercion thoughts
On 7 Apr 2004, at 16:12, John Wilson wrote: > On 7 Apr 2004, at 15:57, jastrachan@... wrote: >> On 7 Apr 2004, at 10:41, John Wilson wrote: >>> So we are doing speculative conversions (which could have >>> significant computational overhead) to find the right function to >>> call. I think I'd prefer to have an isType() which says if the >>> conversion can be performed rather than trying and seeing what >>> happens when trying to find a function to call. >> >> I don't see how that would change anything other than making it more >> complex to implement and open the possibility of saying you can >> convert to a type but not actually implementing it (or vice versa)? >> > > toString(), for example, can be very costly and can have side effects. > I don't thing it's wise to do a conversion when you may not need the > result of that conversion. > > There are many ways of breaking the contract (returning an object > which is not an instanceof the requested type, for example. Though typically we'd only try convert a type to one kind of object. If we did 2 conversions, then we'd have ambiguity and so we'd be throwing an exception anyways. i.e. its only in rare exceptional cases that we'd ever try convert an object to 2 types - when we can't actually call the method - otherwise we'd only be doing a single conversion. So typically, if we did do this, we'd only call toType() once in typical usage. If we called it twice and returned 2 non-null values then it'd be an exception & we wouldn't be able to choose a method. James ------- http://radio.weblogs.com/0112098/
RSS Feed