Why doesn't JavaScript have a goto command?

E

electrician

Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.
 
M

Matt Kruse

Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say
go to it.

There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)
 
W

web.dev

Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.

Javascript does indeed have a "goto" keyword but is just a reserved
keyword.

It is not the matter of difficulty of implementation but rather the use
of "goto" statements that generally leans towards spaghetti code. And
yes, it can also be argued that very conservative use of the statement
can be helpful at times.

Here's a very classic article:

title: Go To Statement Considered Harmful
url: http://www.acm.org/classics/oct95/
 
N

Noozer

Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.

Because, if you need to use a GOTO, then you are doing something wrong.
 
J

Jonas Raoni

Noozer said:
Because, if you need to use a GOTO, then you are doing something wrong.

Not at all, sometimes you have to get out of two loops and with a goto
you can achieve this easily, goto is a reserved word, but JavaScript
has labels.

while(confirm("ok?"))
MyLabel:
while(1)
while(1)
break MyLabel;
 
E

electrician

<There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)
So what about those of us that like programming in spaghetti code? Who
are you or the creators of JavaScript to force me to use their
programming concepts? I like Goto and want it and have worked for
hours to try something else when goto would have saved me precious
time. This is another example of academia forcing us to use useless
non productive time to preserve some higher than thou intellectual crap.
 
Z

Zif

<There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)


So what about those of us that like programming in spaghetti code? Who
are you or the creators of JavaScript to force me to use their
programming concepts?

Someone has a gun at your head, forcing you to use JavaScript? Heck, you
must be one gun programmer.

You can't even be bothered to publish web pages that accommodate
browsers other than IE, why should anyone care about your opinion?

I like Goto and want it and have worked for
hours to try something else when goto would have saved me precious
time. This is another example of academia forcing us to use useless
non productive time to preserve some higher than thou intellectual crap.

But you'd like to force them to implement goto because you want them
too? Because it fits with your concept of programming learned where?
What substantive argument can you provide to show that goto is of any
benefit to JavaScript?

Your 'calculator'[1] stands as a public record of your programming
ability. Claiming ignorance of standards and design principles as a
virtue does not make it so. Did you fix the errors that were pointed
out to you?


1.
<URL:http://groups.google.co.uk/group/co...a+javascript+program?&rnum=1#4355f865f033ecbe>
 
R

RobG

Jonas said:
Not at all, sometimes you have to get out of two loops and with a goto
you can achieve this easily, goto is a reserved word, but JavaScript
has labels.

while(confirm("ok?"))
MyLabel:
while(1)
while(1)
break MyLabel;


That is not the typical use of goto. A better pseudo-code example would be:

while (...){
if (...) {
goto foo;
} else if (...) {
goto bar;
}
}

foo: { }
bar: { }

But you can achieve the same result without using goto.

goto is long dead. If you want to support it's revival, present a
scenario where it is required, or where it is significantly more
efficient than existing methods.
 
J

Jonas Raoni

RobG said:
Jonas Raoni wrote:
That is not the typical use of goto. A better pseudo-code example would
be:

while (...){
if (...) {
goto foo;
} else if (...) {
goto bar;
}
}

foo: { }
bar: { }

Sure, this is a better example of a goto, but JavaScript has not the
goto statement:

alert(goto = 1);

There's just the label, which is similar to a goto, but just works
together with break and continue.
But you can achieve the same result without using goto.

Sure :)
goto is long dead. If you want to support it's revival, present a
scenario where it is required, or where it is significantly more
efficient than existing methods.

One day you'll need to exit from a two nested loop, in this day you'll
see that a label is useful for something.

I've used the label something around two times, sure I could avoid it,
but it would require extra checking in the inner loop, in this specific
situation I'm all for the labels ;]
 
L

Lee

(e-mail address removed) said:
<There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)

So what about those of us that like programming in spaghetti code? Who
are you or the creators of JavaScript to force me to use their
programming concepts? I like Goto and want it and have worked for
hours to try something else when goto would have saved me precious
time. This is another example of academia forcing us to use useless
non productive time to preserve some higher than thou intellectual crap.

