On Sun, 04 Feb 2007 03:24:44 -0800, Robert Klemme
<> wrote:
> On 03.02.2007 13:22, Martin Gregorie wrote:
>> Randolf Richardson wrote:
>
> Completely agree, Martin. "Goto" is quite nonsense - it's not needed
> from a theoretical as well as from a practical point of view.
>
>>> 1. The ability to share code between methods within a class,
>>> which all end with the same functionality (this could be more
>>> efficient than calling another method; javac would need to generate
>>> errors such as attempts to access variables that belong to different
>>> methods, return type mismatches, etc.)
>>
>> Encapsulating the code in a private method makes for more readable code
>> as well as eliminating code duplication.
>
> Plus, with modern JVM's the private method is typically inlined *if* it
> is a performance bottleneck. If not, it's not worth bothering about the
> method invocation overhead anyway.
That's a perfectly valid alternative for one particular application of
"goto."
> Side note: I am amazed that the "issue" of "goto" keeps popping up. The
> high time of Basic has long since gone but people still seem to cling to
> this ancient concept. Or do all these folks use assembler during their
> daily work?
This discussion is very interesting. One of the reasons I think "goto"
keeps coming up is that there is demand for it. Although it is commonly
associated with BASIC, it's also available in other languages such as Perl
(which can be written in a procedural or OO style, or as mixture of both),
assembler (the instruction is usually called "jmp"), etc.
I'm not convinced that "goto" is a bad thing, especially given the
numerous "while (true) { ... }" loops that I've seen over the years
(granted, those are usually examples of bad coding style, but many people
use it because they don't have "goto" at their disposal).
To me, the limit on the placement of labels at the beginning of a loop,
followed by a partial "goto" using the "break label;" instruction is
actually more difficult to follow because first one has to find the label
in preceeding code, then search for the end of the loop to follow the
program flow from there. If the label could at least be placed anywhere
from the beginning of the loop to immediately after its end, with "goto"
enabled for this, I do think this could actually make things a bit better.
I definitely don't agree that removing "goto" eliminates "spaghetti code"
and works against the OO concept (as someone pointed out in a separate
reply), rather it's the individual developers who will continue to write
terrible code even without "goto" (which seems to happen now). As an
aside, a much more serious problem is the lack of source code comments
(usually the majority of the comments in source code are a copy of the GPL
or some other license agreement -- the slightly better programmers include
a minor smattering of vague hints in what seem to be fewer than one or two
dozen randomly selected lines {out of thousands}).
I do believe that a good developer can use "goto" in an intelligent way
that doesn't result in "spaghetti code" and doesn't detract from the OO
concept, so perhaps if Sun ever does decide to implement it they could
also require a "javac" command-line option like
"-allowadvancedinstructions:goto" as a hint that alternatives are strongly
encouraged.
The masses seem to be convinced that "goto" is bad, but in the history of
the world there are countless examples where the masses were wrong (e.g.,
political elections, setting women on fire to determine if they were
witches, removing tonsils because medical experts at the time believed
them to be useless, mis-treatment of leppers, etc.).
--
Randolf Richardson - kingpin+
The Lumber Cartel, local 42 (Canadian branch)
http://www.lumbercartel.ca/