Slashdot Mirror


Goto Leads to Faster Code

pdoubleya writes "There's an article over at the NY Times (registration required) about Kazushige Goto, the author of the Goto Basic Linear Algebra Subroutines (BLAS, see the wiki); his BLAS implementation is used by 4 of the current 11 fastest computers in the world. Goto is known for painstaking effort in hand-optimizing his routines; in one case, "when computer scientists at the University at Buffalo added Goto BLAS to their Pentium-based supercomputer, the calculating power of the system jumped from 1.5 trillion to 2 trillion mathematical operations per second out of a theoretical limit of 3 trillion." To quote Jack Dongarra, from the University of Tennessee, "I tell them that if they want the fastest they should still turn to Mr. Goto."" Ever get the feeling someone wrote an article merely for the pun?

462 comments

  1. So my professors were lying? by R2.0 · · Score: 1, Funny

    They told me never to use GoTo statements in my Fortran class at Lehigh. Lying bastards!

    --
    "As God is my witness, I thought turkeys could fly." A. Carlson
    1. Re:So my professors were lying? by joyfulchicken · · Score: 1, Funny

      Did the lying bastards also tell you to never read the whole article summary? ;-)

      --
      http://chickenmafia.com/ Chickens of the world, unite!
    2. Re:So my professors were lying? by /ASCII · · Score: 4, Funny

      You might want to read up on this page for some human interaction hints.

      --
      Try out fish, the friendly interactive shell.
    3. Re:So my professors were lying? by beelsebob · · Score: 0, Redundant
      Ugly code wasn't the only reason we were given for not using goto. In complex code we were shown several cases where goto lead to slower code because the compiler could no longer perform complex optimizations.

      I'd be interested in exactly what the circumstances for introducing gotos speeding up code are.

    4. Re:So my professors were lying? by Paladine97 · · Score: 1

      That's because Jacob Kazakia (jyk0) was a fool.

    5. Re:So my professors were lying? by jc42 · · Score: 1

      You'd think this would be an insignificant problem, though, because at the machine-code level, pretty much all branching and looping is done with goto-type instructions. Subroutines and interrupt routines are about the only exceptions, and they are arguably not really "branching" instructions.

      Of course, this generally hidden in an assembly language, by not includng the 4 chars "goto" in the opcodes. But it's easy to see through that ruse.

      What this really means is that with gotos, some optimizations can only be done at the machine-code level, because the flow of control is obscured at higher (source and intermediate-data-structure) levels. But this in turn is used as an argument for generally moving optimizations to the lowest possible level, so that they will work even when the source code obscures the flow of control.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    6. Re:So my professors were lying? by Marxist+Hacker+42 · · Score: 1

      And I'll just bet that Goto never uses GoTo. Quite a good pun for entry level CS class...except I bet his name is pronounced with an initial short o vowel insetad of the long o vowel and different sylables. (Got-o, rather than Go-To).

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
  2. Duh... by tpjunkie · · Score: 0, Offtopic

    This isn't news, everyone knows GOTO results in faster code than GOSUB

    1. Re:Duh... by Anonymous Coward · · Score: 3, Informative

      I was involved with the design and the benchmarking effort of #5, #59, #67 and a few others in Top500. The performance of a supercomputer is determined by the number of real FLOPs acheived versus theoretically claimed.

      Theoretical FLOPs per processor = Core(s) * Speed_Per_Core (in Ghz) * 2. So for a Dual 3.6 Ghz Xeon, the theoretrical FLOPS is 2 * 3.6 * 2 = 14.4

      An easy way to find out actual number of FLOPS a computer can acheive is to ask it to solve a number of Linear Algebra problems and then look at the time it takes to finish solving these problems. The faster the time, better FLOPs obviously.

      Now, the reason we chose gotolib was:

      1) It works with GCC
      2) It is optimized to use the processor cache
      3) And therefore fewer cache misses which translates to superior performance
      4) And its free (though the source is not exactly open).

      Because it uses the processor cache so effectively, it results in a better number than a regular BLAS (which does not use processor cache).

      Alternatively, I've also used Intel's MKL which offers comparable performance but then it works best with ICC and its not free. Btw, #59 was benchmarked using gotolib and MKL -- but if I remember correctly, the final result was derived using MKL.

      In essence, if you want to use GCC and work with lots of number crunching ie BLAS, gotolib is your best option.

  3. This certainly is news to me. by trudyscousin · · Score: 4, Funny

    I'd always been told that use of Goto led to a case of the BLAS in my code!

    --
    Those who can, do. Those who can't, write technology blogs.
    1. Re:This certainly is news to me. by BrokenHalo · · Score: 2, Funny

      Yes, but of course Real Programmers aren't afraid to use GOTOs. :-)

    2. Re:This certainly is news to me. by masklinn · · Score: 2, Interesting
      --
      "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
    3. Re:This certainly is news to me. by Mr+Z · · Score: 1

      Ah yes, the story of Mel.

      Differently-impressive is the Tree VLIW IBM has come up with. Here's a blurb from the site:

      In our VLIW architecture, a program consists of a sequence of tree-instructions, or simply trees, each of which corresponds to an unlimited multiway branch with multiple branch targets and an unlimited set of primitive operations. All operations and branches are independent and executable in parallel. The multiway branch is associated with the internal nodes of the tree, whereas the operations are associated with the arcs.

      In other words, each VLIW instruction word isn't just a branch, it's a multiway branch. One tree-VLIW prototype could execute up to 8 branches a cycle.

      I wonder if Mel had anything to do with that architecture...

      --Joe
    4. Re:This certainly is news to me. by Ashley+Bowers · · Score: 0

      Maybe I am knew to all this "NOT" but I have never heard of such a thing but I guess thats why I like these forums so much cuz I can keep up with all that stuff I did nt know.

  4. Throwing bricks in glasshouses, anyone? by trezor · · Score: 4, Funny

    Ever get the feeling someone wrote an article merely for the pun?

    Good thing the headline didn't contribute to that at all.

    --
    Not Buzzword 2.0 compliant. Please speak english.
    1. Re:Throwing bricks in glasshouses, anyone? by jericho4.0 · · Score: 1

      Although they screwed it up. It should read "Goto considered helpful"

      --
      "A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
  5. Psssh. by SatanicPuppy · · Score: 0, Offtopic

    Whatever.

    Goto isn't considered bad programming because it slows things down. It's considered bad programming because it leads to spagetti code.

    And people who "meticulously hand optomize" their code annoy the crap out of me. Run it, tweak it, run it again. Was the second run faster? Then tweak some more.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
    1. Re:Psssh. by XXIstCenturyBoy · · Score: 2, Insightful

      I like to see people replying to a post after reading the name subject line and then express an opinion that 1) Everyone knows and no one would argue with and 2) Has pretty much nothing to do with the article beside a easy pun.

    2. Re:Psssh. by Anonymous Coward · · Score: 0

      Not only did some people not read the article, they didn't even bother reading the article summary. Sigh.

    3. Re:Psssh. by Anonymous Coward · · Score: 0

      Firstly: You, sir, are a fucking idiot. RTFA.

      Secondly: There are few things as rewarding as finally getting to the point in a writing a heavily used routine when there is nothing else to do but hand optimise to squeeze the last few cycles out of it. I believe you are complaining about the people that apply this effort in misdirected places.

    4. Re:Psssh. by crozell · · Score: 1
      And people who "meticulously hand optomize" their code annoy the crap out of me. Run it, tweak it, run it again. Was the second run faster? Then tweak some more.

      Do you have a better idea? It seems like there must be a better way to do this, but the reality is that he's getting speeds much better than any automatic method to try and speed things up. The article claims his code produce a speed increase of ~30% on supercomputing platforms. That's nothing to shrug off just because the method of getting it seems clumsy. Would you rather do without those speedups because you didn't like the way he got there?

    5. Re:Psssh. by gr8_phk · · Score: 1
      "And people who "meticulously hand optomize" their code annoy the crap out of me."

      I'm one of those guys (sometimes). I have a library that has undergone many small performance improvements and is now 2-3 times as fast as when it started. There's even one little run of inline assembler in the most critical part. The code has gone from fairly easy to understand C++ to much less easy to comprehend, so I'd agree that code optimization all the time is not a good thing - it's a tradeoff. People who think there is NO value in optimization annoy the crap out of me.

      For some people, execution time is money.

    6. Re:Psssh. by LWATCDR · · Score: 1

      "And people who "meticulously hand optomize" their code annoy the crap out of me. Run it, tweak it, run it again. Was the second run faster? Then tweak some more."

      Yea that is horrible. Faster code who needs it.
      Get a clue please. We are not talking about a program to print mailing lables! We are talking about math functions.
      Gee a whole second? run a Few million datasets through it and you have a real savings.

      There is a place for meticulously hand optomize code. Math functions are a prime example of one of them.

      --
      See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
    7. Re:Psssh. by ciroknight · · Score: 1

      Well the problem here is where money and time is spent. You can spend more money and time up front and get a product that will save you time and money later, or spend less money and time and get a product that will take longer later and thus cost more. Depending on the product, computational time might be more expensive or less expensive than development time, and that's how I choose to optimize.

      If I'm working on an embedded processor, I'm going to spend the extra time and money it takes to get everything working smoothly and quickly now, and later it'll be fast and effecient. If I'm working on a massive supercomputer, I'm going to go more lax on the optimizing, since the computer can pick up a lot more of the slack. (Yes, this can be considered a "bad" practice, but then again, when you've gone balls-to-the-walls and optimized a program for a supercomputer to achieve maximum effeciency only to find that it saves roughly 5% processing time, you look and feel like a damn fool. I don't recommend it).

      These guidelines should also go into language selection and memory usage, but basically, it's a good way to tell a good programmer from a more shoddy one.

      --
      "Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
    8. Re:Psssh. by jcr · · Score: 1

      people who "meticulously hand optomize" their code annoy the crap out of me.

      What's it to you how anyone else spends their time?

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
  6. 30%+ Improvement by bateleur · · Score: 1, Insightful

    when computer scientists at the University at Buffalo added Goto BLAS to their Pentium-based supercomputer, the calculating power of the system jumped from 1.5 trillion to 2 trillion mathematical operations per second

    Which is certainly good, but to me says more about the previous implementation than it does about Goto's work.

    1. Re:30%+ Improvement by Surt · · Score: 5, Insightful

      Considering the number of scientists who have been looking at this over a number of years, I think it really is a credit to Goto's work. Optimizing at this level is very challenging work on modern processors.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    2. Re:30%+ Improvement by Anonymous Coward · · Score: 0

      Which is certainly good, but to me says more about the previous implementation than it does about Goto's work.

      Yeah, just like Mona Lisa to me says more about previous paintings than it does about DaVinici's work.

    3. Re:30%+ Improvement by roystgnr · · Score: 4, Insightful

      Which is certainly good, but to me says more about the previous implementation than it does about Goto's work.

      Yeah, that previous implementation must have totally sucked. I know all my linear algebra software is written around an assembly language core, hand tuned for each new version of a half dozen processors, and designed from the start to minimize TLB misses instead of just naively trying to fit a dataset into L1 or L2 cache. I don't know why those retards at the universities and national labs were ever using anything else!

      (closing Slashdot, going back to working on my shamefully unoptimized C++ numerics code...)

    4. Re:30%+ Improvement by mangu · · Score: 4, Interesting
      to me says more about the previous implementation than it does about Goto's work


      Which only goes to show that you haven't considered the implications of optimization in modern processors. A Pentium 4 can operate above 3 GHz. This means that light can travel no more than 10 centimeters in the duration of one clock pulse. With the spacing in the motherboard, this isn't enough for a pulse to go from the CPU to the RAM and come back. Even if the memory could operate at the same rate as the CPU, the computation would still be limited by light speed alone.


      Optimization to get the full advantage of a Pentium 4 doing floating point calculations is one of the most difficult tasks one can do in computing. A P4 can do, in one clock pulse, four multiplications and four additions. To get 100% of this speed one needs to have a sophisticated handling of cache memory, among other requirements.

    5. Re:30%+ Improvement by bateleur · · Score: 2, Informative

      Apologies if I implied critcism of his work, that wasn't the intention.

      My point is simply that in the field of optimisation, all your gains come from succeeding where the last guy failed. This 30% improvement in performance is not the difference between Goto's approach and his nearest competitor, it is the difference between his work and the previous solution used on that particular machine.

      It's the statistic I'm criticising - it simply isn't very meaningful.

      (I used to do research into hardware optimisation. Improvements of more than about 5% in any field to which smart people devote a lot of thought always make me suspicious !)

    6. Re:30%+ Improvement by ultranova · · Score: 2, Interesting

      I know all my linear algebra software is written around an assembly language core, hand tuned for each new version of a half dozen processors, and designed from the start to minimize TLB misses instead of just naively trying to fit a dataset into L1 or L2 cache. I don't know why those retards at the universities and national labs were ever using anything else!

      Propably because, being scientists first and programmers second, they simply don't have the time neccessary to learn the characteristics of the processor to the degree neccessary to even match, let alone overcome, the output generated by the compiler. It could also be that the algorithms are under active development, in which case writing them in assembler doesn't really make sense, since it will increase the time needed to write and test new versions. And if the scientists find that some function is unacceptably slow, and can't figure out a more efficient algorithm, they can always just hire a code monkey to hand-tune it with assembler.

      Speaking of compiler optimizations, if simply replacing control structures with goto made the function 30% faster, then either the compiler truly sucks, or the previous implementation was something horrible.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    7. Re:30%+ Improvement by Surt · · Score: 1

      Ah, well it may be a misreading on my part. I took it to be a 30% improvement over the closest competitor, which I thought was quite impressive.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    8. Re:30%+ Improvement by Anonymous Coward · · Score: 1, Informative

      Not entirely true. modern processors take much more clocks to calculate than one clock cycle (say 3 GHz) because they are designed for, so called, pipelining. P4 has 20-clock pipeline (or 30 for prescott), meaning that you don't really need data before, say, 5-10 clocks, so you can afford that kind of latency.

    9. Re:30%+ Improvement by Anonymous Coward · · Score: 1, Informative
      Not entirely true. modern processors take much more clocks to calculate than one clock cycle (say 3 GHz) because they are designed for, so called, pipelining. P4 has 20-clock pipeline (or 30 for prescott), meaning that you don't really need data before, say, 5-10 clocks, so you can afford that kind of latency.

      Except that if you want to get code running at 2/3 of the P4 theoretical limit, you better do something else during the 10 clocks... hence better have prefectched data... knowing that memory latency is 300+ cycles (not 30).

    10. Re:30%+ Improvement by joe_bruin · · Score: 0

      Which only goes to show that you haven't considered the implications of optimization in modern processors. A Pentium 4 can operate above 3 GHz. This means that light can travel no more than 10 centimeters in the duration of one clock pulse.

      The speed of light = 299,792,458 m/s. At 3GHz, that would be 100cm.

    11. Re:30%+ Improvement by pe1chl · · Score: 1

      I'm sorry, but you are wrong.

      299,792,458 / 3*10^9 = 0.0999

    12. Re:30%+ Improvement by Anonymous Coward · · Score: 0

      You know centi is 1/100, right?

          300 000 000.00 m
      / 3 000 000 000.00 clocks

      =             0.10 m/clock
      *           100.00 cm/m

      =            10.00 cm/clock

    13. Re:30%+ Improvement by rangek · · Score: 0

      I get 90 cm... 3E-8 m/s * 3E-9s = 9E-1 m = 90cm

    14. Re:30%+ Improvement by joe_bruin · · Score: 1

      Haha, oops. Thanks for the correction.

      For some reason, I was thinking 1000cm = 1 meter, which is obviously wrong. That's what happens when you post before lunch.

    15. Re:30%+ Improvement by MarkCollette · · Score: 1

      There is no such thing as "they can always just hire a code monkey to hand-tune it with assembler".

    16. Re:30%+ Improvement by Anonymous Coward · · Score: 0

      Or after hitting the bong.

  7. His code is more stable than Mr. Bluescreen's by virtigex · · Score: 5, Funny

    Although he also writes fast code, Mr. Bluescreen was criticised for the poor stability of his code.

    1. Re:His code is more stable than Mr. Bluescreen's by Anonymous Coward · · Score: 0

      I thought Mr. Bluescreen worked in the special effects industry?

    2. Re:His code is more stable than Mr. Bluescreen's by vmxeo · · Score: 2, Funny

      Personally I think Mr. Gosub writes better code. Sure, it's not as fast, but's it's much more readable than Mr. Goto's spagetti code.



      (Wow. I'm suddenly getting flashbacks from my BASIC days...)

    3. Re:His code is more stable than Mr. Bluescreen's by Anonymous Coward · · Score: 1, Funny

      What poor stability? Have you ever seen a blue screen crash?

  8. According to Dijkstra... by Anonymous Coward · · Score: 0

    Goto is considered harmful!

  9. I failed a coding test because of this guy by alta · · Score: 5, Funny

    It was CIS 150, C++ was the language of the day (pascal before, java after.) I was taking an exam that was all coding. I remember extensive use of GOTO from my commodore days, so I used one in a test (the objective was to code something with as few lines as possible)

    I had the shortest working code in the class but the arse hole teacher failed me for it. Said something like "we don't teach goto for a reason. Yeah, it's in the book, but don't ever use it!"

    Jerk. I should post his phone number on slashdot ;)

    --
    Do not meddle in the affairs of sysadmins, for they are subtle, and quick to anger.
    1. Re:I failed a coding test because of this guy by UOZaphod · · Score: 1

      That kind of crap annoys me to no end... Someone sets up the conditions for a test such as "fewest lines possible", you give them a working, legitimate answer, and they reject it because it wasn't what they expected.

      Something like that happened to me recently, in fact. I figure if they have expectations like that they should state them up front. Otherwise, they should be prepared for anything.

      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    2. Re:I failed a coding test because of this guy by CynicalGuy · · Score: 1

      Sorry but I gotta side with the professor. Don't use goto in C++.

    3. Re:I failed a coding test because of this guy by ooze · · Score: 1, Redundant

      "Don't use goto" is sort of and absolute/godly moral. It's good for those that can't think and decide for themselves. People that can think and decide for themselves know that there are no absoltue morals and occasionally decide to use a goto, when it's appropriate for their use.

      While I can understand why structrured programming was introduced, I still think it is sort of funny to use like a dozen syntactical constructions, that all can have their own quirks, for flow control, while all those things are done with one machine code on a proper RISC machine, meaning the jump instruction.

      --
      Just because I can imagine doing a hippopotamus, doesn't mean I'd like to do it.
    4. Re:I failed a coding test because of this guy by CastrTroy · · Score: 4, Insightful

      Obviously this prof was wrong. If he wanted you to code it in as few lines as possible, then he should have expected everyone's code to be completely unreadable, goto's or not. If he wanted your code to be understandable, then he should have asked to make the code as clear as possible, by using as many lines as you may need.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    5. Re:I failed a coding test because of this guy by Mr+Z · · Score: 3, Informative

      Yeah, that is BS! Especially when you have Donald Knuth, Brian Kernighan and Ken Thompson on record in defense of goto when it's warranted. References: Knuth's "Structured Programming with GOTO" (link appears dead), Kernighan, and Ken Thompson: "If you want to go somewhere, goto is the best way to get there."

      And then there was the famous "'GOTO Considered Harmful' Considered Harmful" by Frank Rubin, and a a decent section in Steve McConnell's Code Complete that takes an even-handed view.

      Anyway, swinging carefully back on topic, it sounds like Mr. Goto's work is at the instruction level, not the C or Fortran or even really at the algorithmic level (except maybe tricks like tiling). I program in the embedded space, where getting as close to 100% efficiency is a continual challenge. I wonder if any of his techniques scale down...

      --Joe

    6. Re:I failed a coding test because of this guy by nhnfreespirit · · Score: 1

      While I would tend to agree that abusing goto statements will lead to unreadable code, avoiding them at all cost can have the same or even worse effect! I once hat to work with a piece of legacy c++ code where the original authors needed to use a goto statement. iHaving been told over and over that goto statements are evil, they ended up using a do, break, while(0) construct wrapend in a couple of #define's making the whole thing utterly unreadable. A goto would have explained excately what they intended, instead I had to go hunt for their definitions to figure out what was going on....

    7. Re:I failed a coding test because of this guy by Comboman · · Score: 3, Informative
      Sorry but I gotta side with the professor. Don't use goto in C++.

      "Not recommended" and "don't ever use it" are two differenet things. If it was never meant to be used, it wouldn't be in the language. The goal of the test mentioned was to write the shortest possible piece of code, not the most maintainable or most elegant.

      "The goto can also be important in the rare cases in which optimal efficency is essential." - Stroustrap, The C++ Programming Language

      "Code involving a goto can always be written without one, though perhaps at the price of some repeated tests or an extra variable." - Kernighan & Ritchie, The C Programming Language

      If you don't know who Stroustrap and K&R are, you have no right commenting on C/C++ issues. I have to side with the original poster, the prof was a dogmatic asshole (and so are you).

      --
      Support Right To Repair Legislation.
    8. Re:I failed a coding test because of this guy by leonmergen · · Score: 1

      If you don't know who Stroustrap and K&R are, you have no right commenting on C/C++ issues.

      I'm sorry, I only know Bjarne Stroustrup... who's that Stroustrap you're talking about ? :-)

      And on a more serious note, I think the professor has a valid point... his job is to teach someone C++, and well, like Stroustrup says, goto should only be used in rare cases. At the point that someone reaches this point where he has to perform these kind of optimizations, one can say that he mastered the language enough to be able to properly decide whether or not to use goto. Students, however, shouldn't be taught to be using goto...

      --
      - Leon Mergen
      http://www.solatis.com
    9. Re:I failed a coding test because of this guy by arkanes · · Score: 1

      The professor is right - don't use goto. On the other hand, he's also a dogmatic asshole (assuming that the OP is fairly presenting his case, which I suppose is questionable) for giving an assingment like "write this in the fewest LOC possible". In fact, such an exercise in and of itself is detrimental to the teaching of good programming practice. So minus points for giving it, and extra minus points for giving the OP grief when he used goto to achieve that goal.

    10. Re:I failed a coding test because of this guy by MattWhitworth · · Score: 1

      Yup exactly. Goto is used all over the Linux kernel code, because it is the most efficent method. For example, when multiple conditions could fail in a function, without goto, you would otherwise duplicate that error-clearup code multiple times, increasing the size of the function exponetially. Just look at lxr.linux.no to see what I mean.

      And goto is kind of abused there as well, there's several loop conditions where a goto is strangely used.

    11. Re:I failed a coding test because of this guy by Doc+Ruby · · Score: 1

      But the prof didn't teach not to use goto. He omitted teaching how to use goto, which is not the same - especially since use of goto for optimization was in the book. The prof taught not to use goto by failing the student after the test. That's a failure of the prof to teach a technique we've learned from experience.

      --

      --
      make install -not war

    12. Re:I failed a coding test because of this guy by arkanes · · Score: 1

      The use of goto in this manner in the Linux kernel is used as a poor-mans exception, which C does't have, and use of goto in this manner is more common in C. It's a crummy way of doing your error handling, since it has all of the flaws of exceptions and hardly any of the benefits, as well as introducing a few flaws of its own, but when you're working in C you don't really have any other choice. The use of goto like this is one of the reasons people regularly suggest using C++ for the linux kernel.

    13. Re:I failed a coding test because of this guy by arkanes · · Score: 1

      I don't believe you that the authors needed to use a goto (crappy programming doesn't neccesarily mean that your pet solution is the answer). It's more likely that what they really wanted was an exception.

    14. Re:I failed a coding test because of this guy by Smidge204 · · Score: 2, Insightful

      You do realise that GOTO command translated to a JMP isntruction, which any compiler produces in abundance anyway, right?

      There is no performance issue at all. The ONLY reason 'goto' could be considered bad is that it becomes easy to write code that is difficult for humans to follow.

      =Smidge=

    15. Re:I failed a coding test because of this guy by thesnarky1 · · Score: 2, Interesting

      As few lines as possible?

      I'm surprised the teacher didn't get obfuscated codes, could'a been a fun way to practice for the IOCCC!

      While it might not be smart, whenever I get assignments like this from my teachers, I always will write exactly to the letter. No one SAID I had to have line breaks at the end of a "line". So it'll be an 80 char row, no extra spacing. I won't go so far as to obfuscate it horribly, just take out the spacing.

      I have have teachers give that assignment, and I've given them right back something in as few lines as possible. Most just kind of glare at me and grade it anyways, but one professor just laughed, realized his mistake, and gave me credit for the shortest answer, much to the chagrin of the other students in the class.

    16. Re:I failed a coding test because of this guy by SlashSquatch · · Score: 1

      "...those ivory tower eggheads screwed us again." - Homer

      --
      Autonomous Retard -- Is your camp safe? UnsafeCamp.com
    17. Re:I failed a coding test because of this guy by sedyn · · Score: 1

      A prof of mine had a much better solution to informing students that even though something is legal it may not be desirable...

      Instead of getting a 100, he'd give a 99.9999999999999999999 and a note on the side. The trailing number of 9s would get your attention and the note would teach you a lesson.

      I've always thought it to be fair and effective.

      *Come to think about it, in a fewest LOC assignment we were given in assembly (with the prof mentioned above) I did something very similar to the thread starter... I also got fewest LOC... Granted, assembly is different than C++, but the hack I employed that no one else did involved a jump instruction...

      I'd give the original poster a 99.9999999999999999999 and a note explaining why gotos shouldn't be used, then declare an edict of no gotos in the next class.

      --
      Am I open minded towards open source, or closed minded towards closed source?
    18. Re:I failed a coding test because of this guy by Shinobi · · Score: 1

      Wrong!

      Students should be taught how to use them, and under what circumstances, so they actually know the advantages and drawbacks. Anything else is utterly irresponsible. And it explains a lot of crap I see from compiler-trained monkeys coming out of comp.sci >:(

    19. Re:I failed a coding test because of this guy by LWATCDR · · Score: 1

      Gotos should be avoided but was that a condition of this test? Did he say write it in as few lines as possible without using a goto? It is part of the language and do serve a purpose. There are times when they are best solution. Frankly doing x in as few lines as possible is a good example of where a goto could be a good choice.
      BTW I had a program of mine failed by a teacher because she didn't believe it would work. I think it was to find the largest number out of three or some such thing. I had to create a data set for each possible order of values and walk her through the program. After I proved it worked I only got a B even though it was the shortest program. Her reasoning was that it was "too hard" to understand. This was in stinking FORTRAN IV. Needless to say I never took a class from her again. BTW gotos where okay in FORTRAN IV but I still avoided them.

      --
      See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
    20. Re:I failed a coding test because of this guy by arkanes · · Score: 1
      Who said anything about performance issues? And what the hell does the compiler have to do with anything? If I wanted to write assembly code I'd do that. The *only* reason to use a higher level language at all is to make it easier for humans to follow. Therefore, making it difficult for humans alone is totally sufficent reason for not doing it. Especially since there is no condition using goto that cannot be written using other constructs.

      The whole cowboy culture of programers (just look down in this thread to see people bragging about the least readable assignments they ever turned in) is detrimental to the state of the art in programming. So is the obsession with performance (mostly by people who couldn't tell you the hotspots in the code they're supposedly "optimizing", of course). And thats why stuff like an assignment to turn in code using the least LOC possible is harmful and irresponsible. There is no circumstance, ever, where you will need to use this skill. It provides no special insight into algorithms, and only minimal knowledge of language features. You aren't a better programmer because you avoid your enter key. I know it's not really reasonable to expect college students to act like real grownups, but theres no reason to encourage it in classes.

    21. Re:I failed a coding test because of this guy by Smidge204 · · Score: 1

      But there is no justifiable rason to not use it. Like all other programming syntax and structure, one simply has to be careful about how it is used to maintain readability.

      There is no performance-related reason to avoid it and the only aestetic reason falls squarely on the programmer's coding style and habits. Under the right circumstances, using GOTO can actually improve performance by reducing logic.

      Therefore, statements like "you should never use GOTO" are bullshit. That's all I'm saying.

      The rest of the stuff we already agreed on, it seems.
      =Smidge=

    22. Re:I failed a coding test because of this guy by CynicalGuy · · Score: 2, Informative

      You do realise that GOTO command translated to a JMP isntruction, which any compiler produces in abundance anyway, right?

      This simply isn't true, and it's a shame that it got modded up. Modern compilers do a lot of optimization to your code, and most of those optimizations are disabled as soon as the compiler sees an unconditional jump. Things like placing variables into registers, unrolling loops, etc.

      But what do I know, I'm just a "dogmatic asshole"..

    23. Re:I failed a coding test because of this guy by poot_rootbeer · · Score: 1

      Or, if the professor wanted your code to match best practices in the software development industry, he should have set up the problem so that the optimum solution was a compromise between the briefest code and the most clear.

    24. Re:I failed a coding test because of this guy by Shinobi · · Score: 1

      Actually, I'd say that academically trained compiler monkeys are just as detrimental, because too few of them are taught how to take various real factors such as hardware into account.

      In the real world many fields require optimized programming and lots of low-level knowledge, and high-level languages is just that much useless cruft. Likewise, in some fields, low-level knowledge is just a bonus, and high-level languages and blind trust in the compiler is perfectly fine. The problem is that many academic programmers have put blind faith into high-level languages and "system design". What's needed is flexible programmers who can take both approaches.

    25. Re:I failed a coding test because of this guy by eric76 · · Score: 1
      Sorry but I gotta side with the professor. Don't use goto in C++.

      The problem is that the goto, in the hands of an unskilled programmer, is used for many unnecessary reasons and is rarely used appropriately.

      There is nothing wrong with using a goto in situations when it results in cleaner code that is, therefore, easier to read, understand, and maintain.

      For example, one situation is when nested several levels deep in a loop and have reached a condition requiring an immediate exit from the loop with no additional processing.

      Sure, you can set up some elaborate mechanism so it fails each loop comparison and falls out of the loop, but that needlessly complicates the code. More than once, I've seen people introduce bugs in a program by either screwing up the exit from a set of nested loops or by modifying the later without realizing the purpose of the extra complications.

      Compare that to the simple use of a goto where it determined that an exit from the loop is required. The purpose for the use of the goto in this situation should be intuitively obvious to the most casual observer.

    26. Re:I failed a coding test because of this guy by eric76 · · Score: 1

      A number of years ago, I knew one very fine software developer who really needed a goto but could not bring himself to use them where everyone would see them.

      So he buried the goto's in a set of #define's in an obscure header file.

      I always thought he should have just used the goto in his code and thumb his nose at the goto Nazis.

    27. Re:I failed a coding test because of this guy by MntlChaos · · Score: 1
      The use of goto in this manner in the Linux kernel is used as a poor-mans exception, which C does't have, and use of goto in this manner is more common in C. It's a crummy way of doing your error handling, since it has all of the flaws of exceptions and hardly any of the benefits, as well as introducing a few flaws of its own

      What about performance? Exceptions are slow, because they are allowed to travel between functions. A goto is a single instruction. Fast. An exception has to be constructed, then you have to go look up where the exception is supposed to go, then you have to execute a bunch of code that makes it safe across function boundaries, then you can make the jmp that you would have made.
    28. Re:I failed a coding test because of this guy by Pausanias · · Score: 1

      For example, one situation is when nested several levels deep in a loop and have reached a condition requiring an immediate exit from the loop with no additional processing. Sure, you can set up some elaborate mechanism so it fails each loop comparison and falls out of the loop, but that needlessly complicates the code. More than once, I've seen people introduce bugs in a program by either screwing up the exit from a set of nested loops or by modifying the later without realizing the purpose of the extra complications.

      Dude, think modular. Just put the nested loop inside a function. Then when your exit condition comes, exit() the function. There, you're done, without the use of goto, and without needing to set up conditions at each stage of the nested loop.

      Once you learn to work without gotos, you'll see that the option of using goto never even enters your mind.

    29. Re:I failed a coding test because of this guy by eric76 · · Score: 1

      Are you seriously suggesting that the program should just quit whenever you wish to exit from a loop?

      For what it's worth, I can work quite well without goto's. But unlike many younger developers, I'm not at all scared of using them when they are appropriate.

    30. Re:I failed a coding test because of this guy by Billly+Gates · · Score: 1

      Goto is nothing compared to the evils of perl!

      One liners in perl are very very bad. Because of the garbage filter in slashdot I can't post examples, but do a google search on decss and perl and read teh 6 lines of code in the perl port? ... shudder

      If anyone can understand it without looking up perl programing docs I would be highly impressed.

    31. Re:I failed a coding test because of this guy by cheekyboy · · Score: 1

      Sometimes when writing IO drivers for exotic hardware, YOU HAVE TO. Or do you want to waste
      2000 cycles back tracing the stack of lots of else ifs?

      --
      Liberty freedom are no1, not dicks in suits.
    32. Re:I failed a coding test because of this guy by Anonymous+Cowpat · · Score: 1

      bah! that does suck. I'm firmly of the belief that in an exam ANYTHING that takes the specified input and puts the right result out is a 'correct' answer and should be marked on how well you're implemented your solution, not how well you've implemented the intended solution.
      Assignments and tests are different, you should take the time to do them in accordance with 'best practice', but in an exam situation anything that works should be a right answer.

      --
      FGD 135
    33. Re:I failed a coding test because of this guy by CynicalGuy · · Score: 1

      real men write that shit in asm..

    34. Re:I failed a coding test because of this guy by mikek3332002 · · Score: 1

      If you had to do it in the shortest number of lines, why didn't you just delete all the CR and LF
      characters after the semicolons so it fitted on 1 line.

    35. Re:I failed a coding test because of this guy by ars · · Score: 1
      "....and most of those optimizations are disabled as soon as the compiler sees an unconditional jump..."

      Wow! You got that EXACTLY backward!

      I hope that was a typo, but I'm guessing not.

      Anyway all the stuff gets disabled with a conditional jump! An unconditional jump is nothing, a CPU can optimize that very well - in fact it's not even executed in the standard sense of the word, it's optimized away at an earlier stage.

      --
      -Ariel
    36. Re:I failed a coding test because of this guy by Smidge204 · · Score: 1

      No, an unconditional jump is breazed right over. A CONDITIONAL jump is a problem, because you can't optomize for both possible machine states that might occur after the condition is tested.

      But what do I know, I'm just a "dogmatic asshole"..

      Not a hell of a lot it seems! :)
      =Smidge=

    37. Re:I failed a coding test because of this guy by Monkelectric · · Score: 1

      Ouch. I feel for you man. The "goto considered harmful" is the rallying cry of crappy programmers. As long as we use the von neuman architecture, goto will be a valid tool.

      --

      Religion is a gateway psychosis. -- Dave Foley

    38. Re:I failed a coding test because of this guy by Anonymous Coward · · Score: 0

      +2 Insightful

    39. Re:I failed a coding test because of this guy by cburley · · Score: 1
      "....and most of those optimizations are disabled as soon as the compiler sees an unconditional jump..."

      Wow! You got that EXACTLY backward!

      I hope that was a typo, but I'm guessing not.

      Anyway all the stuff gets disabled with a conditional jump! An unconditional jump is nothing, a CPU can optimize that very well - in fact it's not even executed in the standard sense of the word, it's optimized away at an earlier stage.

      No, it wasn't exactly backward; he was referring to the compiler, not the CPU.

      Anyway, all the above generalizations are false, but true enough for common specific situations that programmers interested in performance should take them into account.

      Many compilers do their most, best optimizations at the "basic block" level, and might (or might not) treat any GOTO (conditional or unconditional) as "ending" a basic block, thus disabling optimizations that might otherwise "work" across them, had "more elegant" code been used instead.

      (I've worked on the internals of such compilers. Especially in the Fortran world, where ancient but important benchmarks have already been "hand-optimized" to use lots of GOTOs, it has been tempting to include a "code lifting" pass to the optimizer that replaces GOTO's with "more elegant" code for the subsequent optimization phases, including breaking things up into basic blocks, to do a better job on.)

      Also, whether a GOTO is explicit or implicit might or might not affect how a compiler views it.

      In C, the "goto" keyword is 100% explicit, as is "longjmp()". "if", "while", "return", "switch" with 'natural' "break"'s at the end of each "case" are all nearly 100% implicit. "continue" and "break" in 'unusual' places are examples of grey-areas that compilers might or might not treat just like explicit "goto"'s in terms of optimization.

      CPUs are another matter. Conditional branches do tend to be bad juju for most modern CPUs (RISC and CISC built in the past 20 years), but sometimes unconditional branches also can introduce problems compared to code that simply "flows through" using repeated conditional tests but not conditional GOTOs (JMPs or branches or whatever).

      Hence the addition of instructions like CMOV (Conditional MOVe) to RISC sets like SPARC (working from memory here, apologies if I've gotten technical details wrong).

      Point being that a decent optimizing compiler these days should not assume GOTO means "stop optimizing", and should not blindly generate JMP/Branch instructions just to avoid extra compares or moves, or even fetches from memory, unless it is sure the savings outweighs the costs (say, the CPU really won't hiccup, or it saves an extra Icache line crossing, or something like that).

      --
      Practice random senselessness and act kind of beautiful.
    40. Re:I failed a coding test because of this guy by Anonymous Coward · · Score: 0

      Exceptions (throw/catch) is worse than goto.

      At least goto tells where to find the other end of the spaghetti. With throw you never know where you're going to end - to the point where it's often easier to run the code in the debugger to see which catch 15 function calls away it hits.

    41. Re:I failed a coding test because of this guy by Anonymous Coward · · Score: 0

      The code is great as an entry in an ofuscated programming contest.

      It is not great when you consider that it is just code without any line breaks.

      It is 6 lines/ of code, but there are a lot of statements in there, separated by ; If you use proper line endings, you would probably get 20-30 lines of code.

      You could probably put a lot of the Doom 3 code on a single line if you really wanted to.

  10. This was a test, aimed at slashdot readers... by Derang() · · Score: 5, Funny

    ...To see who actually reads the article.

    Judging from the replies...not many people ;)

    1. Re:This was a test, aimed at slashdot readers... by Virak · · Score: 2, Insightful

      I think you mean the summary. Anyone who read more than a few words into it would've realized they're talking about a person.

    2. Re:This was a test, aimed at slashdot readers... by Anonymous Coward · · Score: 0

      13 words into the summary, to be exact.

      Too much to expect from many readers here, obviously.

    3. Re:This was a test, aimed at slashdot readers... by TrappedByMyself · · Score: 4, Funny

      Anyone who read more than a few words into it

      The calls for the obligatory "You must be new here".

      --

      Help me take back Slashdot. When did 'News for Nerds' become 'FUD and Conspiracy Theories for Extremist Nutjobs'?
    4. Re:This was a test, aimed at slashdot readers... by Stephen+Williams · · Score: 1

      It's worse than you think. They didn't even read the summary.

      -Stephen

    5. Re:This was a test, aimed at slashdot readers... by veg_all · · Score: 4, Funny

      Anyone who read more than a few words into it would've realized they're talking about a person

      Wow. Slashdot article as Turing Test.

      --
      grammar-lesson free since 1999. (rescinded - 2005)
  11. LOL by Anonymous Coward · · Score: 0

    Edgar Dijkstra can drop dead.

    Oh, wait...

  12. GOTO considered harmful by FooAtWFU · · Score: 2, Funny
    GOTO Statement considered harmful.

    Seriously, though, how does a guy end up with a name like this in computer programming? It sounds made-up! Then again, I've heard some very, very odd names...

    --
    The World Wide Web is dying. Soon, we shall have only the Internet.
    1. Re:GOTO considered harmful by Anonymous Coward · · Score: 0

      Presumably by being Japanese?

    2. Re:GOTO considered harmful by Anonymous Coward · · Score: 1, Informative

      It's just two syllables... the first, "go", is pronounced like the "go" in gordon, not like the English word "go". The second, "to", is not like the English word "to", it is pronounced like the "to" in "tornado". Try saying "gohr-tohr".

      Goto seems like a completely reasonable Japanese name as it fits into the phonetic framework of the language. They have the sounds for "g" followed by a vowel, like o, and the sounds for "t" followed by a vowel like o. Most Japanese syllables are formed by the equivalent of one consonant and one vowel in English, with the exceptions being n, shi, chi, tsu, and the combination of ya, yu or yo with another syllable, like rya, ryu, ryo. etc.

    3. Re:GOTO considered harmful by locnar42 · · Score: 1
      One of the CS professors at my university before I attended was named Dr. Null. I thought other students were joking for quite a while because I didn't believe them either.

      Goto is at least Japanese apparently. Maybe it's a popular name there...

    4. Re:GOTO considered harmful by iGN97 · · Score: 1

      Regarding odd names, in Norway, "Odd" is a quite common name. Interestingly enough, so is "Even".

      My uncle is named "Odd Petter".

    5. Re:GOTO considered harmful by Anonymous Coward · · Score: 0

      Where did you learn Nihorngor? "Goto" is pronounced like "go-toe," with both Os clipped a bit (as neither one is elongated).

    6. Re:GOTO considered harmful by Anonymous Coward · · Score: 0

      I got a vasectomy from a guy in Austin named Dick Chopp.

    7. Re:GOTO considered harmful by quantum+bit · · Score: 1

      Seriously, though, how does a guy end up with a name like this in computer programming?

      He doesn't happen to be a hovering black sphere, does he?

    8. Re:GOTO considered harmful by Anonymous Coward · · Score: 0

      My uncle is named Even Steven

    9. Re:GOTO considered harmful by Anonymous Coward · · Score: 0

      You seem to be fairly knowledgable about the syllabic nature of Japanese (except you forgot the vowels by themselves in your list of exceptions), but boy does your pronunciation sound like a cheap comedy impersonation.

    10. Re:GOTO considered harmful by adisakp · · Score: 1

      I love the article you linked to -- according to it, for-loops are bad as well, but he later says he'll allow using them for realism.

      Let us now consider repetition clauses (like, while B repeat A or repeat A until B). Logically speaking, such clauses are now superfluous, because we can express repetition with the aid of recursive procedures.

      There are "realistic" reasons to use goto as well. How else do you break out of a nested loop 4-levels deep without putting the loop in a separate function and using return or without coding a conditional at each level of the loop (which adds code and slows execution.

    11. Re:GOTO considered harmful by mrchaotica · · Score: 1
      How else do you break out of a nested loop 4-levels deep without putting the loop in a separate function and using return
      Answer: You do use a separate function, because a 4 level nested loop is probably unreadable to begin with. You then let the compiler inline the function to eliminate the overhead.
      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    12. Re:GOTO considered harmful by Anonymous Coward · · Score: 0

      Sorry for the "r"s at the end of the pronounciation guide, but I didn't write it like goh-toh because people might think it was like goe-toe (which it is NOT) which would sound like an american hick. It is not "toe" by any means, however. The e on the end implies there is ending intonation, there isn't. It is monotonic, flat, with a breathy dropping off solid oh sound.

    13. Re:GOTO considered harmful by KenSeymour · · Score: 1

      I once worked with a programmer who's last name was Foo.

      She had lots of files with Foo somewhere in the name.

      --
      "We can't solve problems by using the same kind of thinking we used when we created them." -- Albert Einstein
    14. Re:GOTO considered harmful by adisakp · · Score: 1

      Let's say you're doing something trivial like searching a 4-dimensional array. Creating a separate function or adding the extra comparisons generates extra code and takes longer to write without adding *ANY* clarity to the code.

      In this case, a "goto" would not only take less code but also be more readable.

      Besides as far as letting the compiler inline and optimize everything for you, you'd be surprised what most compilers won't do for you on a regular basis.

      Anyhow, goto is often used here because C/C++ is completely lacking in the "labelled break" construct that Java has that allows you to break out from multiple levels of nesting.

      But aside from this trivial case, I've seen plenty of code where a "goto" made the code more readable and more stable. A common one is resource cleanup code for error conditions in straight C functions. Like any other code construct, it can be abused. Abusing "goto" can make your code look horrible. So can abusing STL, ?:, RTL propagation with comma operator, etc.

    15. Re:GOTO considered harmful by Anonymous Coward · · Score: 0

      Sorry for the "r"s at the end of the pronounciation guide, but I didn't write it like goh-toh because people might think it was like goe-toe (which it is NOT) which would sound like an american hick.

      If you pronounce "goe" just like "toe", it most certainly does sound like it. All you needed to say was that; Say it quickly and don't make a dipthong out of it and it'll sound fine. But what would I know, I'm just an American from a small town who has spent 5 months in Japan...

      It is monotonic, flat, with a breathy dropping off solid oh sound.

      In other words, it doesn't sound like something with an "r"? In my dictionary, only three words end in "hr", and all are names with the most common one being Bohr. At least in all the chemistry classes I've taken, the "r" in "Niels Bohr" is not silent.

    16. Re:GOTO considered harmful by Anonymous Coward · · Score: 1, Interesting

      Don't forget the kitsch painter Odd Nerdrum! Odd nerd, yes indeed.

    17. Re:GOTO considered harmful by mrchaotica · · Score: 1
      Let's say you're doing something trivial like searching a 4-dimensional array. Creating a separate function or adding the extra comparisons generates extra code and takes longer to write without adding *ANY* clarity to the code.

      If you have a 4D array, just the for loops take up enough lines of code that, for readability, it should be abstracted to a function as follows:

      some_type_t search4DArray() {
          for (int i = 0; i < x; i++) {
              for (int j = 0; j < y; j++) {
                  for (int k = 0; k < z; k++) {
                      for (int l = 0; l < w; l++) {
                          if (found_item) {
                              return item; /* note the RETURN, not GOTO */
                          }
                      }
                  }
              }
          }
      }


      This code is superior in several ways.
      • It eliminates the goto in favor of return, which is easier to decipher (since goto can jump anywhere, but return only returns to the line after the procedure call).
      • The function name self-documents why you're iterating through the array (presumably you'd use a more descriptive name than my generic example).
      • It abstracts the array search away from whatever larger procedure you're calling it from, making the calling procedure more readable. Remember that short procedures are desirable.
      • It promotes code reuse (since you can call the same search function elsewhere).

      Also note, by the way, that there's negligable function call overhead because it's only getting called once (as opposed to something stupid, like putting each layer of the loop in its own function).

      Anyhow, goto is often used here because C/C++ is completely lacking in the "labelled break" construct that Java has that allows you to break out from multiple levels of nesting.

      Huh. Oddly enough, I've never heard of this "labelled break" you speak of, nor have I missed it. I guess that, since I've been trained from the get-go not to use gotos, my coding style has developed such that I don't even think about trying to do stuff like that. At any rate, after having looked it up to see what it is, it seems less readable to me than, say, a function call as I illustrated above.

      But aside from this trivial case, I've seen plenty of code where a "goto" made the code more readable and more stable. A common one is resource cleanup code for error conditions in straight C functions.
      Alright, I admit that if there's any situation where a case could be made for the use of goto, this is it. However, I'm not convinced it's necessary even then. I think it's sufficient to indicate errors by returning some specified value from a function (e.g. 0, false, null, MAX_INT, etc.) and, if necessary, specifying the particular type of error by setting errno to the ERR_TYPE. Of course, this approach requires good use of abstraction such that each function knows how to clean up any structures that it personally allocated.
      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    18. Re:GOTO considered harmful by Evil+Pete · · Score: 1

      I remember reading a book on the animal origins of human behaviour by Lionel Tiger and Robin Fox. No joke. Google for "The Imperial Animal"

      --
      Bitter and proud of it.
    19. Re:GOTO considered harmful by ilitirit · · Score: 1

      Go To Statement Considered Harmful: A Retrospective

      There's an interesting bit of code at the bottom of the page.

      // A challenge to the reader to rewrite without using goto's
      int parse()
      {
              Token tok;

      reading:
              tok = gettoken();
              if (tok == END)
                      return ACCEPT;
      shifting:
              if (shift(tok))
                      goto reading;
      reducing:
              if (reduce(tok))
                      goto shifting;
              return ERROR;
      }

  13. Re:If true... by DariaM84 · · Score: 1, Offtopic

    I'm in a programming class right now (literally: my notes are open in another window) and GOTO hasn't even come up. It's an intro-level class, but... I see WHY it's used, and it for sure has its purpose, but if there's a more efficient way to program, duh people are going to go for it. And "registration required"? Ha: http://www.bugmenot.com/ (And yes, the NY Times is on there.)

  14. Re:If true... by Anonymous Coward · · Score: 0

    I studied CS, and we did get GOTO statements (Well "jump" to be true). This of course was in IBM390 Assembler.

  15. That would mean... by LoyalOpposition · · Score: 5, Funny

    Goto Considered Helpful?

    -Loyal

    --
    I aim to misbehave.
    1. Re:That would mean... by Anonymous Coward · · Score: 0

      What I'd really like to see is a "come from" statement, just to keep things nice and clear in the code.

    2. Re:That would mean... by infinite9 · · Score: 1

      Yeah, he's the go-to-guy for code optimization.

      --
      Disconnect your television. Do your own research. Draw your own conclusions. They're probably lying. Don't be a sheep.
    3. Re:That would mean... by aaqubed · · Score: 1

      I can see the next headline now:

      "Goto Considered Helpful" Considered Harmful

      --
      Need help - license plate reverse lookup. NY plate CSE-2960. Guy almost hit me, blamed me, pissed me off.
  16. Re:goto is obsolete by Jeremy+Erwin · · Score: 1

    functions impose overhead.

  17. Re:If true... by SatanicPuppy · · Score: 0, Offtopic

    The thing is, "Goto" isn't logical.

    Think about it. There is no valid logical operator that says, "Okay, skip everything in between and go to the end." There is no valid logical constuct that allows you to ignore conditions, or to skip steps without simplifying. It's no wonder its so damn hard to maintain Goto code...Our brains don't work that way!

    Sure it's quick. How could it not be? There isn't anything to it...you don't have to check anything or clear anything, you just jump ahead.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
  18. Using goto in Linux Kernel Code by trip23 · · Score: 0, Offtopic

    http://kerneltrap.org/node/553
    goto in linux kernel code is not considered harmful. Linus said so in 2003!

    1. Re:Using goto in Linux Kernel Code by quantum+bit · · Score: 1

      FreeBSD uses it quite a bit in system code as well, mostly to simulate exception handling. For example, "goto bad;" after an error to jump to the end of the function which cleans up any memory allocations, etc. Much better than duplicating the cleanup 20 times after each error check.

  19. Clearly Harmful by tverbeek · · Score: 2, Funny

    This guy is clearly considered harmful.

    --
    http://alternatives.rzero.com/
    1. Re:Clearly Harmful by scott_karana · · Score: 1

      Actually, he's mostly harmless.

  20. DEC Math Library by boa13 · · Score: 5, Interesting

    DEC had an ultra-optimized math library (calculations on arrays, Fourier transforms, etc.), improved over decades by generations of PhDs. There were different versions of the routines for the different generations of CPUs, for the different cache sizes of a same model, maybe even for various speeds of RAM. Needless to say, the simple fact of linking against that library instead of the standard one improved the speed of math intensive code by a good 10 to 20 percent (those numbers out of my fuzzy memory, but that far from insignificant).

    Add to that compilers that were producing top-notch machine language for the target architecture (producing images that ran twice as fast as what gcc gave you at best), CPUs that were spanking the rest of the world as far as floating-point performance was concerned, and you can understand why the scientific community has kept using Alphas for so long.

    1. Re:DEC Math Library by Fess_Longhair · · Score: 2, Interesting

      The library is still alive. Apparently a group of the DEC developers are now at intel, and the the library is called the Math Kernel Library (MKL). http://www.intel.com/cd/software/products/asmo-na/ eng/perflib/219769.htm

    2. Re:DEC Math Library by Anonymous Coward · · Score: 0

      Actually, the history of this is that Compaq bought DEC (and the compiler/library group with it), and then Compaq sold the compiler and library group to Intel sometime around the merger with HP.

  21. Re:goto is obsolete by ciroknight · · Score: 2, Insightful

    Point taken, but in the early days goto still made a lot of sense, but a lot of conventional, old practices have gone the wayside with compilers that are smarter and better optimizing, and with better standardization in languages overall.

    The *first* time I learned C, goto was perfectly acceptible (yay K&R original C material).

    But really, my point is that a computer doesn't see things in the sense of functions; it sees things in the sense of labels (memory addresses), and in a sense, programming using functions is simply another way of getting around labeling a routine.

    --
    "Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
  22. No you idiots - it's not about GOTO statements by iBod · · Score: 0, Flamebait

    Read TFA and dig a bit, then you will see...

    >>Actually, GOTO is my last name and does not mean "go to." (Nor is it pronounced "go to"; the correct pronunciation of my name is more like "goat-toe.")

    Good God! How many of you slashbot jerks even bother to sniff the article before launching into a tirade about structured programming etc.

    Dumb asses, the bunch of you!

    1. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 0

      GOTO hell!

    2. Re:No you idiots - it's not about GOTO statements by 91degrees · · Score: 3, Interesting

      No, it is about structured programming. At least indirectly through use of the pun. It's more on topic than a lot of the discussion on this site.

    3. Re:No you idiots - it's not about GOTO statements by limabone · · Score: 5, Funny

      Oh, Goat-toe hell you spoilsport!

    4. Re:No you idiots - it's not about GOTO statements by R2.0 · · Score: 2, Funny

      "the correct pronunciation of my name is more like "goat-toe.""

      Is that anything like camel toe?

      --
      "As God is my witness, I thought turkeys could fly." A. Carlson
    5. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 1, Interesting
      The funny thing is . . . it's about extreme optimization of library code for math. Presumably, these optimizations make extensive use of assembly code, which, in turn, presumably makes extensive use of the JMP command or its equivalent. Which is, in fact, a GOTO.

      Not to mention that code using GOTOs instead of more elegant control structures does, in fact, run faster since the machine doesn't have to worry about maintaining a call stack, etc.

    6. Re:No you idiots - it's not about GOTO statements by fdrake76 · · Score: 1
      Good God! How many of you slashbot jerks even bother to sniff the article before launching into a tirade about structured programming etc.

      Actually on articles like these, I sprint to the comments sections to make my dumb jokes before someone else takes them and *then* read the article to see if it's any good. I find I'm much better at making people laugh instead of making them smarter (as the predicted mod score of this post will surely attest to).

    7. Re:No you idiots - it's not about GOTO statements by ArsonSmith · · Score: 1

      And the name Goat-toe is much funnier than an article about goto making faster code.

      --
      Paying taxes to buy civilization is like paying a hooker to buy love.
    8. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 0

      Sad that you have to point it out. You say ". . .bunch of you!", do you not mean troop, as it is a troop of monkeys, bunch of bananas. I would find that most slashdotters are more akin primates than fruit. The pronouciation of his surname would be GOH-TOH.

    9. Re:No you idiots - it's not about GOTO statements by atrocious+cowpat · · Score: 1

      "Good God! How many of you slashbot jerks even bother to sniff the article before launching into a tirade about structured programming etc. Dumb asses, the bunch of you!"

      IF DUMP ASS GO ATSE.CX

      Or was it the other way round? Anyway: There! Neener-Neener!

      ;-)

      --
      sig? Oh, that sig...
    10. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 0

      goto hell

    11. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 0

      I don't think Kazushige did the original post for this thread "No you idiots - it's not about GOTO statements", he is too polite. But it is correct! Here is more information about his approach and a question.

      From Kazushige Goto's webpage http://www.tacc.utexas.edu/~kgoto/#overview [utexas.edu]

      "During the last decade, a number of projects have pursued the high-performance implementation of matrix multiplication. Typically, these projects organize the computation around an "inner-kernel", C = trans(A) B + C, that keeps one of the operands in the L1 cache, while streaming parts of the other operands through that cache. Variants include approached that extend this principle to multiple levels of cache or that apply the same principle to the L2 cache while essentially ignoring the L1 cache. The purpose of the game is to optimally amortize the cost of moving data between memory layers.

      Our approach is fundamentally different. It starts by observing that for current generation architectures, much of the overhead comes from Translation Look-aside Buffer (TLB) table misses. While the importance of caches is also taken into consideration, it is the minimization of such TLB misses that drives the approach. The result is a novel approach that achieves highly competitive performance on broad spectrum of current high-performance architectures."

      So why have chip designers, software developers and academics been focused on impoving cache preformance (e.g. L1, L2, L3, ...) and not improving TLB and virtual memory performance?

    12. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 0

      Actually, the article is full of Goto statements.

    13. Re:No you idiots - it's not about GOTO statements by smoker2 · · Score: 1
      >>Actually, GOTO is my last name and does not mean "go to." (Nor is it pronounced "go to"; the correct pronunciation of my name is more like "goat-toe.")
      Any relation to "Camel Toe" ?

      Or has he a chinese ancestor called Goat Tse ?

    14. Re:No you idiots - it's not about GOTO statements by alta · · Score: 1

      I'd say that everyone understands that it's not about goto statements...

      But talking about goto statements is a lot more fun than the boring ass story!

      and when talking about a goto statement is more fun than what you're talking about, you REALLY should stop talking :p

      --
      Do not meddle in the affairs of sysadmins, for they are subtle, and quick to anger.
    15. Re:No you idiots - it's not about GOTO statements by barronVonBackstabber · · Score: 1

      Is that similar to a camel-toe, just a bit smaller?

    16. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 0

      You mean Camel-toe.

    17. Re:No you idiots - it's not about GOTO statements by Anonymous Coward · · Score: 0

      It's humor (hoo-mer).

      Something funny that makes you laugh. You see, a guy name Goto who tells us how to program is a fantastic pun. Did you seriously not laugh when you first read that? That's freaking FUNNY.

      Of course we know it's about a guy, not GOTO statements. The summary makes that very clear.

      You must be new here.

  23. Its better if you have a f***ing clue by everphilski · · Score: 1, Insightful

    And people who "meticulously hand optomize" their code annoy the crap out of me. Run it, tweak it, run it again. Was the second run faster? Then tweak some more.

    When we are talking about math routines (I do simulation programming for engineering applications) its much better if you have a f'ing clue about what you are doing than just *tweaking* and seeing if it works better. And when runs take hours, it often isn't even an option.

    -everphilski-

    1. Re:Its better if you have a f***ing clue by SatanicPuppy · · Score: 1

      See, if I'd bothered to read the article, I would have skipped the comment. I skimmed the summary with about 2% comprehension, and punched one of my own buttons regarding hand testing code. Nothing makes me crazier than having to work the math on a simple change that anyone with six months experience would see as an obvious improvement in a project that would take less time to compile than it would take to get a fresh cup of coffee.

      --
      ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
    2. Re:Its better if you have a f***ing clue by samschof · · Score: 2, Interesting
      There is still a lot of tweaking going on in scientific computing. I work on large scale parallel computational fluid dynamics codes where performance can be tricky, especially when dealing with parallel iterative solvers. We often have to build and try a variety of preconditioners and simply measure which gives us the best performance. One preconditioner may lower the iteration count substantially, but it is quite expensive to apply; another may require excessive communication. You may also find that what works great on 32 processors deteroriates quickly once you scale to 256 processors. The point is that you rarely know in advance what the optimal strategies are.

      Of course, these "tweaks" are related the global numerical scheme. Reordering a loop here and there then running to see if it made a difference is simply not practical as you point out.

      Sam

  24. Thank you very much by Prince+Vegeta+SSJ4 · · Score: 3, Funny

    10 Print "oh Mr. K. GOTO" 20 I=I+1 30 If I 5 Print "Domo" Else 50 40 GOTO 20 50 Print "I'm Kilroy! Kilroy! Kilroy! Kilroy!"

    1. Re:Thank you very much by Killjoy_NL · · Score: 1

      No, I'm Killjoy

      oh wait...

      --
      This is the sig that says NI (again)
    2. Re:Thank you very much by Anonymous Coward · · Score: 0

      BRILLANT!

    3. Re:Thank you very much by StikyPad · · Score: 1

      BRILLANT!

      IRONIC!

  25. Assembler Leads to Even Faster Code by McPolu · · Score: 1

    Assembler Leads to Even Faster Code

    1. Re:Assembler Leads to Even Faster Code by ichigo+2.0 · · Score: 2, Informative
    2. Re:Assembler Leads to Even Faster Code by An+Ominous+Cow+Erred · · Score: 1

      Of course, because everyone knows compilers are destructive!

  26. That's too bad for Mr. Goto by macklin01 · · Score: 1

    From TFA:

    It is in the same sense that Kazushige Goto's business card says simply "high performance computing."

    i.e., Goto is the name of the developer, not the name of the coding practice he's using! -- Paul

    --
    OpenSource.MathCancer.org: open source comp bio
    1. Re:That's too bad for Mr. Goto by blindcoder · · Score: 1

      Oh yeah, well, excuse me, I left my sarcasm tags at home today so I couldn't mark the funny in my post for the humorously challenged...

      --
      See my blog for my free opinions.
  27. Re:This caught me off guard! by Anonymous Coward · · Score: 0

    ... and he must have done something awefully wrong, based on his reputation.

  28. Re:goto is obsolete by fdrake76 · · Score: 5, Funny
    Weren't FUNCTIONS invented for the purpose of finally getting rid of goto and labels?

    I believe you are referring to Kazushige's cousin, Mr. Gosub.

  29. dreams by tezbobobo · · Score: 1

    Ahh, the fleeting glimmer of hope, that one day correct programming practices would be discovered incorrect and life would once again become easy.

    But really, is this his real name? did he change it? It could make for some great marketing. "Need Speed? GoTo Goto!"

    I would be open to suggestions for names in up and coming business ventures I could start based soley on the punability of my surname. But for the love of god, no viagra jokes.

  30. Re:duh.... by se2schul · · Score: 0, Redundant

    If used properly, GOTOs can still leave the code readable and maintainable. Besides.... We've all been using GOTO's under different names. In C++, what do you think the 'case' statement or the 'break' statement is? It's essentially a GOTO. Still readable. Still maintainable. Bad programmers will leave code unreadable and unmaintainable regardless of whether or not they use GOTOs. Good programmers can use GOTOs with no problems.

  31. ...summary by colonslash · · Score: 1

    RTFS

  32. I'm hungry. by RandoX · · Score: 0

    For spaghetti. RAmen.

    1. Re:I'm hungry. by z0l0pht · · Score: 1

      10 PRINT "This is teh funny"
      20 PRINT "Mod this up."
      30 GOTO 10

      mmm... spaghetti

  33. Mr. Goto is the one you need! by Bananatree3 · · Score: 2, Funny

    He is your goto-guy :)

  34. Not wasting stack space... by Tominva1045 · · Score: 1



    If I use GoTo and make most everything global then am I not saving valuable stack space?

    Separately, there are some great logical solutions to problems involving the use of GoTo-- we use it to manage the class instance variables (and their states) in a multi-threaded application loop where the number of threads is adjustable at runtime.

    --
    Cogito Ergo Sum
  35. This Guy by Nom+du+Keyboard · · Score: 1
    tell them that if they want the fastest they should still turn to Mr. Goto.

    Obviously he's the GoTo Guy.

    --
    "It's the height of ridiculousness to say for those 9 lines you get hundreds of millions."
  36. Re:GOTO Considered Harmful since at least 1968 by Anonymous Coward · · Score: 0

    Using GOTO is fine and readable as long as you never jump backwards.

  37. Re:goto is obsolete by iamacat · · Score: 0, Offtopic

    Some programming concepts are cleanest when expressed with functions, some with loops and some with gotos. If you have a finite state machine with 7 states and non-trivial logic for transitions, using 7 well-named labels and gotos is cleaner than any other alternative. K&R C book is pretty slim. I think it's not too much to ask anyone to read it and use all the available language constructs and libraries appropriately.

  38. Re:GOTO Considered Harmful since at least 1968 by McPolu · · Score: 1

    Hum... that is why exceptions were invented.

  39. this is the cryptonomicon all over again. by k-sound · · Score: 1

    I remember constantly wondering where the fuck dengo was and what was so special about the place anyway while reading that book.

  40. Re:If true... by ciroknight · · Score: 2, Insightful

    The thing is, "Goto" isn't logical.

    Your argument against Goto is even less logical. Goto is a conditional jump, where the condition is always true. It's an if (true) { do; }.

    Our brains have plenty of Goto's hardcoded into them; "repeat" is typically implemented through in a "goto" fashion, but you'll want to ignore that if you're a modern computer. The correct way is to instead unroll the loop and have no jump instruction at all (if you can get around it).

    Sigh. Why don't they teach assembly anymore. It should be a pre-req to learning higher level languages.

    --
    "Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
  41. Re:GOTO Considered Harmful since at least 1968 by mrsbrisby · · Score: 1, Insightful
    Agreed. GOTO is excellent for exception handling. People are often taught to do blocks like this:
    done = 0;
    for (i = 0; i &lt; 100; i++) {
      for (j = 0; j &lt; 100; j++) {
        if (sc[i][j] == ch) {
          done = 1;
          break;
        }
      }
      if (done) {
        break;
      }
    }
    Goto simply makes it more readable:
    for (i = 0; i &lt; 100; i++) {
      for (j = 0; j &lt; 100; j++) {
        if (sc[i][j] == ch) goto DONE;
      }
    }
    goto FAIL;
    DONE:
    ...
    FAIL:
    ...
    ... and lo, compilers will often produce better code with this construct. So you get more readable, faster code.

    In general, I find it easy to follow as long as gotos always go the same direction (down)- and that we only have one or two labels in a function- we're fine.

    Although, also in general, people who use gotos going up, or have more than two labels in their functions, or that otherwise avoid goto like it's some sort of plague tend to have other problems.

  42. goto is not obsolete by PhrostyMcByte · · Score: 0, Redundant
    Try cleanly breaking a loop from within a switch. It also makes error handling simpler.
    foo=malloc(1);
    if(!foo) return -1;
    bar=malloc(1);
    if(!bar) goto err1;
    baz=malloc(1);
    if(!baz) goto err2;

    return 0;

    err2:
    free(bar);

    err1:
    free(foo);

    re turn -1;
    Other than those two cases, I agree goto should be kept away from noobs who would like to abuse it.
    1. Re:goto is not obsolete by Threni · · Score: 1

      Too busy to check this, but don't you prefer something like:

      int retval = -1;

      if (foo = malloc(1))
      {
            if (!bar=malloc(1))
              free(foo);
            else
              if (!baz=malloc(1))
              {
                      free(bar);
                      free(foo);
              }
              else
                      retval = 0;
      }

            return retval;

    2. Re:goto is not obsolete by Anonymous Coward · · Score: 0

      What kind of dumbass, shitbox, stupid programmer are you? Here's a solution to your "problem":

      foo=malloc(1);
      if(!foo) return -1;
      bar=malloc(1);
      if(!bar) {free(bar); return -1;}
      baz=malloc(1);
      if(!baz) {free(baz); return -1;}

      return 0;

      But why the hell would you be freeing bar & baz in the error code, seeing as they're == NULL ??

      Sure, goto probably is faster in many situations, but the fact is that the disadvantages outweigh the advantages of using it. Removing memory protection from operating systems would lead to a huge speed increase, but it's simply not practical for the uses which personal computers are put to. Goto leads to sloppy code, which leaves plenty of room for error (and security holes, etc). Of course, that's no to say that it's not useful in software for supercomputers which don't require security (e.g. for weather prediction), but you'd still have the problem of the reliability of the code, and of course maintainability. But of course some software doesn't need to be maintained or edited much (e.g. software written to run once on a supercomputer to carry out certain scientific calculations which would reach a definitive conclusion and not require further calculation). So with the problems of security and maintainability factored out, reliability (i.e. ability for the software to achieve its purpose), it remains feasible to use goto in every 10 lines of code if its going to save you 3 months of supercomputer time (i speculate it's a large expense to run a supercomputer, and every minute of time wasted counts).

      Excuse my extremely sloppy writing, I'm rushing, and don't have time to proof read & restructure.

    3. Re:goto is not obsolete by Anonymous Coward · · Score: 0


      static inline void nfree(void *ptr) { if(ptr != NULL) free(ptr); }

      void poo()
      {
          void *foo = NULL, *bar = NULL, *baz = NULL;

          if((foo = malloc(1)) == NULL) goto error;
          if((bar = malloc(1)) == NULL) goto error;
          if((baz = malloc(1)) == NULL) goto error;

          return 0;

      error:
          nfree(foo);
          nfree(bar);
          nfree(baz);
          return -1;
      }


      j00 like?
      On the other hand, if you're not allocating large chunks of memory, you're better off using alloca() which allocates memory on the stack, rather than the heap. That way you won't have to worry about freeing the memory at all.

    4. Re:goto is not obsolete by Anonymous Coward · · Score: 0

      Enjoy your memory leaks, "dumbass".

    5. Re:goto is not obsolete by Threni · · Score: 1

      > j00 like?

      Not really.

      Alloca isn't a standard C function, so it's not portable. Inline is supported on more recent C compilers - isn't it a C99 thing? So probably not available in older compilers in strict ANSI mode (though I could be wrong).

      You're defining the variables locally, which the OP didn't, so you're going to be unable to access the memory once the function if exited from.

      And it's still got a goto. If goto is acceptable then I prefer the OPs version.

    6. Re:goto is not obsolete by Threni · · Score: 2, Funny

      > What kind of dumbass, shitbox, stupid programmer are you?

      Oh dear. That's the worst code I've seen for ages.

      Why free bar in the case that its attempt to allocate memory fails? Shouldn't you instead be freeing foo?

      Likewise for the attempt to malloc baz, where you attempt to free baz instead of both bar and foo.

      > Excuse my extremely sloppy writing, I'm rushing, and don't have time to proof
      > read & restructure.

      Not only that, your code is terrible, and your quoted justification for using goto "in every 10 lines of code" shows that you shouldn't be let anywhere near a compiler.

      And after all that, you manage to find it within yourself to abuse someone who clearly knows more about the subject than yourself! Do you perhaps have a very small penis?

    7. Re:goto is not obsolete by Locke2005 · · Score: 1

      I still use goto, but usually only as the most efficient way to break out of nested for/while loops.

      --
      I've abandoned my search for truth; now I'm just looking for some useful delusions.
    8. Re:goto is not obsolete by Anonymous Coward · · Score: 0

      Why would you write it like that? You can free() NULL pointers safely.

      foo = malloc(1);
      bar = malloc(1);
      baz = malloc(1);

      if( !foo || !bar || !baz )
      {
            free(foo);
            free(bar);
            free(baz);
            return -1;
      }
      return 0;

    9. Re:goto is not obsolete by Anonymous Coward · · Score: 0

      It's also a void function that is return ints.

  43. Preserving valuable stack space.. by Tominva1045 · · Score: 0, Offtopic

    If I use GoTo and make most everything global then am I not saving valuable stack space..?

    Separately, there are some great logical solutions to problems involving the use of GoTo-- we use it to manage the class instance variables (and their states) in a multi-threaded application loop where the number of threads is adjustable at runtime.

    --
    Cogito Ergo Sum
  44. Holy crap! by SatanicPuppy · · Score: 1

    You're right! Jesus.

    *Pours more coffee*

    Mods on crack. I tell ya. Can't believe that made it to 5.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
  45. I knew it!! by sucker_muts · · Score: 1

    I just knew my code is better with goto's than while's, for's, and all those other hidiously difficult to use statements.

    Now if I just could fine the mail address of my CS teacher he'll finaly have to correct my grades from before.

    ...all these years...

    --
    Dependency hell? => /bin/there/done/that
  46. Re:goto is obsolete by Anonymous Coward · · Score: 0

    had I mod points, you would receive one.

  47. Don't care about the guy's name.. by Tominva1045 · · Score: 1



    We don't limit our thought process to the article. Sometimes we GoTo a place outside the box.

    --
    Cogito Ergo Sum
    1. Re:Don't care about the guy's name.. by iBod · · Score: 0, Offtopic

      Uhhh - yeah, right.

      Forgive me if I suggest you stay firmly within YOUR box, pal.

  48. a well-positioned goto is quite clear by more · · Score: 1
    I have written a function with 17 gotos. During my 15 year C++ career, I have written another function with a single goto, too. Both were well-justified and most performance-oriented.

    IMHO, a well-positioned goto is more clear than a structural variable. For example, jumping out of a loop inside a loop is quite nice with a goto. There is no such thing as a double break.

    --

    -- Imperial units must die --

    1. Re:a well-positioned goto is quite clear by aug24 · · Score: 1
      There is no such thing as a double break.

      In Java...

      banana: for (int i=0;i<10;i++) {
      apple: for (int j=0; j<10;j++) {
      System.out.println(i + ", " + j);
      if (i<j)
      break banana;
      }
      }
      ...results in
      0,0
      0,1

      So Java beats C yet again! Faster and better structured! ;-)

      Justin.
      (Forgive the crap indenting, buggered if I can make it any better)

      --
      You're only jealous cos the little penguins are talking to me.
    2. Re:a well-positioned goto is quite clear by fbartho · · Score: 1

      it blew my mind when I figured out that that was valid in C as well...

      you can break to a label.

      I think that though, there is a difference between goto and break used in this manner... when you break label1; you actually go to the statement after label1 though I'm not 100% certain on that.

      --
      Gravity Sucks
    3. Re:a well-positioned goto is quite clear by aug24 · · Score: 1

      It is?! (valid in c)

      I tried it and got a parse error from gcc. Sample code pls? (I like to learn a little something every day!).

      Cheers,
      J.

      --
      You're only jealous cos the little penguins are talking to me.
    4. Re:a well-positioned goto is quite clear by fbartho · · Score: 1

      my apologies, I think I misread something in my java textbook that made me believe it was valid in C... it is funny though in java...

      --
      Gravity Sucks
  49. Re:goto is obsolete by VernonNemitz · · Score: 1

    goto is OK because it can do something in any language that offers it, that no other construct in that language allows.
    You can jump from inside the middle of one nested set of loops and/or tests directly into the middle of another set.
    (USE WITH CARE!)
    Without goto, you have to set a flag and then test that flag multiple times to do the equivalent. What a waste of time!

  50. I always knew that those goto statments were great by Rooked_One · · Score: 0, Offtopic
    i mean come on...

    10 ?"goto statements remind me of 7th grade and looking through the hole in the girls changing room"
    20 goto 10

  51. For added fun. by sammy+baby · · Score: 2, Funny

    Hey kids! Your uncle Sammy here, with a fun rainy-day Slashdot activity for you!

    First: take an article which revolves around a pun, just like this one, to deliver a message which has a different meaning than the headline would suggest.

    Next: Pick a comment-karma threshold. Two or three ought to do it!

    Last: Count how many of the people at that level have completely missed the point of the article: specifically, that the "Goto" in the writeup is not a GOTO statement, but rather the name of a programmer named Kazushige Goto; that this particular distinction is supposed to be considered a bit of ironic humor; and, that this is, in fact, the reason that Hemos posted it "from the we're-punny-this-morning dept."

    Hours of fun for everyone!

    1. Re:For added fun. by Ctrl-Z · · Score: 0, Offtopic

      Even better: Count how many people whine about how many people have completely missed the point of the article. Seriously, I don't see that many people missing the point, but I do see a lot of people trying to make puns out of the name.

      --
      www.timcoleman.com is a total waste of your time. Never go there.
    2. Re:For added fun. by Ralp · · Score: 1

      Hey has anyone said "he's the 'go-to' guy" yet because I think that is a pretty clever and original joke that I just thought of

  52. Dear Moderators, by mangu · · Score: 1, Flamebait

    Please moderate the parent of this post and all others who hurried to post comments on the "GO TO" statement (-1, Redundant). These suckers who don't even read the summary in the scramble to get the first post should be reduced to the status of posting at -1. Thanks.

    1. Re:Dear Moderators, by NicklessXed · · Score: 1

      Please moderate the parent of this post and all others who hurried to correct people who made jokes about the GO TO statement (-1, No Sense Of Humor). While I agree that the joke is obvious, there is no reason to mod the first one who made it Redundant.
      Of course, the other posts with the same joke should be modded down.

      BTW, am I the only who thinks that posts like the parent are far more annoying than the about 70 GO TO posts, that probably have appeared while I'm writing this?

    2. Re:Dear Moderators, by whmac33 · · Score: 1

      I second your motion.

    3. Re:Dear Moderators, by RamblerRandy · · Score: 1

      I tried to moderate but slashdot turned of the moderation after I moderated yours! ;-)
      Anyway, hmm, I think that like has too many of: [goto line 100], [print "moderate"] statement in it!
      BTW: how do you delimit a BASIC (let alone 'C') statement in English? I'm still waiting for a English class for us "techies" to take "English as a programming language" so I can learn it's SOLID rules for me to understand! Wait! There is no 'solid' rules in English! Oh well, still need the class. Um, not the C++ class(ifier).</p>

      Ok, ok, best I can do for jokes, I've been out practice, ok?! In all 3 languages: MS BASIC (pre Qbasic), COBOL, 'C', plus a more recent class in C++ (June 2002).

      And SHUT UP about my "dangling participles" whatever the heck fire that is!

      if(sentence_structure(POINTER) == "dangling" && sentence_structure(POINTER+1) == "participle")
      {
      fprint("error");
      exit(-1);
      }
      else
      fprint("shut up!");

      save file and then:

      c what.c

      "compiler error: English is not a supported module"

      *sigh*
      ** this writing is not compiled by an English compiler for semantic or phrasing errors! They don't exist! Ok, never mind Editors...

      --
      I'll think of a really good SIG just before I die.
    4. Re:Dear Moderators, by unitron · · Score: 1
      "Wait! There is no 'solid' rules in English!"

      I'm pretty sure that there's at least one. The one that says you should have said that there 'are' no solid rules in English. :-)

      --

      I see even classic Slashdot is now pretty much unusable on dial up anymore.

  53. Re:This caught me off guard! by g0at · · Score: 1

    Well jesus fucking christ, it's a good thing you posted a comment telling us all about this! You could have saved some typing, though, and just said "guess what everybody! I didn't read the article, or even pay attention to the summary!!11!1!"

    -b

  54. Re:GOTO Considered Harmful since at least 1968 by Malc · · Score: 1
    I think the modern equivalent (in C++) to this is (please excuse the indentation):
    try
    {
    // do useful stuff
    // if fatal_condition then throw MyException()
    // do useful stuff
    // if fatal_condition then throw MyException()
    // do useful stuff
    }
    catch (MyException& e)
    {
    // bail code goes here
    }
    // do end-of-procedure-cleanup
  55. Re:If true... by Anonymous Coward · · Score: 0

    But you can't just unroll all your loops either since your instruction cache usage will be very bad in that case.

    Deciding which loops to unroll is left as an exercise to the reader :)

  56. Ok... by toupsie · · Score: 2, Funny

    0 END

    --
    Strange women lying in ponds distributing swords is no basis for a system of government.
  57. Re:The Fastest Code of All by limabone · · Score: 1

    1 GOTO END

    BEAT YA! Yours wont even get executed mwahahhahahahahaha!

  58. Perfect example by aepervius · · Score: 1

    of somebody which should read the article before answering and OBVIOUSLY DID NOT DO IT.
    Please Moderate me -5 "Idiot, RTFA".

    --
    C. Sagan : A demon haunted world:
    http://www.amazon.com/gp/product/0345409469/
    visit randi.org
  59. Re:If true... by iamacat · · Score: 1

    Ever assembled a desk or something after it was shipped to your place? Those instructions always have numbered steps and statements like "if you don't need to attach your desk to the wall, go to step 5". Makes perfect sense and since the steps are sorted, I can easily find step 5 in the manual rather than looking for a named label or (*horror*) closing brace with correct indentation.

  60. Re:If true... by CastrTroy · · Score: 1

    Most courses if they mention GOTO at all, tell you never to use it ever. Maybe by not telling you about it, they assume that you won't know about it, and therefore never use it. Nobody in university does learning on their own time. The reason they tell you not to use it, is because it can make spagetti code very easily. However I've found there are good uses for it, and it can make code a little cleaner in certain circumstances. It doesn't pop up very often, but it can be used as a proper method of coding. I am aware that anything can be done with gotos, but at some points, goto actually produces nicer results then the non-goto equivalent.

    --

    Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
  61. Re:If true... by mightypenguin · · Score: 1

    Not to bash your point too much, but my brain works that way :) I remember in school we had to write an assembly program in gcc and I used jmp instructions to dance around a block of code so much (I was trying for the smallest program) that I got my A paper back with my favorite teacher comment ever... "too complex."

  62. Re:If true... by Random832 · · Score: 1

    The semicolon operator "don't start doing this thing until this other thing is completely done" has no place in logic, either. Programming languages aren't based on formal logic, and our brains _do_ work that way. And so do CPUs.

    --
    We've secretly replaced Slashdot with new Folgers Crystals - let's see if it notices.
  63. Re:If true... by qwijibo · · Score: 0, Offtopic

    Goto is used because it is more efficient from the processor's perspective. Function calls have additional overhead. Function calls are easier to follow than a chain of goto's, so most people consider the cost paid in processing time to be well worth the decreased time needed in implementation, testing, debugging, and maintenance.

  64. RTFA. by Anonymous Coward · · Score: 0

    I am still waiting for someone to provide a link that does not require registration. Until then the trolls have a free playing field.

    1. Re:RTFA. by Anonymous Coward · · Score: 0

      Use bugmenot.com

      Even then, there's more than enough information in the first 2 sentences of the summary for people not to be making these stupid mistakes :p

  65. Re:If true... by Anonymous Coward · · Score: 0
    There is no valid logical operator that says, "Okay, skip everything in between and go to the end."

    Neither is there a logical operator for "while", "for", or any other flow control construct.

  66. Where does the slashdot effect come from? by tehanu · · Score: 4, Interesting

    A lot of people complain about people never reading the actual articles before they comment, but it seems worse than that. People don't even bother reading the blurbs.

    I wonder where the slashdot effect comes from then?

    1. Re:Where does the slashdot effect come from? by tehanu · · Score: 1

      I forgot the best thing though. In Japanese, "Goto" doesn't even sound like the programming "go to" :)

    2. Re:Where does the slashdot effect come from? by HawkingMattress · · Score: 1

      Easy, just install the slashdot effect firefox extension like everybody else and you too won't need to read the article in order to hammer the pages of those poor bastards who have their sites posted on the frontpage
      That way we can all keep on complaining about not being able to read the article and make stupid offtopic and misinformed comments like this one, yay.

    3. Re:Where does the slashdot effect come from? by Anonymous Coward · · Score: 0
      In Japanese, "Goto" doesn't even sound like the programming "go to" :)

      Well it would if you pronounced the programming goto Japanese style.

    4. Re:Where does the slashdot effect come from? by Anonymous Coward · · Score: 0

      There are two directions one can go on slashdot. You either click the article, or you click the comments link. If you click the article, and read it, you will become distracted or disinterested by the time you're finished, and have no reason to post. If you click the comments link, you will gloss over some other people's comments and either make a misinformed reply to one or a misinformed new post.

    5. Re:Where does the slashdot effect come from? by jokercito · · Score: 1

      Probably from the lurkers like me who prefer to actually read an article instead of posting inane comments. (Says the guy who mostly posts unfunny attempts to be funny...)

    6. Re:Where does the slashdot effect come from? by jupiter909 · · Score: 1

      One method I personally think happens is that most slashdotters click a link, see that it has no pictures and realise that some reading is needed so then close that tab/window. As they have short attention spans, those same few might click again or might be hoping for some pictures to appear. Thus you have the slashdot effect.

    7. Re:Where does the slashdot effect come from? by Goonface · · Score: 1

      prefetching

    8. Re:Where does the slashdot effect come from? by raoul666 · · Score: 1

      Well, personally...

      10 middle click any links in firefox
      20 middle click tabs to close them
      30 giggle with girlish glee
      40 goto 10

      --
      When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl
    9. Re:Where does the slashdot effect come from? by StikyPad · · Score: 1

      You must be tehanu here. We just middle click on the links as we browse the summaries, then go for a smoke break. When we get back, we post comments!

    10. Re:Where does the slashdot effect come from? by Anonymous Coward · · Score: 0

      Die, you fucking smoker asshole!

  67. Most flamebait title ever! by Chris+Pimlott · · Score: 1

    -sigh-

  68. Re:goto is obsolete by Anonymous Coward · · Score: 0

    The *first* time I learned C, goto was perfectly acceptible (yay K&R original C material).

    What the hell are you on about, I dont have a copy of k&r handy but i distinctly remember them saying something like "goto is inifinitely abusable and should be avoided".

  69. Pah! by BJH · · Score: 3, Informative

    Anybody who criticizes Goto Kazushige's Free Software credentials - he created a Linux/Alpha distribution called Stataboware, which among other things included an early version of his hand-tuned math library back in 1999 (it's now defunct, unfortunately).

  70. Slashdot 2000 by DarthVain · · Score: 2, Funny

    10 Goto FirstPost
    ^C^C^C^C^C^C^C^C

  71. Mod parent up! by DimGeo · · Score: 1

    Mod parent up!

  72. Which is cleaner? by Anonymous Coward · · Score: 0

    Well, I was going to post an example of when goto can be used to improve code flow by streamlining multiple "early return" conditions, but sadly the LameAss(sic) filter rejected it. So you'll have to take my word for it.

  73. Re:goto is obsolete by archeopterix · · Score: 1
    functions impose overhead.
    You mean the pun whooshing over grandposter's head?

    *rimshot!*

  74. Another punny name by Riktov · · Score: 5, Funny

    From the article:
    "Robert A. van de Geijin, a computer scientist who works with Mr. Goto at the Texas Center,..."

    All right, a Japanese programmer named Goto, working with a non-Japanese guy name Geijin. That's too much.

    1. Re:Another punny name by aug24 · · Score: 3, Informative

      Thankfully for my sanity, that one is a typo. It's Van de Geijn (the ij is originally a y with an umlaut - Dutch).

      Justin.

      --
      You're only jealous cos the little penguins are talking to me.
    2. Re:Another punny name by mmusson · · Score: 1, Informative

      The Japanese word that means foreigner is gaijin not geijin.

      --
      SYS 49152
    3. Re:Another punny name by Anonymous Coward · · Score: 0

      It's close enough, you old sod =P

    4. Re:Another punny name by CB1492 · · Score: 1

      Domo arigato, Mr. K. Goto

    5. Re:Another punny name by Scarblac · · Score: 1

      the ij is originally a y with an umlaut - Dutch

      Ahem. The Dutch letter 'ij' is not an y with an umlaut.

      --
      I believe posters are recognized by their sig. So I made one.
    6. Re:Another punny name by stevesliva · · Score: 1

      The fact that you understood the pun makes it a successful pun, not the spelling. Sheesh.

      --
      Who do you get to be an expert to tell you something's not obvious? The least insightful person you can find? -J Roberts
    7. Re:Another punny name by aug24 · · Score: 1

      Strange, I read the same article and think it agrees with me. It's written as a y with an umlaut. Doesn't have the same meaning as it would in germany, but that's definitely a y, and it definitely has two dots over it.

      J.

      --
      You're only jealous cos the little penguins are talking to me.
    8. Re:Another punny name by Dahan · · Score: 0

      It looks like a y with two dots over it when handwritten. That doesn't mean it is related in any way. E looks like an F with an extra line, but it would be incorrect to say that E was originally an F.

    9. Re:Another punny name by Dr.Ruud · · Score: 1

      Aaargh, stop calling the Dutch character ij (U+0133, capital U+0132) a dotted y (U+00FF).

      One of the main origins of the Dutch letter ij is the double-i, of which the last i was written with extra length. You can find examples of ij and iij in old handwritings for numbering pages (Roman numbers 2 and 3). In a word like "bijzonder" the "ij" still has the "long-i" sound.

      In old Dutch handwriting, the ij-ligature and the y and the dotted y were freely mixed. This resulted in many spelling variations of the same name, for example Bruin, Bruyn and Bruijn. In Dutch phonebooks, Bruyn and Bruijn are sorted together. An opinion: The Dutch "letter" IJ

    10. Re:Another punny name by aug24 · · Score: 1

      My point was that it didn't used to be written ij but y umlaut... it's not two letters it's one. It was a comment about a misspelling of Geijin for Geijn for fuck's sake.

      God, geeks: determined to find an argument where none exists.

      J.

      --
      You're only jealous cos the little penguins are talking to me.
    11. Re:Another punny name by aug24 · · Score: 1

      Eh? Why the hysteria? You say yourself they were/are interchangeable.

      FWIW I used to live in the Netherlands and speak a bit of Dutch (much less these days). I was *trying* to explain why the misspelling was obvious - it's not i,j it's 'ij' thus it was clearly a typo. And I find it hard to understand why you can call it a dotted y but I can't call it a y with an umlaut!

      J.

      --
      You're only jealous cos the little penguins are talking to me.
    12. Re:Another punny name by Dr.Ruud · · Score: 1

      Sorry, but I don't know which hysteria you mean, and where you read that I say that "they" are interchangeable.

      You wrote "the ij is originally a y with an umlaut" which is not true. Not because the dots on the U+00FF aren't an umlaut (which they aren't, functionally they aren't a diaeresis either), but because the origin of the Dutch letter 'ij' is otherwise.

      The U+00FF Y DIAERESIS (dotted-y) is used in French names and in some other languages, but is erroneous for Dutch. The dots on the dotted-y are not an umlaut (like in Mann/Männer, compare also mouse/mice) or a functional diaeresis (like in coöperate, naïve, preëmptive, reënact, Chloë, Zoë), they are diacritical marks to show that it is a different letter. More on Umlaut

      In old Dutch handwriting (about 16th century) you will find the mix I mentioned, such as a shape that looks a bit like the U+00FF dotted-y, but it shouldn't be represented by that.

      In contemporary handwriting you often see a shape like a lowly connected i-j, with a dot on top of each of the two verticals. Just like a handwritten 'g' can look like an 'a' with a descender, a handwritten 'ij' can look like a 'u' with a descender (with or without dots).

      The Russian character that when printed looks like 'bI' is often written with a shape like 'y'. That also doesn't mean that they are interchangeable.

    13. Re:Another punny name by aug24 · · Score: 1

      Bloody hell, I was trying to explain a spelling mistake that only makes sense if you know that it is one letter. That letter was and is written as a y with two dots by lots of Dutch people, dead and alive, and has only recently been written as i-j. In Afrikaans it still is a y!

      If all you are really complaining about is that those two dots aren't technically an umlaut, and you would have rather I said "originally a y with two dots over it" then you have waaaay too much time on your hands. My description was meant to inform, not to function as a primer for the history of Dutch typesetting!

      Justin.

      --
      You're only jealous cos the little penguins are talking to me.
    14. Re:Another punny name by Dr.Ruud · · Score: 1

      You made a statement that was a cliché error so you shouldn't be surprised to get a reaction that points to better information. I won't go into your wrong assumptions again, new and repeated ones, because there seems to be no end to them.

    15. Re:Another punny name by Dahan · · Score: 0

      No, it used to be written ij, and it still is. Which is why the capital version is IJ, not Y with an umlaut.

  75. That's great if your language supports it by Anonymous Coward · · Score: 0

    Unfortunately, some languages, particularly older ones still in use today, do not.

  76. Re:If true... by SatanicPuppy · · Score: 1

    Eh. If that was true, then you could use "if(true)" everywhere you use goto, and there would be no difference.

    I disagree with the brain statement as well. There are very few neural functions that have no boundary conditions.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
  77. Re:If true... by SatanicPuppy · · Score: 1

    That's not really a goto...it's just a conditional. If--->then--->else

    A goto is like a derailed thought process. It would be like having a disjoint right in the middle of a sentence telling you to go farther along and do some unrelated thing for a minute, then jerking you back to what you were doing in the first place with another goto statement.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
  78. Re:goto is obsolete by Anonymous Coward · · Score: 0

    This is all well and good, but... is the guy's name actually "Goto"? And if so... does he actually use goto statements, or is that just implied to make the article title more of a hook?

  79. Story redundant? by jejones · · Score: 2, Funny

    After all, it was Donald Knuth himself who, in "Structured Programming with goto Statements" (Computing Surveys, sometime in 1974), wrote "At the [year] IFIPS Conference, I was introduced to Dr. Eiichi Goto, who cheerfully complained that he was always being eliminated."

    (Apologies for errors, as my issues of CS are in storage and I'm doing this from memory.)

  80. Re:If true... by SatanicPuppy · · Score: 5, Funny

    My favorite ever comment was, "If I ever saw this in the real world, I'd fire you" attached to an "A" test paper with a programming question on it I'd managed to reduce to one line of nearly incomprehensible recursion.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
  81. Re:goto is obsolete by Anonymous Coward · · Score: 1, Informative

    is the guy's name actually "Goto"?

    Yes

    And if so... does he actually use goto statements

    The article doesn't speak of goto statements whatsoever.

  82. Re:goto is obsolete by munehiro · · Score: 2, Informative

    Yes, functions impose overhead. however:

    - if your function is small enough and your compiler smart enough, it can inline the routine, removing overhead preserving readability

    - nobody can say where the time-critical code is without profiling. Most of the (fortran) code I handle spends 80% of the time zeroing arrays. There's not so much to optimize in this procedure, and optimizing the remaining 20% by filling the code with gotos is only a waste of time

    - if the algorithm is slow, optimize. If it's still slow, change algorithm.

    - last but not least. If you optimize the code to save some hour of computational cost but you obtain code which needs an additional month to debug, you are doomed to have a very bad time.

    --
    -- "If A equals success, then the formula is A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." - Einstein
  83. Re:Duh! by Anonymous Coward · · Score: 0

    Marvelous insight, Turing! Next time try reading something other than the headline before you post.

  84. Re:If true... by Anonymous Coward · · Score: 0

    Actually it is goto. if (no_need_to_attach_to_wall) goto step5;

  85. Re:If true... by SatanicPuppy · · Score: 1

    No, but they still work within boundary contructs, which is the point of a logical operator. While loops don't randomly disregard the truth value of their repeat condition, nor do For loops. But goto statements do, which breaks the big rule of logical operators...the truth value of the premise must be preserved.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
  86. Re:If true... by scheming+daemons · · Score: 5, Funny
    Of course GOTO is logical in real life. I experience this all the time:

    If wife has headache, GOTO sleep

    If boss is on vacation, GOTO strip bar for long lunch

    If in-laws are coming over, GOTO work and pretend there is a critical problem that requires your presence all night

    If technical conference is in Vegas, GOTO it

    loads of examples.

    If work is boring, GOTO slashdot to kill an hour or two

    --
    "I have as much authority as the pope, I just
    don't have as many people who believe it" - George Carlin

  87. in assembly by freejamesbrown · · Score: 1

    goto similar statements BRA,BEQ,BLT,BGT,etc are standard biz. you survive. you just gotta be diligent with how you arrange your assembly and maintain a style. (and not use assembly when it's possible.)

    but all my EE microprocessor type classes relied on such things...
    m.

    1. Re:in assembly by Anonymous Coward · · Score: 0

      If CPUs have BRAs, then can we deduce that they're all female?

      Thus, we can in fact deduce that all computer geeks DO have girlfriends.

    2. Re:in assembly by Anonymous Coward · · Score: 0

      I guess I'm okay with that.

      Most CPUs have the unconditional branch instruction "BRA" (Branch Result Always) but did you know that a few of the old 8 bit CPUs also have a "SEX" instruction? For the Motorola 6809 "SEX" is Sign EXtend accumulator B into A. (Prepares the two 8 bit accumulators for a 16 bit operation.) The RCA 1802 has a SEt X register "SEX" instruction. The Intel 8048 microcontroller is the adventurous type with its logic operations "ORL" (logical or) and "ANL" (logical and)

      The traditional Motorola CPUs and DSPs (68xx 68xxx 56xxx) are my personal favorites. The Coldfire is close enough to a modernized 68k that I accept the 5xxx series too...

  88. for the pun? (yes) by sita · · Score: 2, Informative

    Ever get the feeling someone wrote an article merely for the pun?

    There's of course the famous Alpher-Bethe-Gamow paper: http://en.wikipedia.org/wiki/Alpher-Bethe-Gamow_pa per

  89. Re:GOTO Considered Harmful since at least 1968 by Carthag · · Score: 1

    Just a quick question, why not do like this?

    for (i = 0; i < 100; i++) {
        for (j = 0; j < 100; j++) {
            if (sc[i][j] == ch) goto DONE;
        }
    }
    FAIL:
    ...
    DONE:
    ...

  90. Re:GOTO Considered Harmful since at least 1968 by McPolu · · Score: 1

    Hum... Both blocks are wrong (for me). I prefer:

    bool bSentinel = false;
    for (i = 0; i < 100 && !bSentinel; i++) {
      for (j = 0; j < 100 && !bSentinel; j++) {
        if (sc[i][j] == ch) {
          //Do something useful here
          bSentinel= true;
        }
      }

  91. The true question by Juiblex · · Score: 1

    But the true question that the article doesn't answer is:

    Does Mr. GOTO use GOTO statements to optimize it?

  92. I love this comment by Anonymous Coward · · Score: 0

    From: Linus Torvalds
    Subject: Re: any chance of 2.6.0-test*?
    Date: Sun, 12 Jan 2003 12:22:26 -0800 (PST)

    On Sun, 12 Jan 2003, Rob Wilkens wrote:
    >
    > However, I have always been taught, and have always believed that
    > "goto"s are inherently evil. They are the creators of spaghetti code

    No, you've been brainwashed by CS people who thought that Niklaus Wirth actually knew what he was talking about. He didn't. He doesn't have a frigging clue.
    =====

    This shows that Linus uses his common sense instead of blindly believing urban myths like "goto is always evil" and "x86 CPUs sucks".

  93. Well Done Slashdotters by Linker3000 · · Score: 4, Insightful

    We have given birth to a new acronym: RPFH Read Past the F**king Headline.

    --
    AT&ROFLMAO
  94. Goto considered harmful... by bullitB · · Score: 1

    ...to CPU manufacturers.

    How are they supposed to sell faster chips when he can make code run faster on them?

  95. Got the feeling? by Big+Nothing · · Score: 1

    "Ever get the feeling someone wrote an article merely for the pun?"

    Here on slashdot, I get that feeling all the time...

    --
    SIG: TAKE OFF EVERY 'CAPTAIN'!!
  96. Re:If true... by ObsessiveMathsFreak · · Score: 0, Offtopic

    I can bet you most universities don't even teach "goto" logic and if they said anything about it, it was: don't use GOTO statements.

    I was told this, unconditionally. I was told why as well, and had the matter illustrated with a mere 12 line example of horrific readability. I still use them though, when the call of the dark side is just too strong for me to resist.

    --
    May the Maths Be with you!
  97. Re:If true... by leonmergen · · Score: 1

    So, if Goto is so unlogical, how would you implement

    int i;
    for ( i = 0; i < 10; ++i ) { }

    without a goto statement ? I challenge you... :)

    --
    - Leon Mergen
    http://www.solatis.com
  98. Humor is wasted on you by js3 · · Score: 1

    don't be so anal retentive. everyone knows it's a pun, it doesn't mean discussing goto is offtopic

    --
    did you forget to take your meds?
  99. Re:If true... by Anonymous Coward · · Score: 0

    Say, dumbass, did you ever see how the program counter works in a CPU? It's all about skipping to the next step, unconditionally. What are you, retarded?

  100. Good for Mr. Goto by mr_rattles · · Score: 1

    I'm glad there are still people out there who realize that there is a time and place where hand optimizing code is actually beneficial. Regardless of which language it's not difficult to write inefficient code if you aren't careful (or even if you are and just having one of those days) and compilers don't always do a perfect job either.

  101. He has also commented that ... by jc42 · · Score: 1

    people are always trying to eliminate him.

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  102. Re:goto is obsolete by 91degrees · · Score: 1

    When you start anthropomorphising code, it's probably time to take a break from computers for a bit...

  103. Examples of Mr. Goto's code in practice. by Bob_Geldof · · Score: 0

    Robert vand de Geijn, a collegue of Mr. Goto's at the University of Texas (my alma mater) came to give a seminar talk to us grad students at the University of Washington Applied Mathematics Department last school year. He was talking about using a new language to program on supercomputers. He showed us slides of how his code stacked up with the state of the art MPI code. In his analysis he also showed off Goto's BLAS. One of the issues with a BLAS is that if the size of your matrices and vectors do not line up well the cache size you will spend a considerable amount of time fetching data from memory. This causes periodic dips in performance when compared to matrix size. GOTOblas significantly improves performance in the regard. This guy GOTO is insanely good at what he does. And quit trying to be funny with your pedantic goto jokes.

    --
    887321 = 337*2633
  104. Re:If true... by hazem · · Score: 1

    Then most processors work with derailed processes.

    It might be nice in a high level language to do things like switch, if..then..else, but at the core of it, the processor is just doing a comparison followed by a "jump if equal", "jump if not equal", "jump if greater than", etc, and finally just a "jump".

    In every case, jump = goto.

    The if..then..else/switch statements are just high level abstractions that lead to the very thing you say is a derailed thought process - jumps/gotos.

    Of course, I prefer nice structures, with functions and all, but don't forget what it really means deep inside the computer.

    As for a sentence, it's more like you're reading how to react to a bomb in your office and you get to "if the timer reads less than one minute, then run like hell and get out of here". It's pretty much a one-way goto, and quite practical.

  105. One note: by sammy+baby · · Score: 1

    I counted at least a dozen, and that's when there were only 60 comments in the story. I found that funny.

    And, for the record:

    1. Whining about missing the joke.
    2. Explaining a joke about missing the joke.
    3. Making a joke about missing the joke.

    I was guilty of 3, and am now also guilty of 2, but have not yet been guilty of 1. I think.

  106. Re:The Fastest Code of All by Cutterman · · Score: 1

    Label not found

  107. Re:If true... by jcnnghm · · Score: 1

    A fully functional web server written in Perl?

    --
    You don't make the poor richer by making the rich poorer. - Winston Churchill
  108. BLAS is very helpful for Linpack by dlapine · · Score: 1
    Just to be clear, Linpack is the code that is used as the basis for top500 runs. If you want to get a decent rating, your cluster must be able to run Linpack well. BLAS helps optimize the score the cluster can achieve.

    We use BLAS for most of our Linpack runs, as it is the fastest set of generic libraries for the purpose. And you can ignore the complexity of coding for a P4, when you consider how much fun it is to code for Itanium, and to do it correctly.

    --
    The Internet has no garbage collection
    1. Re:BLAS is very helpful for Linpack by joib · · Score: 1


      We use BLAS for most of our Linpack runs, as it is the fastest set of generic libraries for the purpose.


      BLAS is an API, with multiple implementations, of which the GOTO BLAS is one. Other implementations are e.g. ATLAS, ESSL, ACML and MKL and of course the reference implementation on netlib.

  109. Libgoto is fast but not open-source by poszi · · Score: 4, Insightful
    Maybe I should not complain because the guy did a great job and his library is available free of charge but I hesitate to use this library because it is closed-source. I benchmarked it and found it fast and started to use it in my scientific codes. I once found a strange problem in a parallel code I was developing. The program crashed for one specific system I was calculating. It was something weird because it worked for many other systems I tested before. I spent a lot of time trying to find the bug in my program when finally I replaced libgoto with standard blas and the problem disapeared. I knew that the crash was when entering blas but I thought it is because I messed with the arrays that are used as parameters. If libgoto were open-source, I would be able to have a version with debugging info compiled and debug the program and the library. I would probably not fix the bug but I would likely figure out more quickly the problem is in the library and not in my code. After I had known the problem is in libgoto, I dowloaded a new version of libgoto and it worked so the bug has been fixed. There is no changelog on libgoto web page so I don't know what was the problem and how it affacted my previous caclulations.

    Atlas is open-source and is a pretty good alternative. It is only a few percent slower than libgoto in most cases.

    --

    Save the bandwidth. Don't use sigs!

    1. Re:Libgoto is fast but not open-source by ufnoise · · Score: 5, Informative

      From the article: Some programmers have suggested that Mr. Goto has not joined the open-source movement because he wants to protect his secrets and strategies from competitors. That is not so, he said recently, noting that the Goto BLAS software is freely available for noncommercial use. And he said he was preparing an open-source version.

    2. Re:Libgoto is fast but not open-source by Kazoo+the+Clown · · Score: 1

      I would think the source would necessarily be in Assembler, as otherwise the differences in various compilers and compiler optimizations could undermine his carefully coded enhancements.
      At the very least he may have to keep close control on how it is compiled if he were using a higher level language compiler. Also, he may be using a macro assembler of his own choosing that isn't readily available, and presumably a variety of assemblers if he has versions for different platforms.


      Consequently, it does not seem particularly surprising that the source is not available, even if you had it you might not be able to do much with it. Also, I would think that an open source version of his library in C or something might not perform quite as well, and therefore those who want to squeeze out the last ounce of performance might still prefer the library as constructed by him.



      --

    3. Re:Libgoto is fast but not open-source by sl3xd · · Score: 1

      For me, the key thing is it's free for noncommercial use. If it's being used commercially, though, it's an entirely different ball game. At least with GPL and BSD code, you have the freedom to use it in a corporate setting. I certainly know this is why I don't (and can't) use libgoto.

      AMD's Core Math Libraries are at least free beer, even to corporate customers; and the performance difference (at least on Linpack) is virtually nil. And since both are closed source -- I'll take the free beer.

      My employer donates a sizeable amount of R&D and bugfixes to GPL'd code (including the Linux kernel); we release the code and/or fixes as soon as it's been validated. GPL and BSD code gives us the freedom to use and improve the softare we use. That freedom counts for a lot more than the free beer aspect of free software, but the cost is certainly a factor.

      Mr. Goto only recently (Sep-Oct, IIRC) changed the license so even the use of his library required either non-commercial use or a license to be purchased. Previously we could at least use his library to boost our linpack numbers, then delete libgoto and software compiled against it; now we simply ignore libgoto entirely, and turn to his competition instead.

      The thing Mr. Goto seems to discount is that his competitors know how to read raw machine code just fine; this is in no small part because two of his biggest competitors (Intel's MKL and AMD's ACML) are from the same corporations which design the chips on which his code runs.

      There's money to be made in it, and both AMD and Intel will reverse-engineer his (and each other's) techniques. libgoto is a single library, with rather well-defined, discrete, component functions. Reverse-engineering library that is so thoroughly defined as BLAS isn't trivial, but it is also quite possible. You already know the inputs and the outputs, you know what mathematically happens in the middle -- after that even machine code becomes fairly simple to read.

      --
      -- Sometimes you have to turn the lights off in order to see.
  110. And the point is... by plopez · · Score: 1

    Maintainability. Go to type statements can make code ugly and unmaintainable fast (not that not using them insures maintainable code, coding styles and best practices are needed).

    The entire point about production code is that it will be used by some else and maintained by someone else. Maintaining code can be much more expensive than initial development. Anything that reduces maintenence costs usually takes precedence over performance, annoyance of the initial programmer(s) and cpu time.

    High end customized scientific computing is an exception. Speed is of the utmost importance and grad student programmers work cheap.

    --
    putting the 'B' in LGBTQ+
    1. Re:And the point is... by eric76 · · Score: 1
      The entire point about production code is that it will be used by some else and maintained by someone else. Maintaining code can be much more expensive than initial development. Anything that reduces maintenence costs usually takes precedence over performance, annoyance of the initial programmer(s) and cpu time.

      Right.

      And in some situations, the intelligent use of goto statements can result in code that is substantially cleaner and easier to maintain.

  111. May Be The Fastest - But Is The Answer Correct! by Anonymous Coward · · Score: 0

    Mr. Goto's library may indeed be the fastest available, but a more important question in numerical methods is whether his library produces correct results. Even simple mathematical calculations are fraught with peril when done with finite arithmetic on a computer. Until you've taken a numerical analysis course from an experienced numerical analyst, you cannot appreciate this point enough.

  112. Nitpick by bsd4me · · Score: 1

    Programming languages aren't based on formal logic

    Imperative languages aren't based on formal logic. Functional programming languages, logic programming languages, and other declarative languages are deeply rooted in formal logic. While some tasks are more difficult in these languages, being able to reason about a program is really beneficial in a lot of situations.

    --

    (S(SKK)(SKK))(S(SKK)(SKK))

    1. Re:Nitpick by Random832 · · Score: 1

      I almost went back and added a note about functional programming. Still, my objection to GPP's claim that functional programming is more natural for human thought stands.

      --
      We've secretly replaced Slashdot with new Folgers Crystals - let's see if it notices.
    2. Re:Nitpick by Random832 · · Score: 1

      PS - consider what's easier for most people? solving a math problem, or following a recipe?

      --
      We've secretly replaced Slashdot with new Folgers Crystals - let's see if it notices.
    3. Re:Nitpick by poopdeville · · Score: 1

      Depends... are you baking a cake or solving a math problem?

      --
      After all, I am strangely colored.
  113. Idiots by Anonymous Coward · · Score: 0

    Read TFA and dig a bit, then you will see...

    >>Actually, GOTO is my last name and does not mean "go to." (Nor is it pronounced "go to"; the correct pronunciation of my name is more like "goat-toe.")

    Good God! How many of you slashbot jerks even bother to sniff the article before launching into a tirade about structured programming etc.

    Dumb asses, the bunch of you!

  114. Re:If true... by tawhaki · · Score: 1

    int i;
    i = 0; i = 1;
    i = 2; i = 3;
    i = 4; i = 5;
    i = 6; i = 7;
    i = 8; i = 9;

  115. If you can't understand his coding... by coinreturn · · Score: 1

    ...then you're in Goto Hell.

  116. Re:GOTO Considered Harmful since at least 1968 by hackstraw · · Score: 1

    I had a boss that was allergic to gotos. It pissed me off, but oh well.

    And as the parent said, yes, they lead to more readable and efficient code. They are used in low level code like the Linux kernel and OpenSSL extensively, and when I do system level programming I use them too.

    I use them when "the shit hits the fan", and I need to clean up my memory or whatever, and return from the function with an error code.

    That same boss suggested code like the first one in the above example, or the infamous do { stuff; } while (0); with break statements. Well, break does not work well with nested loops now does it?

    I think that the allergy to gotos came from the BASIC days where the goto was a line number and not a label, and the gotos then were equivalent to a longjump(), meaning that the jump could go anywhere in the code. C gotos can only go to a label within a function (I guess. If this is wrong, I've never seen anybody use it otherwise, nor should they).

    Aside, from basic C style exception handling, I don't see a need to use a goto anymore than to use a switch statement for one or two cases (which is almost the same as a goto).

    Also, Perl has good uses for goto, but its a little different. You can label individual loops with, uh, a label, and you can say stuff like last outer_loop or whatever you want.

    Trust me, I've seen tons of crappy code that never used a goto, and I've seen tons of good code that have used goto. It does have its uses, and I will use it until something better is added to the C language.

  117. Re:Duh! by Anonymous Coward · · Score: 0

    Actually, unless the compiler optimizes away your goto by removing it and tacking the code that it was supposed to jump to right where the goto was, the goto will result in slower code because your fancy superscalar processor will not be able to fetch across multiple instruction cache lines.

  118. Why do the zealots always have to chime in by leabre · · Score: 0, Redundant

    From the article, "Recently there has been a quiet controversy around the Goto BLAS because Mr. Goto has been slow to offer his work as open-source software, the free model of software distribution.

    Some programmers have suggested that Mr. Goto has not joined the open-source movement because he wants to protect his secrets and strategies from competitors."


    Why does it matter? For a talent as unique as his, and as competitive as it is (according to the article), why is it so wrong to keep it proprietary and actually, uck, profit from his work? Why should there be a contraversy? Here's a thought, the zealots should go immitate him like they do every other commercial venture if its so important to them.

    Anyway, from the article, he says that its not so and there will be an open source release at some point in the future. In anycase, the open source world isn't entitled anything and its shame that they should stirr up tension just because their savory jaws are dripping.

    Good grief.

    Thanks, Leabre

    1. Re:Why do the zealots always have to chime in by haruchai · · Score: 1

      Personally, I have no problem with a smart guy making money. But I do also believe in giving back. From the article: Although he was not formally trained in computer or software design, he perfected his craft by learning from programmers on an Internet mailing list focusing on the Linux operating system for the Alpha chip. His curiosity quickly became a passion that he pursued in his free time and during his twice daily two-hour train commute between his job in Tokyo and his home in Kanagawa Prefecture So, while it's clear that his talent is God-given and his hard work is to his own credit, he cut his teeth on open source - and that was a LONG time ago. So, I would think that a little reciprocity is overdue.

      --
      Pain is merely failure leaving the body
  119. Re:GOTO Considered Harmful since at least 1968 by david.given · · Score: 1

    I've found myself, somewhat to my horror, using the following idiom in C++ quite a lot:

    function()
    {
        if (false)
        {
        error:
            printf("barf!\n");
            return failure;
        }

        Object1 o1();
        if (o.failed())
            goto error;

        Object2 o2();
        if (o.failed())
            goto error; ...etc, several times...
        return success;
    }

    The jump target goes at the beginning, rather than the end, because C++ won't let you jump over a constructor. Previously, I was using nested scopes, which led to messy, overly indented code. This way at least produces cleaner code, although that 'if (false)' is a little startling... maybe I should consider wrapping it in a macro for readability's sake.

  120. Next Headline by szrachen · · Score: 1

    Mr. Case dramatically changes the way Mr. Goto's code looks. Mr. Goto sues...

  121. Re:If true... by jc42 · · Score: 1

    Your argument against Goto is even less logical. Goto is a conditional jump, ...

    No; Goto is a Japanese programmer.

    Actually, it's the name of several Japanese programmers. Puns on their names go way back, to the weeks after Dijkstra's famous paper.

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  122. Bypassing NYT registration by Anonymous Coward · · Score: 0

    Most /.ers should already know this, but you can bypass the New York Times' (free) registration by grabbing a username and password from BugMeNot.

  123. Re:goto is obsolete by mrchaotica · · Score: 1
    You gave some good advice, but you got this part backwards:
    if the algorithm is slow, optimize. If it's still slow, change algorithm.
    Get the order of magnitude optimization first, then quibble about individual instructions (i.e. make a dirty hack) only if you really, really need to.
    --

    "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

  124. Re:According to Soviet Russia... by Marc2k · · Score: 0

    Goto considers harmful YOU.

    --
    --- What
  125. Re:If true... by jc42 · · Score: 1

    Obviously,
        what
            you should have done
            is insert
                lots of
                    line feeds
                and tabs
                into
                    that one line.

        Then it would have been a shining example of highly-structured code, and obviously much more readable.

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  126. Standard disclaimer by Valdrax · · Score: 2, Informative

    It's just two syllables... the first, "go", is pronounced like the "go" in gordon, not like the English word "go". The second, "to", is not like the English word "to", it is pronounced like the "to" in "tornado". Try saying "gohr-tohr". *

    * Note: Pronunciation instruction may only apply if you live in the city of Boston. People living in other localities may need to contact the appropriate authorities for further instruction.

    --
    If it's for-profit but free, you're not the customer -- you're the product (e.g., the Slashdot Beta's "audience").
  127. Re:If true... by jcupitt65 · · Score: 1

    void f( int i ) { if( i < 10 ) f( i + 1 ); }
    f( 0 );

  128. Re:GOTO Considered Harmful since at least 1968 by jc42 · · Score: 1

    Indeed; I use this approach for handling errors in a lot of routines. However, to please the anti-goto crowd, I usually define two macros:

    #define Done goto done
    #define Fail goto fail

    You'd be surprised how many people accept the resulting code as properly structured, when they vociferously reject any code that contains the "goto" token. By moving the goto out to a .h file, you magically create goto-less code.

    People can be really dumb sometimes.

    And I hope they never learn anything about machine code. Their whole world would shatter into little unstructured chunks.

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  129. Re:The Fastest Code of All by Anonymous Coward · · Score: 0

    1 NOP

  130. God damn idiots. by Jerk+City+Troll · · Score: 0, Flamebait

    Look, I usually try not to lose my cool on this, but 90% of the comments here indicate that people think the key to this performance increase is the use of gotos in code. No, you fucking idiots. "Goto", in this case, is Goto-san, a Japanese person (pronounced "Goh-toh" with long o's, not "goh-tu"). The use of gotos in human-written (and read) code is always bad and nowhere is that actually suggested. Do any of you nitwits even understand what a pun is?

    1. Re:God damn idiots. by Anonymous Coward · · Score: 0

      Most Gaijin are baka, this is fact.

      You then have the problem of British/American pronouciations, you can not even use key words as examples, it is a never ending battle you face.

    2. Re:God damn idiots. by slo_learner · · Score: 1

      Take a break and go lay down man. Using optimized code which might use goto instead of a different conditional is an entirely likely scenario. People are just having fun and chatting about this crap. It's entertainment. If you don't like it, go lock yourself in the closet with your linear algebra text and leave us alone.

    3. Re:God damn idiots. by eric76 · · Score: 1

      First of all, we are quite cognizant that the article was about a man named Goto, not about structured programming. But because of the name, it is a very short step to also discussing the use of goto's in code.

      Second, the use of goto's in code is considered bad only by those people who have been indoctrinated for years with that idea and who have never learned to question such indoctrinated views.

      By the way, to what pun are you referring?

  131. You could spend 6 months optimizing... by Darius+Jedburgh · · Score: 1
    ...the crap on your code to get the speed from 1.5 trillion operations per second to 2 trillion. Or if you're smart you can sit on the beach drinking cocktails for 6 months and wait for the next generation of CPUs to come out.

    If a task requires N operations then it takes time O(log N) to execute because of Moore's law. It hardly seems worthwhile to make heroic efforts to incrementally optimize your code, especially when there is a pretty clear cap on the maximum possible efficiency you can squeeze out relative to processor speeds.

    1. Re:You could spend 6 months optimizing... by Frumious+Wombat · · Score: 1

      Do you *do* numerical computing for a living? I've had a properly optimized math library cut my run-time in half, on 1-2 week runs. The issue becomes, when your best algorithm runs in O(N^7), then time spent optimizing your math libraries to cut the prefactors down as far as possible actually matter. You're still limited to around 10 atoms (I'm doing coupled-cluster), but now you get results back in a usable amount of time. More importantly, you get out of the way of the other users of the supercomputer.

      You rely as much as possible on better compilers, faster procs, and better algorithms, but at some point you have to make sure that basic operations done billions of times are running as quickly as possible.

      --
      the more accurate the calculations became, the more the concepts tended to vanish into thin air. R. S. Mulliken
    2. Re:You could spend 6 months optimizing... by joib · · Score: 1

      ..the crap on your code to get the speed from 1.5 trillion operations per second to 2 trillion. Or if you're smart you can sit on the beach drinking cocktails for 6 months and wait for the next generation of CPUs to come out.


      Yes, this is one reason why optimization usually doesn't matter. It's also entirely irrelevant for this discussion. What we have here is an implementation the the BLAS api, which ultimately is the thing that (wild guess) about 50 % of all supercomputer cycles in the world are spent doing. As these supercomputers are very expensive, and users use them because they need maximum performance, it makes sense economically to spend quite some time on an optimized BLAS library.

    3. Re:You could spend 6 months optimizing... by Locke2005 · · Score: 1

      Or if you're smart you can sit on the beach drinking cocktails for 6 months and wait for the next generation of CPUs to come out. Unless of course you're trying to get on the top 500 supercomputers list, in which case you probably are not going to throw away those 32768 CPUs and buy new ones every six months, are you? The people who really need a hand-optimized BLAS library are the ones running massively parallel computers, not a single desktop PC.

      --
      I've abandoned my search for truth; now I'm just looking for some useful delusions.
    4. Re:You could spend 6 months optimizing... by Lars+T. · · Score: 1

      Assuming that the optimisations will not make your code faster on the next generation of CPUs.

      --

      Lars T.

      To the guy who modded me down from perfect to terrible Karma - Apple haters still suck

    5. Re:You could spend 6 months optimizing... by Anonymous Coward · · Score: 0

      Hahahahahaha... I was scanning through the comments looking for this response. You morons never let me down!

    6. Re:You could spend 6 months optimizing... by g-san · · Score: 1

      Gonna have to call Dumbass on this one.

      The guys who figure this shit out do get to sit on the beach drinking cocktails, with the umbrella and the pineapple slice, and their yacht is anchored just off shore.

      Meanwhile, you are sitting in meetings discussing late and overbudget computing projects because you lose 60 days a year from forklift upgrades of the data center...

  132. 200+ comments and I can't believe they missed this by Deanasc · · Score: 1

    10 Print"Slashdot sucks";
    20 Goto 10

    --
    I've hit Karma 50 and gotten a Score:5, Troll... I win!
  133. Much faster.... by Anonymous Coward · · Score: 0

    _main:
          ret

  134. Re:goto is obsolete by munehiro · · Score: 1

    Get the order of magnitude optimization first, then quibble about individual instructions (i.e. make a dirty hack) only if you really, really need to.

    Exactly, but quibbling is almost a waste of time if you can go down further by changing the algorithm... I mean, it's a waste of time trying to optimize the code for a bubblesort when you can implement a quicksort.

    --
    -- "If A equals success, then the formula is A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." - Einstein
  135. Re:GOTO Considered Harmful since at least 1968 by Anonymous Coward · · Score: 0

    I disagree. I split out the loops into a separate function (or use exception handling if available.)

    fn1()
    {
        if (fn2()==0)
        {
            good stuff
        }
        else
        {
            bad stuff
        }
    }
    int fn2()
    {
        for (i = 0; i < 100; i++) {
            for (j = 0; j < 100; j++) {
                if (sc[i][j] == ch) return 0;
            }
        }
        return -1;
    }

  136. Read The Freaking BLURB! by Anonymous Coward · · Score: 1, Insightful

    Speaking of compiler optimizations, if simply replacing control structures with goto made the function 30% faster, then either the compiler truly sucks, or the previous implementation was something horrible.

    I don't mean to pick on you in particular, since half of the comments in this article are equally retarded, but what the hell? I know Slashdot's "early posts get modded up more" system discourages Reading The Fine Article, but are there really this many people who can't spare enough time to read the front page blurb before commenting?

    Goto BLAS is not a BLAS implementation which replaces control structures with goto statements - Goto BLAS is a BLAS implementation written by a man named Kazushige Goto! Just in case anyone didn't catch that, Hemos even points it out again with "Ever get the feeling someone wrote an article merely for the pun?"

    There's still at least ten Slashdot users here who actually understand the subject of conversation. If you're not one of them, would you please just read their comments, try to catch up, and stay silent until you're sure you aren't the "noise" in "signal to noise ratio"?

  137. Re:If true... by KarmaMB84 · · Score: 2, Funny

    In CS courses below 300, we were told that goto was evil and should NEVER be used. They didn't even teach its use. In 300+ courses, we were given examples of why goto is sometimes the best approach producing easier to understand code that was also faster. In fact, a lot of time was spent by professors that did real work deprogramming brainwashed students who were taught that global variables should never EVER be used, goto is Satan, dynamic memory is for terrorists and all kinds of god awful ideas.

    That is one of the problems with academia. There are too many Java hugging professors teaching the C/C++ courses and trying to push their own agenda. A Java loving professor completely deprived his students of an entire semester of C++ file/data structure instruction because of his Java pimping agenda. When the term project of "File and Data Structures in C and C++" is a Java project, you know there's a problem...

  138. But According to Knuth by DaveAtFraud · · Score: 1
    The GOTO can be used in structured code. Here's a link to his paper: Structure Programming with go to Statements.

    Yes, the original paper has goto as two words.

    --
    They that can give up essential liberty to obtain a little temporary safety deserve neither safety nor liberty.
    Ben
  139. Re:If true... by trmcdougle · · Score: 1

    Unfortunately for your argument most of those operations tend to be GOSUBs since you return from them!

  140. Optimization works! by Anonymous Coward · · Score: 0

    How many times have somebody posted "optimization isn't worth the effort" or "modern compilers make optimization obsolete" on slashdot? I am not sure where that lie got started, but that fallacy has spread far and wide among programmers and especially project managers. All of the best programmers I know with carefully optimize their code - by hand. Yes, actually using a debugger, and sometimes even paper and pencil! Frankly, it is the lazy programmers who are most likely to claim that optimization doesn't matter.

    1. Re:Optimization works! by rvbarthel · · Score: 1

      I had a similar experience recently. The code I was running was starting to stress my hardware. I had considered upgrading some of my gear until I had a more experienced guy looked at my code. He suggested I change the data structure I was using. I did it and got a 4x improvement in performance. My older hardware now performs better then ever!

  141. Kazushige's webpage about TBL performance by Anonymous Coward · · Score: 0

    From Kazushige Goto's webpage http://www.tacc.utexas.edu/~kgoto/#overview

    "During the last decade, a number of projects have pursued the high-performance implementation of matrix multiplication. Typically, these projects organize the computation around an "inner-kernel", C = trans(A) B + C, that keeps one of the operands in the L1 cache, while streaming parts of the other operands through that cache. Variants include approached that extend this principle to multiple levels of cache or that apply the same principle to the L2 cache while essentially ignoring the L1 cache. The purpose of the game is to optimally amortize the cost of moving data between memory layers.

    Our approach is fundamentally different. It starts by observing that for current generation architectures, much of the overhead comes from Translation Look-aside Buffer (TLB) table misses. While the importance of caches is also taken into consideration, it is the minimization of such TLB misses that drives the approach. The result is a novel approach that achieves highly competitive performance on broad spectrum of current high-performance architectures."

    So why have chip designers, software developers and academics been focused on impoving cache preformance (e.g. L1, L2, L3, ...) and not improving TLB and virtual memory performance?

  142. Re:Goto: The sordid story by Gnutte · · Score: 1

    are these guys serious? of course optimized code is uglier, nastier and usually faster than nicer looking ones.

    I think optimized code is very beautiful.

  143. Re:GOTO Considered Harmful since at least 1968 by TheSlashFrog · · Score: 1
    Real programmers know better:
    for (i = 0; i < 100; i++) {
      for (j = 0; j < 100; j++) {
        if (sc[i][j] == ch) {
          return DONE;
        }
      }
    }
    return FAIL;
    That's much more readable, about as fast code.
  144. Seppuku by Anonymous Coward · · Score: 0

    If only it were exceedingly popular in western culture and less popular in Japan.

  145. Re:goto is obsolete by mrchaotica · · Score: 1

    Yeah, that's what I said -- changing from bubblesort O(n^2) to quicksort O(n log n) would be an example of an order of magnitude optimization.

    --

    "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

  146. Welcome to continuations. by master_p · · Score: 1

    The functional programming community has been literally screaming for years that functional programming languages that have the tail call optimization/continuations can be much faster than programming languages that do not have it. Now here comes a guy that says 'goto' is faster. Of course it is faster, but it should be used within the proper abstraction, i.e. continuations, and not like 'goto 100' as it was in Basic.

    Basically much time is spent in C programs in unwinding the stack, whereas programs that use continuations execute a simple goto (i.e. a jump) to the continuation, reusing the available stack space. This can lead to better memory usage, especially in recursive algorithms, which means the swap file does not grow with thrown-away stack data.

    1. Re:Welcome to continuations. by Anonymous Coward · · Score: 0

      Hey bubba,

      how about first reading the article?

    2. Re:Welcome to continuations. by eric76 · · Score: 1

      The use of recursive functions can lead to some very cool solutions, but if you need optimization, it is often best to completely avoid recursive functions.

    3. Re:Welcome to continuations. by Riktov · · Score: 1

      The functional programming community has been literally screaming for years that functional programming languages that...

      Literally screaming for years, eh? Maybe that's why they get ignored.

  147. Re:GOTO Considered Harmful since at least 1968 by mrsbrisby · · Score: 1

    It's slower and less readable (consider if "Do something useful" is quite long)

  148. Agreed, and more by jd · · Score: 1
    Binaries are only available for only a very small number of platforms, but I need high-performance BLAS on a much wider range of systems, hence I can't use libgoto. "It might not be optimized for those platforms", you say. Well, having an optimized framework and the ability to add my own code would have solved that one.


    High-performance libraries are great, but if they are closed-source can only EVER be great in the most restrictive case possible, which is useless in non-standard or heterogeneous environments.


    For this reason, ATLAS is interesting to me. It's not as fast as it could be (by a long way), it doesn't support the full set of BLAS/LAPACK functions (which is crappy), it also doesn't provide optimizations on many chips that Linux will run on (doubly crappy) and it's a one-man project where the one man is massively overworked on the non-existant time available to maintain the project. On the other hand, it's Open Source (so I can add code I consider missing), it's Open Source (so I can compile on any platform I like) and it's Open Source (so I know the code will get some support from someone, for as long as it is in use).


    Where I need more speed, and DON'T have the time to make the necessary changes - well, I'm screwed, because there is bugger all in the way of good BLAS/LAPACK libraries for Broadcom's SB1 processor. Not even Broadcom support their own processors. Such is life.

    --
    It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
  149. Re:GOTO Considered Harmful since at least 1968 by mrsbrisby · · Score: 1

    If fn2() takes several arguments, you've done extra stack operations. Your exception handling code is also far away from the code that generated the exception.

    So it's slower and less readable...

  150. GOTO not slow by booch · · Score: 1

    OK, I know that the article is not about GOTO statements. However, I'd like to respond to everyone saying that GOTO statements are bad.

    The reason GOTO statements are bad is not speed. The reason GOTO is harmful is because it leads to spaghetti code, which confuses programmers. In pin-hole optimizations, GOTO can actually speed things up in many situations. And it's probably impossible on most architectures for your machine language not to have GOTO (jump) statements. In fact, there are architectures that have an explicit GOTO statement in every instruction.

    --
    Software sucks. Open Source sucks less.
    1. Re:GOTO not slow by p3d0 · · Score: 1

      First, it's "peephole" optimizations, not "pinhole" optimizations. Second, gotos disrupt pipelines, and are usually expensive. You say it can "actually speed things up in many situations". Well, yes, that's true of almost any instruction, so it's an information-free phrase.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    2. Re:GOTO not slow by eric76 · · Score: 1
      architectures that have an explicit GOTO statement in every instruction

      Modern architectures?

      The only one I'm familiar with was back in the early or mid 60s, I think, for using drums as memory devices.

      In those cases, each instruction contained the address of the next instruction. The program could then be optimized so that when the instruction was complete, the drum would be in the appropriate position to read the next instruction.

      In such a system, storing the instructions in sequential order on the drum would mean that most of the time, the CPU would have to wait for the drum to spin all the way around before the next instruction to be read.

      Has this been necessary in some more recent computer?

  151. Re:GOTO Considered Harmful since at least 1968 by mrsbrisby · · Score: 1

    That's fine, but I'd put "error:" after the return success. That way people aren't jumping backwards.

    Of course, with C++, you really should be using C++ exceptions (or you shouldn't be using C++... :) )

  152. Re:If true... by aevan · · Score: 1

    If book is boring GOTO last chapter. Say I have no appreciation for the 'finer classics of literature', but that's how I managed to read 'Tale of Two Cities' If paragraph is still describing door two sentances in, GOTO next paragraph. =P

  153. But still not as bad as Harry Deadlock. by Achoi77 · · Score: 1
    Worst. Coder. Ever.

    Trying to debug his stuff was hell!

  154. Re:GOTO Considered Harmful since at least 1968 by mrsbrisby · · Score: 1

    Real programmers know better than to do that.

    You've either duplicated finalization code (by putting it before each return), or performed it in the calling function which would mean additional stack operations).

    Your solution is either less readable or (much) slower.

    Real programmers know that goto has it's purpose and don't hide from good tools. If you can't use goto properly, that's fine- maybe in another 10-20 years of programming you'll feel comfortable enough with your skills to use it.

  155. Re:If true... by Shano · · Score: 1

    Switch statements in particular have exactly the same behaviour as a computed goto: the program flow jumps from the start of the block to some label in the middle, and continues from there. If you look at it that way, fall-through is an obvious consequence, and not just there to trap inexperienced (and some experienced) programmers.

    Of course, it's all kept in a single self-contained block, although there's no reason you can't nest them (actually, I'm not certain about that in C. I know I've done it in some other languages). But it's effectively a goto, nonetheless.

  156. Re:The Fastest Code of All by chickenmonger · · Score: 1

    Too bad someone beat you to the bunch in 1994, in the IOCCC contest. Plus, this program is self-reproducing, too. Runs about as fast as the OS will allow any program to run.

    http://www.ioccc.org/1994/Makefile
    http://www.ioccc.org/1994/smr.c
    http://www.ioccc.org/1994/smr.hint

  157. GOTO's.... by Anonymous Coward · · Score: 0

    I was always told using GOTO's was a sign of weakness......

  158. Welcome to RTFA by joib · · Score: 1

    TFA is about a guy whose surname is 'Goto'.

  159. Now, wait for the next (worst) pun by DrYak · · Score: 3, Funny

    Wait until you read in an interview about Mr. Kazushige Goto's favorite food.
    Italian.
    Pasta.
    Specially Spaghetti.

    [/me ducks and runs away....]

    --
    "Sufficiently advanced satire is indistinguishable from reality." - [Tips: 1DrYakQDKCQ6y52z6QbnkxHXAocMZJE61o ]
    1. Re:Now, wait for the next (worst) pun by StikyPad · · Score: 1

      That was definately not indistinguishable from reality. ;)

  160. Re:If true... by ObsessiveMathsFreak · · Score: 1

    In fact, a lot of time was spent by professors that did real work deprogramming brainwashed students who were taught that global variables should never EVER be used, goto is Satan, dynamic memory is for terrorists and all kinds of god awful ideas.

    I'm not so much against telling learner students not to use these things as I am against teaching learner students that these things even exist at all. All these techniques are advanced, and students should be comfortable wit hthe basics before they are even exposed to the tricky concepts. A lot of misuse of these language feature comes from people who don't really understand what they're for.

    --
    May the Maths Be with you!
  161. BEEP! by Artemis3 · · Score: 1

    SYNTAX ERROR: LINE 10

    --
    Artix
    Your Linux, your init.
    1. Re:BEEP! by Anonymous Coward · · Score: 0

      Please explain?
      No space between Print and "? That is usually allowed.
      Semicolon after the string? In the old days, that meant "no CRLF after printing this".

    2. Re:BEEP! by tao · · Score: 1

      The uppercase P in print. Same bug on line 20 with the uppercase G in goto.

  162. That professor is not very bright by 3770 · · Score: 1

    Amen!

    I'm so tired of people who say to _never_ use gotos. I understand why professors are saying this. The average computer science student often will use it in the wrong way. On average a class of computer science students will produce better code if they are told to never use gotos. But that doesn't mean that it never is good, only that the average programmer is a moron.

    Not using goto's are one of those mantras that was coined by someone who hadn't thought things through, that got popular and were taught to students without critical thinking by professors with no real life experience.

    I rarely use gotos (unless I'm coding in a language that doesn't support exceptions in which case it is a central part to how I centralize the cleaning up my stuff before returning an error code from my function) but I would be really pissed if it wasn't available when I really need it.

    --
    The Internet is full. Go Away!!!
  163. benchmarks? by loftwyr · · Score: 1

    I've been hearing a lot about Mr. Goto's code versus Atlas and ACML. Has anyone done a side by side benchmark to see who is best for all-round BLAS use?

  164. Computed goto by apankrat · · Score: 4, Interesting
    Not as helpful as computed goto

    Seriously. Computed goto is very useful for low-level
    optimizations in things like high-throughput ethernet
    drivers and such. It basically eliminates conditional
    checks in cases where the condition stays the same
    for a particular set of data. So instead of
    if (context->condition)
          foo(context);
    else
          bar(context);
    one would have
    /* one-time initialization */
    if (context->condition)
          context->jmp = &_foo;
    else
          context->jmp = &_bar;
     
    ..
     
    goto *context->jmp;
     
    for (;;)
    {
    _foo: foo(context); break;
    _bar: bar(context); break;
    }
    If the second part is executed in a loop, the savings of
    not making an IF comparison accumulate fairly quickly.
    --
    3.243F6A8885A308D313
    1. Re:Computed goto by ChadN · · Score: 3, Insightful

      Yuck! For this example, it'd be much clearer (to me), to simply initialize a function pointer to either foo or bar, and call that in a loop. I'd imagine it is just as fast. Jumping into loops can be clever, but is seriously non-intuitive, IMO.

      --
      "It's overkill, of course. But you can never have too much overkill." - Anonymous Slashdot Coward
    2. Re:Computed goto by apankrat · · Score: 1

      Well, that was just an example for illustrative purposes. Computed
      gotos are typically used for switch-case optimizations, where
      individual cases contain small blocks of inlined code rather than
      function calls. Wrapping each case into a function and manipulating
      function pointers IS an option, but the overhead of a function call
      will eat up all savings of not using the switch-case.

      I just thought of a good example outside of high-perf drivers. All
      Brainf*ck interpreters include a loop iterating over
      a command sequence and executing very simple commands in a
      switch-case style. Using computing goto's instead of a switch-case
      gives about 10-15% performance boost. And that's quite a lot for
      a non-algorithmic optimization.

      --
      3.243F6A8885A308D313
    3. Re:Computed goto by ChadN · · Score: 1

      "Yuck" again! :)

      Actually, I concede the validity of your point, and certainly I think it is important for programmers to understand the computed GOTO technique. Some languages, such as Fortran, support it directly.

      I personally feel it should always be used judiciously, and as least for C/C++, etc. probably not at all unless in the most extreme cases (ie. no other technique can be imagined). In your second example, above, I'd venture that either "inline" or macro (ab)use could come to the rescue; maybe, or maybe not. Some might say resorting to macros is exchanging the devil you don't know, for the devil you do...

      That said, I use goto's all the time in C (for error handling mainly, where it must be carefully maintained but is at least somewhat elegant and canonical), and almost NEVER in C++ (which mostly obviates it with another set of complex symantics). I'm glad "GOTO Statement Considered Harmful" has gotten some reconsideration.

      --
      "It's overkill, of course. But you can never have too much overkill." - Anonymous Slashdot Coward
  165. Re:goto is obsolete by Phatboy · · Score: 1
    my point is that a computer doesn't see things in the sense of functions

    You do realise that a function call most certainly doesn't translate into goto statements?

    There have been Jump To Subroutine instructions for longer than my knowledge of instruction sets goes back - it pushes the address of the instruction that should be executed following the execution of the function on the stack and jumps function (the address of which you give as a parameter).

    Likewise, there is a corresponding Return from Subroutine instruction which takes the address off the stack and jumps to it.

    The idea that functions are some sort of modern whimsical high-level construct is definately false, as is any idea that goto has ever been a good idea when you can use a function instead.

  166. Re:If true... by jc42 · · Score: 1

    int i = 11;

    (;-)

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  167. Re:GOTO Considered Harmful since at least 1968 by Anonymous Coward · · Score: 0

    Real programmers don't perform linear searches of 100x100 arrays when performance matters.

  168. Look at the asm output of your compiler sometime by fishbowl · · Score: 1

    Look at the asm output of your compiler sometime, and ponder how many algorithms
    end up with unconditional jumps. I can easily see how it might be possible to optimize away a stack operation here and a compare there by suggesting a jump in the right place, why not?

    Just because it's *possible* to get a performance improvement, doesn't make it a win in every situation, right?

    I'm sure the kind of mess Dijkstra was dealing with when he wrote the paper, was truly maddening. I'd be willing to bet that the kind of GOTO abuse by the ALGOL(?) and PL/I(?) programmers of the day were in *every* loop structure, and *very* common special case handling.
    Bundle that with the kind of optimizations you had to do in the days of 8K core being a big machine, and the end result could be *really* ugly.

    On the other hand, Dijkstra himself would probably use GOTO in the situation described in the article (e.g., porting LAPACK?)

    --
    -fb Everything not expressly forbidden is now mandatory.
  169. for more technical info, see goto's personal site by Trollll · · Score: 3, Informative

    for more technical info, see his site at the Texas Advanced Computing Center. pretty pictures and software tool downloads even.

  170. Why bother with this story? by brsmith4 · · Score: 2, Informative

    I can attest to the efficiency of these routines. When I benchmarked a 22 processor Opteron cluster w/ Myrinet, the use of Goto BLAS resulted in a near 20% drop in CPU utilization but yielded a ~2 GFlop gain in performance using HPL (performance was roughly 60 GFlops total. Given more time, I could have probably coaxed more out of Linpack). This compared to ATLAS, the self-tuning BLAS and LAPACK routines that I painstakingly recompiled at least a few dozen times. Generally, ATLAS yields very decent results even compared to some of the "drop-in" Lin-Alg. routines found with most high-end compilers like PGI (ACML, PGI-optimized BLAS/LAPACK/SCALAPACK) but so far, nothing I have tried rivals the performance, in the case of HPL, of Goto's implementation. Great work, man!

  171. Consider this... by Anonymous Coward · · Score: 0

    Altought the ACM said so, it does not mean its true. It might just be desinformation.

    How about you doing some tests and reach results-based conclusion?!

  172. Re:Look at the asm output of your compiler sometim by narcc · · Score: 1

    Even if you don't read the article at least read the summary. It's about a guy with the last name 'Goto'.

  173. Well, it DOES have some uses, but... by Anonymous Coward · · Score: 0

    Not perfect, but at least the following isn't too unreasonable:

    int err = 0;

    foo = malloc(1);
    if (!foo) err = -1;

    if (!err) bar = malloc(1);
    if (!bar) err = -1;

    if (!err) baz = malloc(1);
    if(!baz) err = -1;

    if (err) {
      if (foo) free(foo);
      if (bar) free(bar);
      if (baz) free(baz);
    }

    return err;

  174. GOTOs sometimes make the code *more* readable by randyflood · · Score: 4, Interesting


    I like everyone else was trained *never* to use the dreaded goto statement. I'll grant that Pascal was more readable than Basic (with unlabeled gotos).

    But, sometimes, it is actually better to use a goto to make the code more readable. The Linux Kernel, for example, uses gotos. I was pretty sceptical at first because it had been drilled into my head how unreadable code was with gotos in it. But, reading the code, I have to admitt is is much more readable for exception handeling, for example.

    If the goto would not make your code more readable then don't use it. But, in the cases where it would avoid a bunch of sillyness trying to get out of a bunch of nested loops in case some error happened, then it makes a lot of sense.

    Linus Torvalds (and others) explain the reasoning for this at:

    http://kerneltrap.org/node/553

    In short, there are both readability and efficiency reasons to use gotos.

    --
    Randy.Flood@RHCE2B.COM
    1. Re:GOTOs sometimes make the code *more* readable by chrisbell · · Score: 0

      I was also trained to be anti goto. I almost never have used them, but it is true that there are times that it makes sense to use them.

      At one place I worked the original writers used tons of endless for loops that were and the practice was to use a break statement to get out of 'em. Kind of the same thing.

    2. Re:GOTOs sometimes make the code *more* readable by swillden · · Score: 1

      But, sometimes, it is actually better to use a goto to make the code more readable. The Linux Kernel, for example, uses gotos.

      Actually, I have hardly seen any code, anywhere that does *not* use goto. In lots of code the programmer seems to prefer a different keyword, 'return', but it's still essentially means 'leave this code right now, do not execute any further instructions'.

      The common use of 'goto' you see in the kernel and elsewhere is essentially to implement a more featureful 'return'. When you need to bail out of the current function, but need to do some cleanup on the way out, 'goto' is exactly what you need. For those who haven't seen the usage, you're just replacing:

      ...
      if (/* test an error condition */)
      {
      /* do cleanup */
      return ERR_CODE;
      }
      ...
      {
      if (/* test another error condition */)
      {
      /* do cleanup */
      return ERR_CODE;
      }

      With:

      ...
      if (/* test an error condition */)
      {
      retval = ERR_CODE;
      goto end_func;
      }
      ...
      if (/* test another error condition */)
      {
      retval = ERR_CODE;
      goto end_func;
      }
      ...
      end_func:
      /* do cleanup */
      return retval;

      The second is no harder to follow and avoids duplicating the cleanup code or creating a deeply-nested, hard-to-follow sequence of ifs.

      A couple of decades back, 'structured' code was a popular fad, with its emphasis on single-entry, single-exit functions. I can see the theoretical simplicity of having code that does not return from the middle of a function, but in practice there's an awful lot of code where the process of performing a single functional task involves:

      • Check/perform task prerequisite A. If it fails, the function fails.
      • Check/perform task prerequisite B. If it fails, the function fails.
      • Check/perform task prerequisite C. If it fails, the function fails.
      • Check/perform task prerequisite D. If it fails, the function fails.
      • Since A,B,C,D succeeded, perform the task.

      The "early-exit" style of programming is often the cleanest way of implementing such functionality.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    3. Re:GOTOs sometimes make the code *more* readable by StikyPad · · Score: 1

      Right.. as I always say, "Never use GOTO except for exceptions."

  175. Really? How fascinating! by Anonymous Coward · · Score: 0

    goto statements remind me of 7th grade and looking through the hole in the girls changing room

    Could you see into the boys changing rooms from in there?

  176. Do you *do* numerical computing for a living? by Darius+Jedburgh · · Score: 1

    Way too much! I used to get excited about a 10% speedup. But these days I just can't get excited about it when I know that next year's PC+old code will blow away current PC+optimized code. (Probably because, as everyone knows, time passes faster when you're older.) I'd rather spend time on algorithmic stuff that might make, say, an O(log N) improvement in speed that will continue to pay off more and more over time. But I suppose it's good to know there are young whippersnappers out there prepared to optimize the libraries I may have to use.

    1. Re: Do you *do* numerical computing for a living? by Frumious+Wombat · · Score: 1

      10% improvement, I agree with you. 25%, we start to pay attention, and when my runtime drops by half or more, then it's worth the trouble. Regrettably, while the computer gets faster every year, the size of problem I'm expected to tackle gets larger as well, so no net win.

      It would be nice if the comp-sci types would, every now and then, mention that some of those algorithms have huge prefactors, and those matter. Optimized, versus stock Netlib BLAS makes a huge difference on my codes. On the other hand, I certainly wouldn't recommend that level of detail on the whole program.

      --
      the more accurate the calculations became, the more the concepts tended to vanish into thin air. R. S. Mulliken
  177. almost... by fbartho · · Score: 1

    i=10;

    --
    Gravity Sucks
  178. Heh. by jhantin · · Score: 1

    Justin Case? That guy in Neuromancer?

    And why's Mr. Goto suing -- did he take exception?

    --
    ...when you're writing a game...tweak the difficulty of "Easy" to something [your mother] can cope with. -- onion2k
  179. Re:If true... by yatt · · Score: 1
    "Sigh. Why don't they teach assembly anymore. It should be a pre-req to learning higher level languages."

    They (ie my uni) do teach assembly any more but why not really start with the fundamentals? Only with a solid grounding in semiconductor physics will they fully understand the implications of:
    print "hello world"

    but seriously

    I'll agree with you that it's useful to know assembly but it was confusing, particularly for those who were reasonably new to programming.

    We were introduced to assembler just before we got to pointers and I think that timing makes more sense than starting from scratch with assembly.

    Assembler requires alot of hardware knowledge that isn't necessary for any higher level language and i think that when you start out programming you have enough on your plate without having to worry about memory and registers and interupts.

    What's wrong with starting with the nice easy stuff? It's like in maths where they start with counting rather than, say, integration. Just because the first programmers started out with cogs and wheels (or slaves and a drum or whatever they did start with) doesn't mean it's the best way for everyone else to learn.

  180. Re:GOTO Considered Harmful since at least 1968 by McPolu · · Score: 1

    if "Do something useful" is quite long, I will write it in a separate function ;)

  181. no... really?!? by pyrrho · · Score: 1

    back when we decided they were a bad idea it was because "they're so damned slow"... usually, they take a WHOLE INSTRUCTION when compiled. But if you remove them, why that's zero instructions... huh, should be faster.

    Next up... Fortran still faster than C.

    --

    -pyrrho

  182. You know you're a programmer... by neuro.slug · · Score: 1

    ...when someone tells you to go to Hell, you are more indignant about the method than the destination.

    -- n

  183. Re:duh.... by charletes · · Score: 1

    I really can't believe none of you have undestood the article... It's not that kind of "Goto". It's not about an instruction, it's about a guy!!!!!!!!

  184. Re:Look at the asm output of your compiler sometim by eric76 · · Score: 1

    The worst abuse of goto's I've seen was in a numerical analysis class.

    Back in the 70's, one student turned in an assignment with a goto on nearly every other line!

    It looked like she dropped or shuffled her deck of cards and used goto's to put them back in order.

    The resulting program didn't work correctly and it took a good half hour or more to find the actual error. If I remember right, the failure was because she used a variable starting with 'I' for what should have been a FLOAT. Normally, I could pick those errors up very quickly.

  185. Another Goto. by pkhuong · · Score: 1

    Isn't that another Goto? (of hash-consing fame, which makes deep-equality on functional lists O(1) and often significantly reduces memory consumption by discovering duplicates at runtime)

    Well, I guess I could name my first-born Foobar Gosub and s/he should be a good computer scientist ;)

    --
    Try Corewar @ www.koth.org - rec.games.corewar
  186. Punny, tum-tum by Anonymous Coward · · Score: 0

    Gai, that is SO gei

  187. Congrats!One of the funniest topics I've ever read by Anonymous Coward · · Score: 0

    Thank you, Slashdot ! ;-)

  188. Re:goto is obsolete by Anonymous Coward · · Score: 0

    Don't forget his nephew, Mr GOatse.

  189. Mr. Goto's name by Anonymous Coward · · Score: 0

    FWIW, Mr. Goto is pronounced goe toe. Not "goto" as in the BASIC construct.

  190. Re:GOTO Considered Harmful since at least 1968 by TheSlashFrog · · Score: 1

    If you can't use goto properly, that's fine- maybe in another 10-20 years of programming you'll feel comfortable enough with your skills to use it.

    It's the opposite, 10-20 years ago I was quite comfortable using gotos - before I learned the basic principles of good C programming, mainly how to avoid spaguetti programming and break down your code into smaller meaningful routines.

    Regarding stack overhead, have you heard of inline functions? You can still write good readable code and let the compiler do all the dirty work, thank you very much. You may not feel comfortable enough to take advantage of the compiler with your current skills, but maybe in another 10-20 years...

  191. Re:GOTO Considered Harmful since at least 1968 by david.given · · Score: 1
    That's fine, but I'd put "error:" after the return success.

    You didn't read what I said, did you? I can't put it at the end because you can't jump over a variable declaration in C++. (Because you can't jump into a greater scope than the one you're currently in, but you can jump into a lesser one.)

    And I can't use exceptions because this is an embedded device where I can't afford the 2kB-per-stack-frame hit that enabling exceptions in gcc gives me.

  192. Re:The Fastest Code of All by pe1chl · · Score: 2, Funny

    This always reminds of how "Label not found" was translated as "Volumenaam niet gevonden" in the Dutch version of MS-DOS.

    The translator apparently had seen the DIR output "Volume in drive A: has no label" and believed that the "label" is referring to a "volume label" and translated it as "volumenaam" ("volume name").

    But when a .BAT file uses GOTO and specifies a nonexistent label, the translation to "volume name" is completely incorrect.
    When I first got this errormessage running a .BAT file, it took me quite some time before I understood what was happening.

  193. Fishy by DirtyLiar · · Score: 1

    How many of you botherd to read the article? This sounds like a very deep hoax.

    An Asian Dr. Goto?
    A non-Asian Dr. van de Geijin?

    The BLAS?

    A quick google of "van de Geijin" | "Mr Goto" | "Dr Goto" brings up 12,100 hits.
    http://www.google.com/search?hs=SIB&hl=en&lr=&clie nt=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q= %22van+de+Geijin%22+%7C+%22Mr+Goto%22+%7C+%22Dr+Go to%22&btnG=Search

    Dunno.

    --

    THINK! It's patriotic

    1. Re:Fishy by Anonymous Coward · · Score: 0

      p.s. Never trust a doctor named Dr. Van de Phealjooupp, especially if his business card has an ambiguous space in his title "T h e r a p i s t"
      That was the worst $100 I ever spent. :-(

  194. Re: wrong on multiple counts by Anonymous Coward · · Score: 0

    [Disclaimer: 3rd party here. I'm replying to your post, but the grandparent needs to be slapped as well.]

    >Yeah, that's what I said -- changing from bubblesort O(n^2) to quicksort O(n log n) would be an example of an order of magnitude optimization.

    I can't help myself. You set yourself up the bomb. First of all, the term "order of magnitude" refers to power 10. Consider the runtimes of three algorithms: A = 0.11, B = 1.0, C = 9.9. A and B are within an order of magnitude of one another, and B and C are also within an order of magnitude of one another. However, A and C are approximately 2 orders of magnitude apart.

    Second, going from O (n^2) to O (n log n) is not an "order of magnitude" difference. It's difference in the order/degree of the polynomial. They're similar terms, but they have quite different meaning. For inputs less than n=59, n^2 and n log n are within an order of magnitude, and it is also possible to pick two different n log n algorithms that are always more than an order of magnitude apart.

    Third, never argue that quicksort is O (n log n), because it's not. It's only n log n on the "average" case, but it's still n^2 in the worst case. There are adaptive modifications to quicksort that make it n log n in the worst case by recursively selecting the best pivot; however, such adaptive quicksort algorithms are usually nowhere near as fast as heapsort and its variants. When you call qsort in C, you just get the plain vanilla version of quicksort that has n^2 worse case runtime. Its n log n "average case" is about 30% faster than a good heapsort (* this depends on the things like the relative cost doing memory writes vs comparisons). To me, the "average" savings of 30% is usually not worth the chance that my program will unexpectedly freeze for a few seconds (or worse).

    In short, I do not recommend blindly using qsort instead of bubble sort, which is potentially faster and is always more stable. If you're going to blindly pick another comparison sorting algorithm, choose heapsort. If you're only sorting integers, use a radix sort.

  195. Re:goto is obsolete by dodongo · · Score: 1

    Well, you beat me to my punch line. Cheers!

  196. Japanese pronunciation by zooblethorpe · · Score: 1
    * Note: Pronunciation instruction may only apply if you live in the city of Boston. People living in other localities may need to contact the appropriate authorities for further instruction.

    Indeed. For the average Merkun, the easier and closer pronunciation would probably be the two words go toe , with the accent on "toe". (No offense to the GP poster, but what's up with the "r"s?) Strictly speaking, there are only five Japanese vowels, and they are all flat, very like what you get with Spanish. Vowel length is another important pronunciation distinction, but this doesn't happen in English, as this language uses syllabic stress instead. That's why you may sometimes see the Japanese surname Goto variously spelled as Gotoh or Gotou, or even with diacritics as Gotö or Gotô, to emphasize that the second "o" is supposed to be long.

    Just my ¥2 as a Japanese-English translator. Eigo de no hatsuon ha dou de mo ii n da kedo, dekireba, chikai hodo ii ja nai desu ka.

    --
    "What in the name of Fats Waller is that?"
    "A four-foot prune."
  197. Re:GOTO Considered Harmful since at least 1968 by mrsbrisby · · Score: 1

    Regarding stack overhead, have you heard of inline functions? You can still write good readable code and let the compiler do all the dirty work, thank you very much. You may not feel comfortable enough to take advantage of the compiler with your current skills, but maybe in another 10-20 years...

    You're kidding right?

    Let me guess, you also run everything with -funroll-loops, don't you?

    It's the opposite, 10-20 years ago I was quite comfortable using gotos - before I learned the basic principles of good C programming, mainly how to avoid spaguetti programming and break down your code into smaller meaningful routines.

    I'm so glad the Linux kernel developers are 10-20 years behind you then.

    Goto doesn't produce spaghetti code- you do. That's the problem. If you want to blame it on goto, fine, but inlining functions far away from their exception handlers is still spaghetti code.

    By the way, most C compilers don't avoid the stack operations when inlining- most of the time they can't- they simply avoid the call routine.

  198. Re:GOTO Considered Harmful since at least 1968 by mrsbrisby · · Score: 1
    You didn't read what I said, did you? I can't put it at the end because you can't jump over a variable declaration in C++. (Because you can't jump into a greater scope than the one you're currently in, but you can jump into a lesser one.)

    I misread these:
    Object2 o2();
    as
    Object2->o2();
    (blaming slashcode) instead of what you probably meant.

    And I can't use exceptions because this is an embedded device where I can't afford the 2kB-per-stack-frame hit that enabling exceptions in gcc gives me.

    I covered that: or you shouldn't be using C++... :)
  199. Don't kid yourself ... by 32771 · · Score: 1

    into thinking that gotos can't give faster code. I demonstrated this to a CS guy who looked at my goto with disgust. I replaced a for loop with an if (...) goto label; statement in my C code and out came improved performance. Gotos are useful in coaxing gcc based compilers into giving up loop optimization and leaving it to the guy who should worry about it in the first place - the user. The other compilers are so bad they don't matter or are so good I don't have to worry about.

    --
    Je me souviens.
  200. Re:200+ comments and I can't believe they missed t by Anonymous Coward · · Score: 0

    But that would be an infinte loop!

    Or am I missing something?

    :)

  201. Ah The Paradox of Programming by Greyfox · · Score: 1
    There are a lot of things they teach you not to do in school. A lot of the things they teach you to avoid WILL get newbies in trouble. Hopefully by the time you get to the point where you realize that you can in fact perform the forbidden act, your skills have progressed to the point where you know where and when it is justified to do so and all other potential courses of action will be more awkward.

    Of course I'm talking about using goto. What else would I be talking about?

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  202. Here's my understanding. by Mr+Z · · Score: 1

    The main place where goto seems to foul up compilers is where it makes the control-flow graph (CFG) something more complicated than the graphs that arise from normal conditional flow. CFGs arising from normal nesting control-flow constructs can be drawn on a 2-D surface with no lines crossing each other. The same can't always be said of code littered with gotos.

    --Joe

  203. Re:GOTO Considered Harmful since at least 1968 by Anonymous Coward · · Score: 0

    Exceptions are very slow and should be used only for exceptional cases. The general suggestion is to never use exceptions for defining control logic in the code where performance matters.

  204. Re:goto is obsolete by ciroknight · · Score: 1

    Your comment goes more towards validating my comment than against it, so I don't understand why you said it. Instruction logic "goto" statements may be a jmp instruction, but the fact is, it is still a jump, which is functionally, goto. Hell, I'm sure if you compiled an app using a goto jump and decompiled it, you'd most certainly find it.

    The same goes for a lot of functions (depending on the programming language). If the function isn't inlined during compilation, the compiler will simply load the addresses/data of what's needed for that instruction into a register, jmp to the location of the function, complete the function, and return back to where it was in order.

    As for the "no use for a goto when you have a function"; there are a _lot_ of instances where a jump instruction is useful, where a function simply won't do what you want to do. For example, inside of a switch or nested if statements, etc. There are situations where jumping simply can't be avoided. The reason they teach against it is simply because people tend to use it badly; it leads to running off the stack, memory leaks and they are typically difficult to debug. However, I'd love to see you write a kernel without using a goto statement somewhere.

    --
    "Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
  205. Structured code is good by typical · · Score: 1

    I like using goto for cascading error handling in functions performing allocation. This avoids redundant error-handling code and extraneous flag variables.

    However, this is *structured* use of goto, in such a way that one essentially doesn't need to look at the destination (and if one does, it's on the same page, and ordered -- foobar_error10 is the first label, then foobar_error9, then foobar_error 8...).

    I agree with the general concept of avoiding goto. The initial complaint about goto was that it makes code hard to read and maintain.

    The easiest-to-read code structure that I've ever seen is a tree -- function foo calls function bar and function baz, each of which call their own functions. Procedural programming follows this structure.

    Code that uses goto for general control flow is completely unstructured -- instead of trying to follow the control flow of a tree, it's trying to follow a randomly-connected graph.

    Every function pointer (and setjmp()/longjmp()) in C breaks this beautiful, easy-to-read tree, so minimizing use of function pointers is quite useful.

    I don't know why so many people get hung up on OO. Reading OO (with polymorphism) is like reading a bunch of little one-level bushy trees that aren't connected to any of the other trees.

    --
    Any program relying on (nontrivial) preemptive multithreading will be buggy.
  206. Well... by woolio · · Score: 1
    additions. To get 100% of this speed one needs to have a sophisticated handling of cache memory, among other requirements.


    One problem with "optimization" is that often the wrong thing is optimized.

    For example, Someone might be able to implement a convolution (dot product) using the regular O(N^2) formula... For a vector of length N, this will result in O(N^2) floating-point adds and multipications being performed... Loop-unrolling could be used to keep all the units on the P4 busy...

    However, the same result could be computed using a FFT, which is O( N Log2 N ) in # of adds & mults. Thus, this method requires significantly less computation [picture what happens when N=128], and a tad bit more memory. This implementation will not fully utilize a P4's arithemtic units although it would likely complete in far less time than the first method.

    Thus, if someone is trying to show off how fast their new processor/supercomputer/cluster can be, they may not use the fastest implementation!

    I recall seeing a few "supercomputer" specs recently that advertised "TFLOP/s" rates that were calculated based upon the maximum instruction bandwidth... This is deceptive advertising since even highly compute-intensive programs will not have an instructions stream composed solely of floating-point arithmetic... (And if a huge number of floating pointer operations are being done without any loads/stores, then perhaps there is a way to simplify the calculation!)

    People usually refer to Amdahl's law for parallelizability... But a similar concept exists when taking about instruction mixes and functional units.
    1. Re:Well... by Anonymous Coward · · Score: 0

      Good libraries would implement both, depending on N - you do know that for small N the overhead of the N log N method is bound to make it slower.

      And remember that N log N methods are usually based on reducing the problem size (in half) and recursing. In this process, when N gets small enough the N^2 method becomes fastest, and so the recursive also benifits from having the N^2 base-case algorithm run fast.

      Giving different example, a good library to multiply huge integers will have a hand optimized for cache assembly version of the N^2 algorithm, then Karatsuba (N^1.585), then 3-way Toom-Cook (N^ 1.465), then FFT multiplication, as well as thresholds to switch between algorithms.

  207. goto in allocation functions by typical · · Score: 1

    How do you deal with functions that perform a transaction -- i.e. operations that must be all rolled back if any operation fails?

    For example:

    int alloc_func(void) {
            r = malloc(30)
            if (!r) goto alloc_func_error1;
            t = malloc(20);
            if (!t) goto alloc_func_error2;
            q = malloc(25);
            if (!q) goto alloc_func_error3;
            return 0;

    alloc_func_error3:
            free(t);
    alloc_func_error2:
            free(r);
    alloc_func_error1:
            return -1;
    }


    I mean, in C++ you can get this by having code that runs when variables go out of scope, but in C, this seems to me to be a pretty good way of dealing with the problem.

    --
    Any program relying on (nontrivial) preemptive multithreading will be buggy.
  208. Procedural code easier to read than functional by typical · · Score: 1

    I can safely say that, regardless of what's easier to write, functional code is much harder to *read*.

    Procedural code (C w/o function pointers and setjmp()) follows a simple, easy-to-read tree structure.

    In functional code, I can't just look at some dead code and know what code is being executed ("Oh, so this variable that's being executed is a function returned from this other function that took a function that was returned from another function a while later...now *what* code, exactly, does that mean is being run?")

    --
    Any program relying on (nontrivial) preemptive multithreading will be buggy.
  209. Re:If true... by Anonymous Coward · · Score: 0
    While loops don't randomly disregard the truth value of their repeat condition, nor do For loops. But goto statements do

    Goto statements are deterministic, just like the others.

  210. Re:If true... by typical · · Score: 1

    I still maintain the point that designing a monolithic kernel in 1991 is a fundamental error. Be thankful you are not my student. You would not get a high grade for such a design...Writing a new OS only for the 386 in 1991 gets you your second 'F' for this term. But if you do real well on the final exam, you can still pass the course.

    -- Andy Tanenbaum, flaming Linus Torvalds for perceived design flaws in Linux

    --
    Any program relying on (nontrivial) preemptive multithreading will be buggy.
  211. Duh by Supergibbs · · Score: 1

    I've always heard GOTO was faster, that was never the problem. People don't like them because of maintainability. OOB is easier for large complex applications and tracing a mess of GOTO statements, especially on code that isn't yours, is a nightmare!

    -Jesse

    --
    First post! (just in case I am...)
  212. I can't believe nobody's posted this yet ... by AngusSF · · Score: 1
    --
    "A gun is a tool, Marian. No better, no worse than any other tool. An axe, a shovel, or anything." Shane (1953)
  213. Re:If true... by Deviant+Q · · Score: 1

    int i = 10;

    --
    "May the days be aimless. Let the seasons drift. Do not advance the action according to a plan."
  214. Scope creep kills a project. by TapeCutter · · Score: 1

    Excellent example of the "real world", somebody in authority gives you an explicit requirement - "code something with as few lines as possible" - then (after the delivery) adds another requirement - "don't use goto".

    When you point out that it was not part of the requirements you will be called unproffesional since "everybody knows" the second requirement is implicit in all projects.

    Trying to anticipate all the possible implicit requirements will get you nowhere in fighting the "everybody knows" attitude. Your proffessor is an unreasonable customer. Unfortunately you just have to wear it because, (like many programmers in the "real world"), you don't have a boss with balls to set the customer straight.

    Scope creep problems are akin to a builder being told the customer wanted an indoor swimming pool but neglected to say anything until after the building was finished. The builder will either prepare a quote for the new work or tell the customer to fuck off, why should software be any different?

    --
    And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
  215. It's not by theolein · · Score: 1

    The Y with diaresis is a convenience spelling of ij in Dutch. Try it out. It's easier writing a y with two dots than an i and a j seperately.

  216. Hell yeah it does! by crhylove · · Score: 1

    10 print "hello"
    20 goto 10

    Watch how fast that shit runs!

    --
    I hold very few opinions. I hold information based on observation and fact. If you wish to disagree, please use facts.
    1. Re:Hell yeah it does! by krischik · · Score: 1

      Well true, but why should it be any faster then:

      loop
            Ada.Text_IO.Put_Line ("hello");
      end loop;

      Martin

    2. Re:Hell yeah it does! by Anonymous Coward · · Score: 0

      The inherent homosexuality of the Ada programming language penalizes a 24% computational overhead, specifically the sucking and blowing calculations.

  217. Pacbase! by necronom426 · · Score: 1

    You should see the code that Pacbase creates. It's an application that writes COBOL with as many GOTOs as possible. It's horrendous! You are not supposed to look at the COBOL of course; you program with the Pacbase language which is almost as bad.

  218. Re:If true... by SatanicPuppy · · Score: 1

    Alas, I can't put myself on that kind of level. And, in retrospect, if anyone put that code into one of my projects, I'd fire 'em too. Gratuitous recursion is too memory intensive and diffucult to read to be of much use. Sure it's pretty, but doing it with a simple loop is more efficient, even if oh so much uglier.

    --
    ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
  219. Flamebait? by iBod · · Score: 1

    Oh brilliant!

    Where was the 'flamebait' in that comment?

    Idiot mods strike again.

  220. A better teaching idea. by Nicolay77 · · Score: 1

    I believe the teacher should gave students two pieces of code, one with spaguetti goto code, one with well behaved structured code.

    Both of them big enough to not be trivial and both of them with some kind of bug.

    "Please fix this one. It's called GT. If you solve it the qualification is 100%. If you're unable to fix it, fix the other one, called GTL (goto less), but the qualification in that case is 80%."

    And then give 100% to any of the solutions.

    That way they will learn WHY most goto's are a bad idea.

    --
    We are Turing O-Machines. The Oracle is out there.
    1. Re:A better teaching idea. by Doc+Ruby · · Score: 0

      Well, that's a way to teach GOTO programming technique. I was just pointing out the problem of a teacher acting like they'd taught a student not to do something, when they'd just omitted teaching that thing. I think penalizing a student for using that thing they'd learned independently, but not gotten instruction not to use, is exactly backwards: penalizing their initiative and creativity (if it was used correctly). Our mutual point is that teaching is not a "gotcha" game, but rather a means of communicating between people, one of whom is responsible for initiating and enforcing the clarity of both parties' communication. Your technique might work for you, and for others like you - other students might respond to different techniques. That's what communication is like among individuals.

      --

      --
      make install -not war

  221. digg by Nicolay77 · · Score: 1

    But now most /. people read the article if it first shows up in digg.com !

    --
    We are Turing O-Machines. The Oracle is out there.
  222. Re: wrong on multiple counts by shobadobs · · Score: 1

    First of all, the term "order of magnitude" refers to power 10.

    The term "order of magnitude" refers to whatever the speaker was referring to. Definitions of words and phrases are not set in stone. When talking about asymptotic bounds, people use "order of magnitude" all the time. Deal with it.