You're not really making the best possible use of this group.
When you find yourself facing hours trying to work around
the lack of some feature, ask for suggestions about how to
write the code correctly. That's bound to be more satisfying
than wasting your time and then griping about the language.
 
R

Richard Cornford

So what about those of us that like programming in spaghetti
code?

You should not be employed in commercial code development, because you
will be needlessly imposing ongoing costs on anyone you work for.
Who are you or the creators of JavaScript to force me to
use their programming concepts?

How can anyone be forcing you to write javascript at all? But if you
choose to (for reasons of expedience or whatever) it makes more sense to
learn to use the language as it is rather than wishing it was another
throwback to the 1960s.
I like Goto and want it and have worked for
hours to try something else when goto would
have saved me precious time.

The odds are very good that whatever you are trying to do can be simply
done with the constructs javascript already has.
This is another example of academia forcing us to use
useless non productive time to preserve some higher than
thou intellectual crap.

You will find that no new languages will have - goto -, because it
turned out to be a source of considerably more problems than it solved.
Recognising when something is a bad idea and stopping doing it is not
only the preserve of academia. But you are the one wasting time railing
against the way things are instead of learning to cope. That is not very
practical of you.

Richard.
 
E

electrician

<<You should not be employed in commercial code development, because
you
will be needlessly imposing ongoing costs on anyone you work for. >>

I work for myself. If I had to hire elite JavaScript programmers that
insist on not using goto I would be out of business.
Yet several of my JavaScript programs are practical and solve very
complicated linear programming models in the electrical field where I
am an expert.
I want a goto statement, because it would make my programming life
easier. I like to spend my time on subject issues, not programming
issues.

<<How can anyone be forcing you to write javascript at all? But if you
choose to (for reasons of expedience or whatever) it makes more sense
to
learn to use the language as it is rather than wishing it was another
throwback to the 1960s.>>

I used the older languges quite efficiently before JavaScript came
along, and I often used goto.
I really do think I will be looking at Visual Basic Script. If it has
a goto I may just goto vbscript and give MS even further credit for out
doing Sun.

I like Goto and want it and have worked for
hours to try something else when goto would
have saved me precious time.


<<The odds are very good that whatever you are trying to do can be
simply
done with the constructs javascript already has.>>

No way! Fortran still has goto and has for longer than most JavaScript
programmers have been alive.
This is another example of academia forcing us to use
useless non productive time to preserve some higher than
thou intellectual crap.


<<You will find that no new languages will have - goto -, because it
turned out to be a source of considerably more problems than it solved.

Recognising when something is a bad idea and stopping doing it is not
only the preserve of academia. But you are the one wasting time railing

against the way things are instead of learning to cope. That is not
very
practical of you.
Richard. >>

And I suppose Perl is not a Modern Language? Perl has a goto.
Furthermore, I really wonder how many of the "modern" JavaScript
programmers know iota about Fortran IV.
 
Z

Zif

<<You should not be employed in commercial code development, because
you
will be needlessly imposing ongoing costs on anyone you work for. >>

I work for myself. If I had to hire elite JavaScript programmers that
insist on not using goto I would be out of business.

Insisting on using a language feature that doesn't exist may have made
it difficult to hire any programmer, much less an 'elite'.

Yet several of my JavaScript programs are practical and solve very
complicated linear programming models in the electrical field where I
am an expert.

But your programs have bugs, how practical is that?

I want a goto statement, because it would make my programming life
easier. I like to spend my time on subject issues, not programming
issues.

Obviously you have little time for programming. You don't have time to
fix obvious bugs in your programs and you don't bother to program for
any browser other than IE.

<<How can anyone be forcing you to write javascript at all? But if you
choose to (for reasons of expedience or whatever) it makes more sense
to
learn to use the language as it is rather than wishing it was another
throwback to the 1960s.>>

I used the older languges quite efficiently before JavaScript came
along, and I often used goto.
I really do think I will be looking at Visual Basic Script.

Please do - your pages only work in IE anyway. Your programs contain
bugs and errors, the more their distribution is restricted the better.

