Why doesn't JavaScript have a goto command?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • electrician@electrician.com

    #1

    Why doesn't JavaScript have a goto command?

    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.

  • web.dev

    #2
    Re: Why doesn't JavaScript have a goto command?


    electrician@ele ctrician.com wrote:[color=blue]
    > 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.[/color]

    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/

    Comment

    • Matt Kruse

      #3
      Re: Why doesn't JavaScript have a goto command?

      electrician@ele ctrician.com wrote:[color=blue]
      > 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.[/color]

      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 :)

      --
      Matt Kruse




      Comment

      • Noozer

        #4
        Re: Why doesn't JavaScript have a goto command?


        <electrician@el ectrician.com> wrote in message
        news:1141763263 .543682.253290@ i39g2000cwa.goo glegroups.com.. .[color=blue]
        > 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.[/color]

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


        Comment

        • Jonas Raoni

          #5
          Re: Why doesn't JavaScript have a goto command?

          Noozer wrote:[color=blue]
          > <electrician@el ectrician.com> wrote in message
          > news:1141763263 .543682.253290@ i39g2000cwa.goo glegroups.com.. .
          >[color=green]
          >>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.[/color]
          >
          > Because, if you need to use a GOTO, then you are doing something wrong.[/color]

          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;


          --
          Jonas Raoni Soares Silva


          Comment

          • Tony

            #6
            Re: Why doesn't JavaScript have a goto command?

            Noozer wrote:[color=blue]
            > <electrician@el ectrician.com> wrote in message
            > news:1141763263 .543682.253290@ i39g2000cwa.goo glegroups.com.. .
            >[color=green]
            >>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.[/color]
            >
            >
            > Because, if you need to use a GOTO, then you are doing something wrong.[/color]

            Ever program in Assembly?

            Comment

            • electrician@electrician.com

              #7
              Re: Why doesn't JavaScript have a goto command?

              <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 :)[color=blue]
              >[/color]

              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.

              Comment

              • Zif

                #8
                Re: Why doesn't JavaScript have a goto command?

                electrician@ele ctrician.com wrote:[color=blue]
                > <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?[/color]

                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?

                [color=blue]
                > 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.[/color]

                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.c o.uk/group/comp.lang.javas cript/browse_frm/thread/3b545c991e656da 6/4355f865f033ecb e?q=How+do+you+ stop+a+javascri pt+program%3F&r num=1#4355f865f 033ecbe>

                --
                Zif

                Comment

                • RobG

                  #9
                  Re: Why doesn't JavaScript have a goto command?

                  Jonas Raoni wrote:[color=blue]
                  > Noozer wrote:
                  >[color=green]
                  >><electrician@ electrician.com > wrote in message
                  >>news:11417632 63.543682.25329 0@i39g2000cwa.g ooglegroups.com ...
                  >>
                  >>[color=darkred]
                  >>>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.[/color]
                  >>
                  >>Because, if you need to use a GOTO, then you are doing something wrong.[/color]
                  >
                  >
                  > 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;[/color]


                  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.


                  --
                  Rob

                  Comment

                  • Jonas Raoni

                    #10
                    Re: Why doesn't JavaScript have a goto command?

                    RobG wrote:[color=blue]
                    > 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: { }[/color]

                    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.
                    [color=blue]
                    > But you can achieve the same result without using goto.[/color]

                    Sure :)
                    [color=blue]
                    > 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.[/color]

                    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 ;]


                    --
                    Now with alcohol <URL:http://youtube.com/watch?v=lnQTZxq xc10> =X
                    Jonas Raoni Soares Silva

                    Comment

                    • Richard Cornford

                      #11
                      Re: Why doesn't JavaScript have a goto command?

                      electrician@ele ctrician.com wrote:[color=blue]
                      > Matt Kruse wrote:[color=green]
                      >> There is no logcal need for goto.[/color]
                      >[color=green]
                      >> The lack of goto forces you to think of the correct way to
                      >> solve your problem, rather than relying on spaghetti code :)[/color]
                      >
                      > So what about those of us that like programming in spaghetti
                      > code?[/color]

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

                      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.
                      [color=blue]
                      > I like Goto and want it and have worked for
                      > hours to try something else when goto would
                      > have saved me precious time.[/color]

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

                      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.


                      Comment

                      • Tony

                        #12
                        Re: Why doesn't JavaScript have a goto command?

                        Lee wrote:[color=blue]
                        > Tony said:
                        >[color=green]
                        >>Noozer wrote:
                        >>[color=darkred]
                        >>><electrician @electrician.co m> wrote in message
                        >>>news:1141763 263.543682.2532 90@i39g2000cwa. googlegroups.co m...
                        >>>
                        >>>
                        >>>>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.[/color]
                        >>
                        >>Ever program in Assembly?[/color]
                        >
                        >
                        > These days, I think it qualifies as "doing something wrong".
                        >[/color]

                        lol

                        Comment

                        • electrician@electrician.com

                          #13
                          Re: Why doesn't JavaScript have a goto command?

                          <<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.

                          [color=blue]
                          > I like Goto and want it and have worked for
                          > hours to try something else when goto would
                          > have saved me precious time.[/color]


                          <<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.
                          [color=blue]
                          > This is another example of academia forcing us to use
                          > useless non productive time to preserve some higher than
                          > thou intellectual crap.[/color]


                          <<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.

                          Comment

                          • Zif

                            #14
                            Re: Why doesn't JavaScript have a goto command?

                            electrician@ele ctrician.com wrote:[color=blue]
                            > <<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.[/color]

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

                            [color=blue]
                            > Yet several of my JavaScript programs are practical and solve very
                            > complicated linear programming models in the electrical field where I
                            > am an expert.[/color]

                            But your programs have bugs, how practical is that?

                            [color=blue]
                            > 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.[/color]

                            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.

                            [color=blue]
                            > <<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.[/color]

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

                            [color=blue]
                            > 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.[/color]

                            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.


                            [...]
                            [color=blue]
                            > <<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.[/color]

                            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.e du/~EWD/>

                            [...]
                            [color=blue]
                            > 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.[/color]

                            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.



                            --
                            Zif

                            Comment

                            • Voodoochile

                              #15
                              Re: Why doesn't JavaScript have a goto command?

                              [color=blue]
                              > 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.[/color]

                              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.
                              [color=blue]
                              > This is another example of academia forcing us to use
                              > useless non productive time to preserve some higher than
                              > thou intellectual crap.[/color]

                              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

                              Comment

                              Working...