Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: A conundrum in C: found this fragment in Steve McConnell's CODE COMPLETE
<benmarco7@mail.com> wrote:

> CODE COMPLETE, page 356
>
> if(StatusOK)
>   {
>   if(DataAvail)
>     {
>     ImportantVar = x;
>     goto MID_LOOP;
>     }
>   }
> else
>   {
>   ImportantVar = GetVal( );
>   MID_LOOP;
>
>   /*  lots of code  */
>   . . .
>   }
>
>  * * * * * *  end fragment * * * * *
>
>   The idea here is to rewrite the code without the goto LABLE.

I'd say, encapsulate the "lots of code" as a function, since it's
called under at least two different contexts.  Pass it enough
arguments (perhaps pointer arguments if it needs to modify its
inputs) that it can operate in all the contexts it needs to.
(And perhaps if it's really *LOTS* of code, break it up still
further into sub-sub-routines.)

Yes, I'd recommend that even if the original author's "intent"
was something quite different.  It's important to *understand*
his/her intent, yes; but you need not be bound by it.  (Unless
the person is your boss.  ;-) )

My general philosophy in C (or C++, or Perl) is, keep all functions
(subroutines) quite short, and never duplicate anything.  If I
see the same block of code being used even TWICE, I cut it out,
put it in its own function, and call it, rather than trying to
either duplicate it or jump to it with goto.

(I sometimes do use goto, but mostly for error handling inside
nested loops.)

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant



Report this thread to moderator Post Follow-up to this message
Old Post
Robbie Hatley
04-03-08 03:07 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 12:49 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.