I really do think I will be looking at Visual Basic Script. If it has
a goto I may just goto vbscript and give MS even further credit for out
doing Sun.

Sun? They own the JavaScript trademark, their involvement in the
development of JavaScript has been minimal. Or are you getting confused
with Java? Java doesn't have goto either.


[...]
<<The odds are very good that whatever you are trying to do can be
simply
done with the constructs javascript already has.>>

No way! Fortran still has goto and has for longer than most JavaScript
programmers have been alive.

FORTRAN must keep goto for backwards compatibility, the fact that it
continues in the language does not indicate that it is essential for all
programming languages.

Here's an article written in 1968 titled "Go To Statement Considered
Harmful":

<URL:http://www.acm.org/classics/oct95/>

About the author:
<URL:http://www.cs.utexas.edu/~EWD/>

[...]
And I suppose Perl is not a Modern Language? Perl has a goto.
Furthermore, I really wonder how many of the "modern" JavaScript
programmers know iota about Fortran IV.

You have previously said that you don't need to learn anything about
standards or design principles to write JavaScript programs, why should
your opinion on any programming subject be taken seriously?

Perl was first released (version 1.0) in 1987, so it is almost as old as
Windows. FORTRAN IV was released in 1966. Is the age of an idea the
sole criterion for whether it is better than some other idea?

Has there never been a new idea that was better than an old idea? Maybe
Newton saw further because while standing on the shoulders of giants he
kept his eyes shut tight.
 
V

Voodoochile

I work for myself. If I had to hire elite JavaScript programmers that
insist on not using goto I would be out of business.
Yet several of my JavaScript programs are practical and solve very
complicated linear programming models in the electrical field where I
am an expert.
I want a goto statement, because it would make my programming life
easier. I like to spend my time on subject issues, not programming
issues.

Ive just got to chime in here. Im also a self taught programmer (for
the past 12 years), and I also used to be an electrician (which turned
out to be a huge benefit when it comes to debugging and QA, by the
way).

At first I had no small amount of sympathy for you, in the calculator
thread; you ran head first into a bunch of egos. But now you come back
for more, and Im not sure why you expected anything different, unless
thats what youre looking for...

The thing is, a programming language is just a tool like any other; a
hammer, an EMT/Rigid bender, the law, a fork, spoken languages, shoe
horns...all tools. Which tool you use and how you use it depends on
what it is you want to do.

As was allready pointed out, goto is not used much anymore because of
the problems that arise when it is abused. I know you work relatively
alone and run a small site, but the reality is its not with programmers
like you in mind that language features are decided upon. The vast
majority of software is developed by groups and teams of developers,
many of whom never see each other, so features that tend to be abused
and thus make a language unreadable by anyone coming along later
usually get frowned upon. With the advent of the web, scalability is
also a huge concern; your app may run fine on the desktop with one
user, but collapse when 200k people all access it at once.

Havent you ever gone into a panel and wondered "What the hell was this
moron doing? Its going to take me forever to straighten this out" as
you look at the 220 feeds and dont see brown yellow or orange anywhere?
Kinda like that. Doesnt it piss you off when the guys who did the new
construction obviously didnt give a rats ass about the guys who had to
come along and make repairs/maintain things later on? (Can you say
Union Labor?)

If you had to run, oh, half inch EMT from one side of a room to
another, the walls being 10 feet apart - you cant go accross, only
around - that means two 90s...do you also complain that you have to put
a box in between? I mean, its only 20 feet, what a waste of your time,
right? But there are reasons ~why~ you have to put a box between, arent
there? What would you say to an impatient helper who said screw it and
bent and strapped the run with no box in the middle? (Id say YOU pull
the damn wire, then make him rip it out and put in the box). Also to
the point, why are you supposed to put a loop in the wire in the box?
Is it so you can do your job faster, or is it so the guys who open it
up later on can do theirs safer?

