|
Posted by ccc31807 on March 20, 2008, 3:36 pm
Please log in for more thread options
On Mar 20, 2:26 pm, xhos...@gmail.com wrote:
> > So you avoid last, next, etc. and returns in the middle of subs as well?
> > To me those are all forms of GOTO.
>
> Where do you draw the line? All looping and branching are also forms of
> GOTO, if that is the way one wants to look at it.
If you want to ~look~ at it, you can draw flow charts and make sure
that each structure, sequential, looping, or selection, has only one
entry point and one exit point. Alternatively, you can construct a
control flow graph and make sure each structure has one start and one
end node.
All the next, last, redo, and return statements do is exit a loop
according to the value of a variable. True, they are forms of a goto
instruction, but I think we have the idea that goto implies goint to
any arbitrary point in a program while the next, etc., just break out
of the inmost loop (except for labeled loops, but even then they don't
transfer control arbitrarily.)
I think that the point is writing clear, concise, and even beautiful
code, avoiding excessive subjectivism and ideosyncratic expressions,
and following consistent stylistic conventions. This will never go out
of style.
I expect that in about twenty years, someone will write an article
that Java will be considered harmful. This won't be the fault of Java,
but of the habit of forcing all code to conform to OO conventions.
This won't be Java's fault, but the fault of all those who conform
excessively to the One True Way, and discover much later that it's
just another way.
CC
|
|
Posted by RedGrittyBrick on March 20, 2008, 9:12 pm
Please log in for more thread options
John Bokma wrote:
>
>> In nearly 30 years of programming I have completely avoided use of
>> GOTO in a professional context. All I have seen continues to convince
>> me that Dijkstra was right on this matter. YMMV.
>
> So you avoid last, next, etc. and returns in the middle of subs as well?
A false premise means your conclusion is false.
> To me those are all forms of GOTO.
Not to me. I imagine almost any control structure will produce JUMP
instructions when compiled to machine code on certain machines. That
doesn't mean I write no code!
I use unlabelled last, next, multiple returns etc sparingly. It's pretty
hard for me to make a tangle of spaghetti code using unlabelled last,
next and return. When reading someone else's code, if I see a "last" or
"next" statement I know that control passes in a certain direction to
the boundary of a block, with GOTO in a monolithic program there is no
intrinsic way of knowing which way, how far or whether there are
multiple overlapping GOTOs in both directions.
If a GOTO is written by you or Abigail it is likely to be close to it's
target and judiciously used. If a GOTO is written by someone in order to
jump > 300 lines and to avoid creating subroutines, I think it is more
likely to be contributing to an unstructured hard-to-maintain/debug tangle.
|
|
Posted by Lawrence Statton on March 21, 2008, 10:42 am
Please log in for more thread options >
> > In nearly 30 years of programming I have completely avoided use of
> > GOTO in a professional context. All I have seen continues to convince
> > me that Dijkstra was right on this matter. YMMV.
>
> So you avoid last, next, etc. and returns in the middle of subs as well?
> To me those are all forms of GOTO.
>
One could put forward the argument: Those are syntactic sugar to cover
those cases where the "no goto" rule deserves to be excepted.
--
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
place them into the correct order.
|
|
Posted by John Bokma on March 21, 2008, 12:11 pm
Please log in for more thread options
>>
>> > In nearly 30 years of programming I have completely avoided use of
>> > GOTO in a professional context. All I have seen continues to
>> > convince me that Dijkstra was right on this matter. YMMV.
>>
>> So you avoid last, next, etc. and returns in the middle of subs as
>> well? To me those are all forms of GOTO.
>>
>
> One could put forward the argument: Those are syntactic sugar to cover
> those cases where the "no goto" rule deserves to be excepted.
Instead of rules I prefer to ask myself the following questions:
1) can I understand my own code next month without effort (can I after
one year)
2) can a peer do the same?
3) can someone who has some programming experience read the code without
wasting too much time.
I always get a good feeling if a customer contacts me that a
modification has been made to my code and that it was easy to do so.
Making up rules and then consider syntactic sugar exceptions sounds odd to
me.
--
John
http://johnbokma.com/
|
|
Posted by Big and Blue on March 21, 2008, 12:22 pm
Please log in for more thread options John Bokma wrote:
> Instead of rules I prefer to ask myself the following questions:
>
> 1) can I understand my own code next month without effort (can I after
> one year)
> 2) can a peer do the same?
I have to read my own, and others, code from 15+ years ago.
I can assure you that in a loop a statement of:
goto DONE_THIS:
and a DONE_THIS label at the end of a loop is much easier to follow than a
last, break or continue.
goto's are not (and never were) harmful per se. Certain uses of them were,
just as certain uses of all sorts of programming constructs were (such as
Pascal insisting that everything be in one file).
--
Just because I've written it doesn't mean that
either you or I have to believe it.
|
| Similar Threads | Posted | | help me pass argument to the subroutine and then return the value from that subroutine to another. | October 14, 2006, 1:35 am |
| A subroutine for gcd | July 17, 2006, 9:38 am |
| subroutine | July 20, 2006, 5:36 pm |
| "Undefined subroutine" | November 21, 2004, 8:48 pm |
| How to tell if a subroutine arg is a constant | February 24, 2005, 9:13 am |
| Subroutine Function | March 3, 2005, 5:14 pm |
| subroutine explanation | April 22, 2005, 8:40 am |
| problam in subroutine? | December 5, 2005, 1:40 pm |
| calling subroutine | January 3, 2006, 6:35 pm |
| subroutine doesn't seem to run after calling it. | May 9, 2006, 4:04 pm |
|