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?
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. There was no mention of it in my university classes at all. I remember being told not to use it my high school computer science class. Ha..
This isn't news, everyone knows GOTO results in faster code than GOSUB
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.
So far, no one has read either the article, or the blurb... hint: it's not about using the goto statment to make your code faster (bo avoiding those oh so expensive stack instructions).
Morons.
10 PRINT "HELLO"
20 GOTO 10
http://kerneltrap.org/node/553
goto in linux kernel code is not considered harmful. Linus said so in 2003!
Personally, I think there are a few - a very few - times when GOTO is the right thing to do. In some languages, something like:can be quite readable and quite useful, and may even be more readable than the "canonical" way of accomplishing the same thing in that language. A word of caution - it is very easy to overuse this and wind up with a pile of spaghetti. In general, GOTOs should not be used by beginning programmers unless it's the preferred structure in a given language, such as most Assembly-languages. Before you ask, I think beginning programmers SHOULD write at least toy programs in assembly languages, as a history lesson if nothing else.
Now, as for the pun, I like it
Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
Of course goto leads to faster code. Goto is simply a non-conditional jump - in most processors it is a single instruction that takes few cycles.
But the only case where it should lead to huge improvements in performance is when you replace functions with goto. Then you eliminate a ton of code that fiddles with the stack and saving processor state before going to another function.
The code can be less maintainable, but primarily because functions are easier to deal with than even well written goto code.
And, of course, anything that makes code easier to write is generally better for most applications. Computers are fast enough now that the perfromance hit when the customer is using it is cheaper for the company producing the software than the performance hit the coder takes writing faster code. Only in cases where extreme perfromance is needed is it better to spend more resources writing the code than running it.
-Adam
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.
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
Actually de facto a WHILE / FOR /REPEAT is transformed in assembler code with an label and a JNB / JNC / JMP (or even a REP) whatever toward the label once the check whether the loop is finished is made. A Goto is simply a JMP that you code in your program. For a good compiler this should make NO DIFFERENCE whatsoever between a FOR/REPEAT/WHILE and a IF test with a GOTO. Now naturally if the previous implementation had crappy rolled up REPEAT/WHILE and he unrolled it then naturally it will be 30% better. This has nothing to do with Goto but everything to do with the previous/bnew implementation. And after having worked so much time with F77/66 I saw enough spaghetti code with GOTO for 5 life time. I guess this article should get the foot-icon for "humor".
C. Sagan : A demon haunted world:
http://www.amazon.com/gp/product/0345409469/
visit randi.org
10 ?"goto statements remind me of 7th grade and looking through the hole in the girls changing room"
20 goto 10
Uhhh - yeah, right.
Forgive me if I suggest you stay firmly within YOUR box, pal.
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.