My long winded point is that there are many many priorities being
balanced in the evolution of any programming language. Its not all
about initial dev time, its about future maintenance time, scalability,
learning curve, etc etc etc. And languages ~do~ evolve; goto is just
proving to be unfit for survival. Personally I hate it with a passion,
but then Ive spent a lot of time in the past as a maintenance
programmer. ;) Its dissappearance is just Darwinism as far as Im
concerned.
This is another example of academia forcing us to use
useless non productive time to preserve some higher than
thou intellectual crap.

While Im not going to argue with you that those ducks are in the sky
oftentimes, in this case I think youre shooting the old man standing
next to you with a hellava lot of salt shot. Dont let youre anger at
the pomposity, self importance and pretension you find here prompt you
to write code that in the future may bite you in the ass.

Eric
 
T

Tim Streater

<There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)

So what about those of us that like programming in spaghetti code? Who
are you or the creators of JavaScript to force me to use their
programming concepts? I like Goto and want it and have worked for
hours to try something else when goto would have saved me precious
time. This is another example of academia forcing us to use useless
non productive time to preserve some higher than thou intellectual crap.

You are a fathead, aren't you (as we saw in your other thread). The goto
leads to unmaintainable spaghetti code, and as was pointed out in the
other thread, it becomes untestable too, so you can't guarantee its
gonna work properly in all conditions.

FORTRAN has a goto, he says. Sure - and I stopped using FORTRASH in 1978
- and that's also the last time I used a goto statement.

You need to get it into your thick skull that this has nothing to do
with "academia". It's called engineering. I want my software to:

1) work
2) be maintainable
3) be extendable

Spending some time making it properly structured and clean ("designing"
it might be the pompous academic word to use here snoot snoot) will pay
dividends down the road.

I once spent several hours working through some "spaghetti" code only to
find the klod had used a Fortran computed goto to implement subroutine
calls. So several pages of code could suddenly be condensed into perhaps
half a page. Buggered if I'm ever going to do THAT again.

-- tim
 
T

Tim Streater

Richard Cornford said:
(e-mail address removed) wrote:

The odds are very good that whatever you are trying to do can be simply
done with the constructs javascript already has.

Not just "very good", Richard. An odds-on certainty, a shoe-in, the only
horse in the race with four legs, etc etc.

-- tim
 
T

Tim Streater

<<You will find that no new languages will have - goto -, because it
turned out to be a source of considerably more problems than it solved.
And I suppose Perl is not a Modern Language? Perl has a goto.
Furthermore, I really wonder how many of the "modern" JavaScript
programmers know iota about Fortran IV.

I once (mid '70s) had to maintain a compiler written in FORTRAN by an
"academic", and indeed to port it to another platform. This turned out
to be quite easy because although he had used the goto (as FORTRAN IV
lacks features), the author had been careful about it - no spaghetti. He
had written it like an engineer would. So places where the FORTRAN
dialects differed between the two machines were limited and clear. This
exercise was at the end of a 10-year period writing in FORTRAN - I
gratefully abandoned it as soon as better languages came on the scene.

-- tim
 
V

VK

So what about those of us that like programming in spaghetti code? Who
are you or the creators of JavaScript to force me to use their
programming concepts? I like Goto and want it and have worked for
hours to try something else when goto would have saved me precious
time. This is another example of academia forcing us to use useless
non productive time to preserve some higher than thou intellectual crap.

<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function demo() {
OUTER: while(true) {
INNER: while(true) {
var msg = 'Do I need to learn JavaScript better and go get some
life?';
var ans = window.prompt(msg, 'Yes');
if (ans.toLowerCase() != 'yes') {continue INNER} else {break OUTER};
}
}
}
</script>
</head>

<body onload="demo()">

</body>
</html>
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Tue, 7 Mar 2006 13:48:44 remote, seen in
news:comp.lang.javascript said:
Not at all, sometimes you have to get out of two loops and with a goto
you can achieve this easily, goto is a reserved word, but JavaScript
has labels.

while(confirm("ok?"))
MyLabel:
while(1)
while(1)
break MyLabel;

But I see no 'goto' there.

When available, 'goto' always allows a jump from anywhere to anywhere
remotely reasonable; but 'break label' is only for jumping out of [more
than 1] enclosing loop. Those who write 'goto' do not mean 'break
label'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top