A Conversation for The GOTO Statement
The h2g2 association for the abolition of gotos...
TowelMaster Started conversation Aug 24, 2001
You really make me think about starting a group like that...
We could play games : One person could send in a program with gotos that "could not be written better without them". And the rest could then try to prove him/her wrong...
Anyway, informative again.
Greetz,
TM.
The h2g2 association for the abolition of gotos...
TowelMaster Posted Aug 28, 2001
Hello SchrEck Inc.
Well as long as it's not a democratic process you can be the vice-president... .
How about lots of stories about impossibly stupid ways in which gotos were used ? Or, if we may expand a bit, we could reenact the 1980-s Structured Programming Wars. I must admit that I am more into that than into Gotos because I learned the programming-trade in the early 80-ies. When the wars were most fiercely fought... And I am one of those b****ds who has never used a goto in my life. And in those days men were real men, women were real women, and nerdy-looking programmers on coffee and coke were real nerdy-looking programmers on coffee and coke.
How about a perform in Cobol that I found back then ? I'll do it in "pseudocode" as my Cobol is now very, not to say *very* rusty...
Simple objective : Take any number of minutes(total-minutes) and calculate the total hours(hours) and remaining minutes(minutes).
Originally found in the new software back then :
[code]
P3000-calculate.
Perform P4000-calculate-2 until total-minutes < 60.
Move total-minutes to remaining-minutes.
P4000-calculate-2.
Add 1 to hours.
Subtract 60 from total-minutes.
[endcode]
This makes the program run P4000 until the total-minutes is < 60. So in the case of total-minutes = 10.000 this will result in 10.000/60 = 166 times x three instructions = 490 instructions. For one calculation!
When I found this "logic" the programs(there were over a thousand of them!) executed this bit of coding for thousands of times...
Mind you : this was written by hired programmers who were paid a fortune! Whereas the simple solution of course would be to code it like this :
[code]
P3000-calculate.
Divide total-minutes by 60 giving hours remainder minutes.
[endcode]
And they all wondered why the stuff took ages to run each night...
TM.
P.S. I always did like the jokes you could program with gotos. Like "goto the-loo" et al. I know, I know, I was young...
The h2g2 association for the abolition of gotos...
SchrEck Inc. Posted Aug 29, 2001
OK, then, I'd like my title to be 'VP of Lengthened Loops and Concise Case Constructs'. Remind me to have my business cards printed...
But serious, the worst things that I've ever stumbled upon are self-modifying assembler programs. There was a counting loop for instance where the opcode for INC was changed to DEC in order to let it count downwards... shudder. Hellish to maintain.
The h2g2 association for the abolition of gotos...
Blitzer Posted Sep 21, 2001
The dumbest code I've ever seen was written by people in the 1980s and 1990s. They were so stupid that they didn't think to make the code work once the year clicked over to 2000. Is there anybody prepared to admit that they were one of these people? How about any people who made millions of dollars from other people who got scared by the stupid people.
The h2g2 association for the abolition of gotos...
mishofsydenham Posted Jan 27, 2003
I made about £400 extra from being on 12 hour support for 2 days on 29-30 December 1999. The guys who were on support for 31st December/1st Jan got £1000 extra. Not my idea, but if it came to taking the money and running, then I for one, etc. etc. Needless to say, there were no problems.
The h2g2 association for the abolition of gotos...
Bellman Posted Feb 6, 2003
I made no money at all. Most of my work's done in a language that supports dates from 1753 to 9999, knows about Leap Years, and doesn't have a Goto.
The h2g2 association for the abolition of gotos...
E}I{ Posted Jun 3, 2003
First, sorry for bad English....
Hm. I remember coding quite fast monochrome gouraud shaded texture mapper 5-6 years ago which looked like that:
(note this is not _real_ code and it contains no CPU specific optimizations)
--------------------
x86 32 bit pseudocode
--------------------
;inner scanline loop
;esi/ebp/edx -texture x/y coords/color with fractional part
nextpixel:
..... ; generate pixel color (placed in al, for example)
mov [edi],al
inc edi ; one byte instruction can be changed to "dec edi"
add esi,0DEADDEADh ; texel X delta-value
add ebp,0DEADDEADh ; texel X delta-value
add edx,0DEADDEADh ; texel X delta-value
loop nextpixel
---------------------------------------
;delta values are overwritten by triangle setup code saving me three registers(coz I don't have free registers at all) or three slow (on older x86 machines) memory accesses per each pixel.
-"inc edi"/"dec edi" selection depends on where point with middle Y coordinate is located(this way I can forget about left/right orientation and interpolate starting tx/ty/color values only between upper and lower triangle points without duplicating inner loop for both cases)
Also i found this code very fast
---------------------------------
#define BRK goto loopstart;
counter = -200; // for example, of course
:loopstart
.... ///do something that always must be done
if(!++counter) goto exit;
tmp=base_address+counter;
switch(tmp) {
case 0:
BRK
case 1:
BRK
...
case n:
BRK
}
:exit
-----------------------------------------------
real code was more complicated, but you can get the idea. I got >10% performance gain in time critical app by arranging things this way(coz i saved at least one jump and some misc instructions).
The h2g2 association for the abolition of gotos...
E}I{ Posted Jun 3, 2003
sorry, instead of
tmp=base_address+counter;
i meant
tmp=*(base_address+counter);
or just (more confusing sometimes)
tmp=base_address[counter];
Key: Complain about this post
The h2g2 association for the abolition of gotos...
More Conversations for The GOTO Statement
Write an Entry
"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."