GOTO, alive and well after all [modified]
-
CDP1802 wrote:
See also: Spaghetti code
After years of the 'never GOTO' doctrine was implemented, I've come across horrible text book examples of spaghetti code in which a GOTO statmenent shined but from its absence. On regards of 8 bit CPUs lacking multiply and division instructions, the Motorola 6809 sports a MULtiply instruction, while the Hitachi 6309 adds an extra multiply plus two division instructions. That made this CPU line stand heads and shoulders above the rest of its generation :cool: -- RP
-
I remember employing some self modifying code ( X| ) to save some space, so tight were the limits.. wouldn't do that on a modern PC :)
-
And the Z80 had some as well, if I remember right. But they were very slow and it still was a good idea to avoid them if possible.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
CDP1802 wrote:
And the Z80 had some as well, if I remember right. But they were very slow and it still was a good idea to avoid them if possible.
The hardware multiply was missing on the Z80, programmers had to write up the routines to handle that. For those who this may interest, this is how it was done in the old days [^] :-\ -- RP
-
And the Z80 had some as well, if I remember right. But they were very slow and it still was a good idea to avoid them if possible.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
-
See also: Spaghetti code :)
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
CDP1802 wrote:
Spaghetti code
Have you been sniffing forks again?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus! When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
-
CDP1802 wrote:
Spaghetti code
Have you been sniffing forks again?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus! When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
-
I just pulled this out of MSDN:
using System;
class SwitchTest
{
public static void Main()
{
Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large");
Console.Write("Please enter your selection: ");
string s = Console.ReadLine();
int n = int.Parse(s);
int cost = 0;
switch(n)
{
case 1:
cost += 25;
break;
case 2:
cost += 25;
goto case 1;
case 3:
cost += 50;
goto case 1;
default:
Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");
break;
}
if (cost != 0)
Console.WriteLine("Please insert {0} cents.", cost);
Console.WriteLine("Thank you for your business.");
}
}It has been a long time since I have seen so much 'goto' in one place, especially because I also count in switch statements and 'break'. This makes the question of using goto or not look a bit academic. Edit: In the old days such code would have made much more sense. On an 8 bit CPU without any instructions for multiplication or division all kinds of crazy things were done to avoid having to multiply or divide. But those days are long over...
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
modified on Wednesday, March 23, 2011 4:58 AM
CDP1802 wrote:
It has been a long time since I have seen so much 'goto' in one place
GOTO statements are great when you are programming in VBA. However, I have not used it anywhere else.
-
I just pulled this out of MSDN:
using System;
class SwitchTest
{
public static void Main()
{
Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large");
Console.Write("Please enter your selection: ");
string s = Console.ReadLine();
int n = int.Parse(s);
int cost = 0;
switch(n)
{
case 1:
cost += 25;
break;
case 2:
cost += 25;
goto case 1;
case 3:
cost += 50;
goto case 1;
default:
Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");
break;
}
if (cost != 0)
Console.WriteLine("Please insert {0} cents.", cost);
Console.WriteLine("Thank you for your business.");
}
}It has been a long time since I have seen so much 'goto' in one place, especially because I also count in switch statements and 'break'. This makes the question of using goto or not look a bit academic. Edit: In the old days such code would have made much more sense. On an 8 bit CPU without any instructions for multiplication or division all kinds of crazy things were done to avoid having to multiply or divide. But those days are long over...
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
modified on Wednesday, March 23, 2011 4:58 AM
CDP1802 wrote:
Edit: In the old days such code would have made much more sense. On an 8 bit CPU without any instructions for multiplication or division all kinds of crazy things were done to avoid having to multiply or divide. But those days are long over...
We have Co-Processors now...:)
Semper Fi http://www.hq4thmarinescomm.com[^]
www.jaxcoder.com[^] WinHeist - Windows Electronic Inventory SysTem -
CDP1802 wrote:
And the Z80 had some as well, if I remember right. But they were very slow and it still was a good idea to avoid them if possible.
The hardware multiply was missing on the Z80, programmers had to write up the routines to handle that. For those who this may interest, this is how it was done in the old days [^] :-\ -- RP
-
And the Z80 had some as well, if I remember right. But they were very slow and it still was a good idea to avoid them if possible.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
i was going to mention that too
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"