Dear all
What's the suggested replacement for the (since 7.1) obsolete assignment
attempt? I don't see a satisfying replacement for it.
Consider for instance (with the obvious corresponding classes):
dog ?= animal
I consider it syntactic sugar for:
if attached {DOG} animal as tmp_dog then
dog := tmp_dog
else
dog := Void
end
If I have to replace all assignment attempts (originally 1 line) with 5
lines of code where I have to specify the type again, that's not
extremely great and also quite detrimental to readability (nesting).
Another solution would be (slightly different semantics of course):
check attached {DOG} animal as tmp_dog then
dog := tmp_dog
end
This is about 3x slower than assignment attempt (already useless for
me), takes 3 lines instead of 1 and I also have to specify the type again.
Last but not least there would also be:
dog := {DOG} #? animal
Finally, only one line. But again about 3x slower and multiple
declarations of the type; also not satisfying for me.
Maybe an actual example might help the discussion:
I use(d) assignment attempt extensively. Almost exclusively in places
where I know it cannot fail like with INTERNAL.new_instance_of. In the
super unlikely case that it would fail, I would in the following
statement get a "call on Void target" exception; that's good enough. So,
originally I have:
dog ?= internal.new_instanceof_of (foo)
dog.bark
This would now become (I can't use "check" and "{DOG} #?" because it's
too slow):
if attached {DOG} internal.new_instanceof_of (foo) as tmp_dog then
dog := tmp_dog
else
dog := Void
end
dog.bark
-- more code
I can't remove the else branch. Otherwise (e.g. in a loop where "dog"
might be set multiple times), it would become undebuggable in case of
failure if there's already an old value. Another translation would be:
if attached {DOG} internal.new_instanceof_of (foo) as tmp_dog then
dog.bark
-- more code
else
(create {EXCEPTIONS}).raise ("Houston, we ran out of beer!")
end
I don't like either replacement.
So my questions:
- What is the recommended replacement for assignment attempt?
- Why is a "check-then" statement 3x slower than an "if" statement that
raises an exception in the else branch?
Thanks
Marco
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/eiffel_software/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/eiffel_software/join
(Yahoo! ID required)
<*> To change settings via email:
eiffel_soft...@yahoogroups.com
eiffel_softwar...@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
eiffel_softwa...@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/