DM> Single entry. Single exit. Flow always goes
DM> down, except in properly
DM> defined structural loops (while, do while, for). Clean-up code will
DM> always get executed. Adding extra clean-up code will not break
DM> anything - it will also get executed every time because it is part of
DM> the single exit.
CD>
CD> Yeah... I've seen such things. It's not the only way to do it.
CD> Nor are alternative methods (IMO) "less readable".
DM> Without writing every pointer-resource into classes, I've been hard
DM> pressed to find other ways of doing it. Perhaps an example, Chris?
CD>
CD> I must be missing something as this sounds like pretty basic stuff
CD> to me. All you need do is create an appropriate class and we can
CD> get the same "will also get executed every time" functionality via
CD> a destructor rather than using gotos as a funnel to some shared
CD> code section.
Yeah, that's what I thought. "It's OBVIOUS!" When you need 10-12 resources
simultaneously due to a combination of required functionality and
management-imposed (sometimes even design-imposed) restrictions...
For example, trying to manage the autodetection of multiple protocols
(NetBIOS, TCP/IP, SNA, and another which I forget at the moment) in a GUI...
the APIs are all C. Sure, OCL/MFC could be used (ok, OCL since this is
Visual Age, not Visual)... except that we aree forced to a minimalist
approach: the ICLUI DLLs must be compressed (hey, we already use 3 CDs - the
extra few meg could push us to 4!), on the CD, so our install can't use them.
For the same space reasons, we can't statically link, either. So all
resource handles, etc., must be in our code, not hidden behind the OCL. If
we were to write enough classes to handle everything... we'd HAVE the OCL!
[And, by seperating too much, the speed, in this case, does drop
significantly. This is AFTER finding a seperation that gained speed.]
CD> You could be making a better case for the example you've described
CD> over on the C echo.
And sometimes you HAVE C code that you just renamed *.c to *.cpp, and need to
modify.
DM> Often writing a dozen small classes
DM> that handle resources is less readable than the goto.
CD> I would submit that if you needed a dozen small classes to avoid
CD> the goto, then the goto (or lack thereof) is not the problem.
The problem isn't always something we can avoid. goto will sometimes be a
better solution.
--- Maximus/2 3.01
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|