Patricia said:
Andrew McDonagh wrote:
....
I agree that one should not emulate goto, or even think
about emulating goto. More generally, it is a mistake when
learning language B to think in terms of emulating low level
features of language A. It is much better to think in terms
of how to solve a problem in B.
However, I don't understand the relationship between the
use, or non-use, of goto and OO.
Its just IHO, goto puts too strong an emphasis on procedural code within
the OO classes. This makes the restriction of being able to replace the
conditionality statements with polymorphic calls.
In essence, we'd have procedural function calls, rather than messages
between objects.
If Java had its entire object structure just the way it is
now, but didn't have try-finally, I would want a way
to implement clean-up code.
There's always pure OOA/D/P ways of performing clean-ups, the Java
try-finally merely makes this 'simpler' to implement. Essentially the
try-finally construct could be thought of, as a means of decorating
certain object messaging, with some additional 'clean-up' afterwards.
Don't get me wrong, having this ability built into the language can be a
good thing.... but not always.
Personally I've never yet encountered a situation where I've needed the
try-finally construct. As its always been more appropriate to have
greater control over the 'clean-up'. Sometimes this control has been via
polymorphic messaging too.
Not that using it would worry me, I just haven't required it (yet).
Conversely, if exception
handling and final clauses were added to C, with no other
changes, I would not have used its goto.
Patricia
I can understand your point. However, there are C developers who do not
ever or very rarely use Cs goto. They prefer conditional logic within
the function to handle the situation.
Andrew