Subject:
|
Re: Are there GOTO statements in NQC?
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Fri, 21 Nov 2003 02:40:30 GMT
|
Original-From:
|
T. Alexander Popiel <popiel@SPAMLESSwolfskeep.com>
|
Viewed:
|
850 times
|
| |
| |
In message: <HooG4n.1tD1@lugnet.com>
"Ralph Toepper" <ralph.toepper@t-online.de> writes:
> As a computer science software engineer i work since 1984.
I've been coding since about '81, too. Big deal.
> My university studies before (Hamburg, Germany) taught me, that science had
> proved: any program using a goto statement can easily be transformed into a
> structured program. Remember, that this is scientifical proved!
Well, yes, by transforming it into a while loop with a state variable
representing what would otherwise be the execution counter. While
this is a provable transformation, it doesn't necessarily add anything
to the _readability_ of a program.
> What is the paradigm of a structured program? A structured program is a list
> of commands, using no goto.
The use of goto is irrelevant to structured programming; instead,
structured programming is about forming your code to conform to
abstract structures, such as loops, data manipulations, etc.
> Having one point of comands to go into and only one poit to go out off.
Ah, you're using Dijkstra's structured programming instead of Jackson
structured programming (which focuses on data forms instead of code
flow forms). Note that by this rule, an 'if' statement cannot be
an independent unit; it must be modifying some block... since an
independent if would require two exit points (which is disallowed).
> We usualy call that an algorithm.
Err, no. An algorithm is an interpretable, finite set of instructions
for dealing with contingencies and accomplishing some task which can be
anything that has a recognizable end-state, end-point, or result for all
inputs. (Definition from http://en2.wikipedia.org/wiki/Algorithm.)
> It is about formulating a problem in a structured computer language: if
> you reduce your vocabulary to the possibilities of your high level computer
> language, you formulate your problem as its own solution. This is not
> possible, if you use goto.
Limiting your vocabulary does nothing to actually solve most problems.
As an example, try this one:
Given a set of nodes N and a set of weighted connecting paths P,
output a set of paths p visiting all nodes in N exactly once where
the sum of the weights of the paths in p is equal to or less than
the sum of the weights of the paths in any other set q which visits
all nodes in N exactly once.
All of the phrases in that problem statement are relatively easily
translatable into C (without using goto!)... but the problem statement
doesn't give any suggestion as to how to solve the travelling salesman
problem.
For a simpler one, try sorting:
Given a set of elements S, each with an associated value, output an
ordered set O where every element e of O has a value equal to or less
than the value of e's successor element.
At most, problem statements tend to show how to _verify_ results, not
how to get them in an effective manner.
Adding goto to your vocabulary does not change this.
> Let me tell you a little bit more about structured programming. The purpose
> of structured programming is, to avoid eccessive use of goto, which makes
> the code quite unreadable. Of course, a single goto might be ok. But if you
> want to reach the high scills a programmer could get, you should demontrate
> the world, you dont need a goto.
Perhaps a better source of information on structured programming is
http://en.wikipedia.org/wiki/Structured_programming, or even a university
course on programming language theory.
> And it can easily be done. Any construction using a goto can similary be
> repaced by a construction using a flag. With this in mind, you can do it.
And again, this doesn't actually improve readability in several important
cases (including state machines and finite set automata, which are well
nigh unreadable whether you use goto or not).
> So structured programs consist of commands, sequences of commands, blocks
> of sequences of commands and of 5 structured commands: if, case, for, while,
> repeat (in a pascal sense). All other c code is not so good, while - of
> couse - c offers the same opportunities.
I'm surprised you leave out monitors for synchronization; of course,
when Dijkstra was formulating his set of operators, multiprocessing
was unheard of. Similarly missing are try/throw/catch/finally of
exception processing.
> The creator of pascal, Nicolaus Wirth, stated: a goto is only nessesary to
> exit a program (from its subroutines in the middle) to perform a fatal abort.
By your own admission that it is provably possible to convert any program
using goto into one that isn't, Niklaus Wirth's statement is provably false.
- Alex
|
|
Message has 1 Reply: | | Re: Are there GOTO statements in NQC?
|
| (...) Um, not exactly. Structured programming is about taking a high level problem, breaking it down into logically related modules (using as much reuse as possible) and then breaking those modules down as well, and so on. It's about being cognizent (...) (21 years ago, 21-Nov-03, to lugnet.robotics)
|
Message is in Reply To:
| | Re: Are there GOTO statements in NQC?
|
| As a computer science software engineer i work since 1984. My university studies before (Hamburg, Germany) taught me, that science had proved: any program using a goto statement can easily be transformed into a structured program. Remember, that (...) (21 years ago, 21-Nov-03, to lugnet.robotics)
|
3 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
|
|
|
Active threads in Robotics
|
|
|
|