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 / 23744
23743  |  23745
Subject: 
A structured programming question
Newsgroups: 
lugnet.robotics
Date: 
Fri, 18 Mar 2005 13:44:34 GMT
Original-From: 
Mr S <SZINN_THE1@YAHOO.COMsaynotospam>
Viewed: 
1058 times
  
All,

Not to start more discussion on structured vs.
unstructured programming, and I hope this doesn't.
This doesn't necessarily relate directly to the RCX,
but I would like to tap some of the knowledge that is
on this list. I have had no formal training for
programming, and would like to know what the 'correct'
way to handle value testing in a structured
programming manner.

With the RCX, often you know that the value is between
0 and some higher value, but when you are testing a
value and know that the value could be anything,
including garbage, how do you structure the testing?

Example:
If $value is > 50
then ... do something
end if

or

If $value is > 40 and < 65
then ... do something
end if

These tests only allow for the value being numeric,
and within a range of 40.0001 to 64.999.

Example:
If $value is numeric and > 40 and < 65
then .... do something
end if

or

if $value is not numeric
then ... do something
else if $value is numeric and > 40 and < 65
then ... do something different
end if

Both of the latter examples test for a negative result
prior to setting the action test. My question is this.
How correct is it to do this, test for negative
returns prior to acting on a positive return in the
test, when it is known that $value can be any possible
value.

I do realize that when you are managing your
variables, you should know what value will be
available. My question is about when you don't know,
such as reading the data log, or someone else's data
file, or say... grabbing data from the IR port from an
external host.

A switch or case statement handles this quite well,
allowing you to only test for desired values and
letting everything else fall to the default action.
Without a case or switch, using only if..then..else,
the programmer has to do this. I'm just wanting
confirmation on what is taught as the correct way.

In my code, I have had to do this in some places where
case and switch are not available. I am curious if
there is another way that is more functional, or less
wasteful of clock cycles?

Thanks

S



__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/



Message is in Reply To:
  Re: Robolab's string
 
(...) John, the program you are proposing for discussion is a good example for bad programming practise, you are absolutely right. I think Dijkstra was the first to insist to banish GOTOs from well structured programming. This was one of the things (...) (20 years ago, 18-Mar-05, to lugnet.robotics, FTX)

4 Messages in This Thread:


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

Custom Search

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