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 / 23746
23745  |  23747
Subject: 
Re: A structured programming question
Newsgroups: 
lugnet.robotics
Date: 
Fri, 18 Mar 2005 21:21:01 GMT
Viewed: 
1073 times
  
in lugnet.robotics Mr S wrote:

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.

What i can tell you is that you should have a more formal workout,
of what an algorithm is.

What is wrong with your algorithm design is the logic. What you call
a negative result is redundant in the above example. You could write
your example like that:

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

implying, that if the second condition isnt true, nothing happens.

Because if its not numeric, then you know that and do not need to
test it again.

There are different programming languages underway. Some distinguish
between data types, some do not.

Examples of scalar data types: boolean, integer, float, string

If you got a given variable content and ask yourself, what datatype
the content is of, you are in two situations: if your programming
language does not support datatypes, like for example perl does, you
need to test the content. It is usual to do this with regular
expressions.

If your programming language supports datatypes, you cannot attempt
to identify the datatype from a value you have read.

Because datatyping is strong in those cases. You must know the
datatype, before you read the value.

In perl for example exists a function "ref(variable)" that allows
you to distinguish between scalar variables, arrays and so on.

In case of RCX datalogs you will receive integers only.

Greetings
Ralph

P.S. i would text layout it like that (most popular form today):

if $value is not numeric then
  ... do something
else
  /** note, the value is numeric now **/
  if $value > 40 and < 65 then
    ... do something different
  else
    ... do nothing
  endif
endif



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
3 hours ago
Custom Search

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