To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 21643
21642  |  21644
Subject: 
Re: Are there GOTO statements in NQC?
Newsgroups: 
lugnet.robotics
Date: 
Thu, 20 Nov 2003 17:49:27 GMT
Viewed: 
834 times
  
In lugnet.robotics, Vadim Iosifovich Vaynerman <dimav@Glue.umd.edu> wrote:

I REALLY need to use a goto statement in the NQC programming project I'm
doing for the RCX. Dows anybody know if such a statement extsts, and if
so, what the syntax is? I know gotos are bad programming practice, but its
really hard to make a workaround here. All ideas are appreciated.

I'm probably in the minority here, but I'm going to come right out and say that
goto's are not a bad thing, contrary to popular belief.  In fact, I find it
rather pompous when I come across admonishments in textbooks that there is no
valid reason to use a goto statement.  This advice presumes that the language in
question is perfect and can elegantly handle all possible control flow
structures.  Many times, the language is deficient and you find yourself adding
all sorts of flags and subroutines to come up with a control flow that doesn't
use a goto statement.  Hogwash.  There is no shame in it, I say!  If you find
yourself doing these things to make your code "pretty", try using the goto and
see if your code doesn't become more efficient and easier to read.

In C, you have the break statement to exit for/while loops.  This same statement
is used to exit switch statements.  If you want to exit a for/while loop while
in a switch statement, you have to play games like adding a flag or messing with
the condition statement that exits the loop.  Oftentimes, this ends up
needlessly introducing extra code or makes your true intent less readable.  It
also makes your code more prone to maintenance bugs because if you ever alter
the loop condition you have to alter all the places in your loop where you use
these special tricks to exit the loop.

Sometimes (in C) you may want to exit an outer loop from an inner loop.  Again,
you can play games with the exit condition (but not always) to find a means to
exit both loops "gracefully", but oftentimes you create obfuscated code to
achieve this.  You might also try bundling things up in subroutines, but here
you sacrifice speed for "elegance", which can be especially critical for
applications in embedded environments.  Of course, in this situation you could
revert to assembly language where goto statements are de rigueur, but why do so
if you could just as easily use C with a goto statement in that situation.

Now, to be sure, you can misuse the goto statement and I'm sure that's the
motivation behind the textbook taboo.  The logic being that if you don't use it,
you can't get yourself into trouble.  But, my view is that people often cause
trouble for themselves precisely because they don't use a goto statement where
it is desirable because of an inadequacy in the HLL language.  IMO, the
textbooks should instruct better on when it is advisable to use a goto, not just
take the easy route and say "Down that road lies shame!".

There.  Sorry for the rant, but this is one of my pet peeves.

Mark



Message has 2 Replies:
  Re: Are there GOTO statements in NQC?
 
(...) As a general rule I do not use goto's because I don't have a need for them. I've coded so many LOC in my life that the "if then else" structure of modern language was a step up from where I started. :^) The original BASIC and FORTAN had gotos (...) (21 years ago, 20-Nov-03, to lugnet.robotics)
  RE: Are there GOTO statements in NQC?
 
(...) <snipped rant> (...) And as a longtime embedded guy myself, I agree with Mark. It's the old sharp tools and dull craftsman thing. In the hands of a practiced expert, the goto can be a thing of beauty and can make the code more readable, which (...) (21 years ago, 20-Nov-03, to lugnet.robotics)

Message is in Reply To:
  Are there GOTO statements in NQC?
 
Hello all, I REALLY need to use a goto statement in the NQC programming project I'm doing for the RCX. Dows anybody know if such a statement extsts, and if so, what the syntax is? I know gotos are bad programming practice, but its really hard to (...) (21 years ago, 20-Nov-03, to lugnet.robotics)

19 Messages in This Thread:









Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR