Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes

 
Don't use gotos!! Fair warning
Reply
Posted 2007-07-20, 11:36 AM
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2007-07-20, 11:51 AM in reply to Demosthenes's post "Don't use gotos!! Fair warning"
I used a few Goto's in my Computing project a few months ago... my teacher went crazy!

Thing is, she hadn't told us not to use Goto statements because it's unstructured.

Bollocks to that - I know what my program is doing, I know where the Goto's go, and it's not as if anyone else will see it.
Old
Profile PM WWW Search
Lenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basics
 
 
Lenny
 



 
Reply
Posted 2007-07-20, 11:55 AM in reply to Lenny's post starting "I used a few Goto's in my Computing..."
Edsger Dijkstra's 1968 criticism of goto's, in case you're interested:

http://www.acm.org/classics/oct95/
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2007-07-21, 04:46 PM in reply to Demosthenes's post "Don't use gotos!! Fair warning"
I don't goto, man. I just don't.
Old
Profile PM WWW Search
Grav never puts off to tomorrow what can be done the day after tomorrowGrav never puts off to tomorrow what can be done the day after tomorrowGrav never puts off to tomorrow what can be done the day after tomorrowGrav never puts off to tomorrow what can be done the day after tomorrowGrav never puts off to tomorrow what can be done the day after tomorrow
 
 
Grav
 



 
Reply
Posted 2007-07-21, 04:52 PM in reply to Grav's post starting "I don't goto, man. I just don't."
Goto's are fine for some things. Having multiple level breaks in C like in PHP would practically eliminate those things though.

Here's an example with some meaningless code:
Code:
for(i = 0; i < 10; i++)
   for(j = 0; j < 10; j++)
      if(i == 4 && j == 5) break 2; /* break 2 levels out */
In real C you would have to use a goto for that, or get nasty with some boolean flags.
Old
Profile PM WWW Search
Mantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to be
 
 
Mantralord
 



 
Reply
Posted 2007-07-24, 03:01 PM in reply to Mantralord's post starting "Goto's are fine for some things. ..."
Or, you could simply put the loops in an inline function and return from it.

All this structure, of course, breaks down to gotos at the machine code level, anyway.

Of course, you can write spaghetti code without gotos, too:
Code:
unsigned uState=0;
while(1){
  switch(uState){
    case 0:
      //stuff
      uState=2;
      break;
    case 1:
      //other stuff
      break;
    case 2:
      //land here
      uState=1;
      break;
  }
}
This is actually a construct commonly used in my line of work 0_0
Old
Profile PM WWW Search
WetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusionWetWired read his obituary with confusion
 
 
WetWired
 



 
Reply
Posted 2007-07-24, 04:02 PM in reply to WetWired's post starting "Or, you could simply put the loops in..."
Mantralord, you are a great wizard, But Wetwired has seemed to outdone you.

CRUCIO MANTRALORD! YOU LET HIM SURPASS YOU AGAIN!
Old
Profile PM WWW Search
slaynish enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzslaynish enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
slaynish
 



 
Reply
Posted 2007-07-25, 11:01 PM in reply to WetWired's post starting "Or, you could simply put the loops in..."
WetWired said:
Or, you could simply put the loops in an inline function and return from it.

All this structure, of course, breaks down to gotos at the machine code level, anyway.

Of course, you can write spaghetti code without gotos, too:
Code:
unsigned uState=0;
while(1){
  switch(uState){
    case 0:
      //stuff
      uState=2;
      break;
    case 1:
      //other stuff
      break;
    case 2:
      //land here
      uState=1;
      break;
  }
}
This is actually a construct commonly used in my line of work 0_0
I think a "break 2;" is more elegant than an inline function but eh.

Actually, I've used that structure before too...here's a shitty html parser I wrote some time ago:

Code:
void HTMLParser::Parse(std::string code)
{
	std::string::iterator oldp, curp;
	int stage;
	Element elem;
	
	oldp = curp = code.begin();
	stage = 0;
	while(curp != code.end()) {
		switch(stage) {
		case 0:
			if(*curp == '<') {
				elem.type = Element::TEXT;
				elem.data.assign(oldp, curp);
				elements.push_back(elem);
				oldp = curp + 1;
				stage = 1;
			}
			break;
		case 1:
			if(*curp == '/') {
				elem.type = Element::CLOSINGTAG;
				oldp++;
				stage = 2;
				break;
			} else
				elem.type = Element::TAG;
				
			// Fall through
		case 2:
			if(!IsAlphanumeric(*curp)) {
				elem.data.assign(oldp, curp);
				elem.data = ToLower(elem.data);
				curp = BuildParamArray(code, curp, elem.params);
				elements.push_back(elem);
				stage = 3;
				continue;
			}
			break;
		case 3:
			if(*curp == '>') {
				oldp = curp + 1;
				stage = 0;
			}
			break;
			
		}	
		curp++;	
	}
	
	if(oldp < curp) {
		elem.type = Element::TEXT;
		elem.data.assign(oldp, curp);
		elements.push_back(elem);		
	}
}
Old
Profile PM WWW Search
Mantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to beMantralord seldom sees opportunities until they cease to be
 
 
Mantralord
 
 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 02:01 PM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.