Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-02-2008, 05:16 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
goto

Hi,

a goto command for gs2 would be nice :o
__________________
Reply With Quote
  #2  
Old 02-02-2008, 05:37 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Explain?
__________________
Reply With Quote
  #3  
Old 02-02-2008, 05:39 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
well like

PHP Code:
function onCreated()
  {
  if( 
foobar )
    goto 
blub;
  
player.chat "d";
  }

function 
onPlayerChats()
  {
  
Label blub;
  
player.chat "c";
  } 

and it will go to the script part where the label blub is and continue there, so if foobar is true the player will say c @ onCreated
else he will say d, but when foobar is true he wont say d at any time
__________________
Reply With Quote
  #4  
Old 02-02-2008, 05:49 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by projectigi View Post
well like

PHP Code:
function onCreated()
  {
  if( 
foobar )
    goto 
blub;
  
player.chat "d";
  }

function 
onPlayerChats()
  {
  
Label blub;
  
player.chat "c";
  } 

and it will go to the script part where the label blub is and continue there, so if foobar is true the player will say c @ onCreated
else he will say d, but when foobar is true he wont say d at any time
well, I don't see any use of it tho Unless you give other examples :o
__________________
Reply With Quote
  #5  
Old 02-02-2008, 05:58 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
I am 100% completely against this idea.

This completely kills the idea of object-orientation.

This is what we have functions for.

You couldn't even justify goto in GS1, let alone GS2.
__________________
Reply With Quote
  #6  
Old 02-02-2008, 06:29 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
There is absolutely no need for this. You have functions and event triggers for a reason.

goto only really works in completely linear languages, of which GScript is not one.
Reply With Quote
  #7  
Old 02-02-2008, 07:00 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
goto's are only useful ( really ) when you want to break out of two loop controls. They are quite obfuscating otherwise. Additionally, there are numerous reports telling us that the more goto's there are in a code, the higher the complexity is.

Plus... There'd be quite a bit of problems with the environment change ( change in function / object / scope ). It's best not to use it at all... In ANY language -- Even ones that support it. The MAJORITY of the cases, they can be completely avoided. In cases that aren't... You could just make a function-call... using return foo();

If you really want to understand... Just imagine Zodiac if goto's existed.
Reply With Quote
  #8  
Old 02-02-2008, 07:28 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Absolutely not.
__________________
Reply With Quote
  #9  
Old 02-02-2008, 08:08 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
Quote:
Originally Posted by Novo View Post
goto's are only useful ( really ) when you want to break out of two loop controls.
right, its quite annoying to check for a flag each time you have 2+ loops :P
or something like a breakall; that would just kill all the loops instead of the one you are in

basically what you're saying is kinda weird, that sounds like just because c++ has goto's every game only uses them instead of loops
__________________
Reply With Quote
  #10  
Old 02-02-2008, 08:42 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by projectigi View Post
right, its quite annoying to check for a flag each time you have 2+ loops :P
How does that have anything to do with wanting "goto"?
Quote:
Originally Posted by projectigi
or something like a breakall; that would just kill all the loops instead of the one you are in
It's called "return", and will end function execution there and then, regardless of how many loops you have.
Reply With Quote
  #11  
Old 02-02-2008, 08:46 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
Quote:
Originally Posted by Skyld View Post
How does that have anything to do with wanting "goto"?
PHP Code:
for( foo 0foo 100foo++ )
  {
  for( 
bar  0bar 100bar++ )
    {
    
mehfoo ][ bar ] = blub;
    if( 
/* do something that would exit the loop */ )
      goto( 
lEndL01 );
    }
  }
Label lEndL01:
//after loop 
Quote:
Originally Posted by Skyld View Post
It's called "return", and will end function execution there and then, regardless of how many loops you have.
you don't always want to end the whole function :P
__________________
Reply With Quote
  #12  
Old 02-02-2008, 08:48 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by projectigi View Post
PHP Code:
for( foo 0foo 100foo++ )
  {
  for( 
bar  0bar 100bar++ )
    {
    
mehfoo ][ bar ] = blub;
    if( 
/* do something that would exit the loop */ )
      goto( 
lEndL01 );
    }
  }
Label lEndL01:
//after loop 
you don't always want to end the whole function :P
Then structure your code better.

You could easily have those two loops in a function by themselves, and use "return" to end there, and send back the result of your function execution to the calling function.
Reply With Quote
  #13  
Old 02-02-2008, 08:49 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Skyld View Post
It's called "return", and will end function execution there and then, regardless of how many loops you have.
Example:

PHP Code:
function onCreated() {
  
foo bar;
  var = 
2;
  
doLoop();
  
doOtherThings();
}

function 
doLoop() {
  for (
010i++) {
    for (
010j++) {
      if (
this.stuff[i][j])
        
doLoopThings();
        return;
      }
    }
  }

__________________
Do it with a DON!
Reply With Quote
  #14  
Old 02-02-2008, 09:24 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
Quote:
Originally Posted by Skyld View Post
Then structure your code better.

You could easily have those two loops in a function by themselves, and use "return" to end there, and send back the result of your function execution to the calling function.
if i put every loop into a own function, reading a code with 1000+ lines will kinda be annoying lol
__________________
Reply With Quote
  #15  
Old 02-02-2008, 09:36 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by projectigi View Post
if i put every loop into a own function, reading a code with 1000+ lines will kinda be annoying lol
Usually you can find a way to actually make it look better.
__________________
Do it with a DON!
Reply With Quote
  #16  
Old 02-02-2008, 10:32 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Perhaps break uint; to end 'uint' loops.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #17  
Old 02-02-2008, 11:17 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Graal has survived without goto and it will continue to do so despite your wishes. You need to structure your code better rather than ask for goto.
__________________
Reply With Quote
  #18  
Old 02-03-2008, 12:56 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
goto would be a complete nightmare when trying to read code.

Think about it; in languages such as BASIC they have it, but that is not object oriented, and does not have functions.

Think about this ...

function foo() is called. It goes to CAT which is in function bob(), which goes to DOG which is in function moo() ... then eventually does it go back to the original function foo()? Or does it keep advancing?

And THEN, what happens if you GOTO a function, and then the function ends? Your whole script has stopped.

That's not the way GS2 is supposed to work. After you call one function, it goes back to the function it was in before when it's completed. This is how it should work. goto would completely screw this up.

In Java, goto is actually a reserved variable name (you cannot name a function or variable it). I guess they REALLY don't like it.

If you need to quit a loop, return is your best option, or to use a variable I suppose.

Simply structure your code better is my suggestion.
__________________
Reply With Quote
  #19  
Old 02-03-2008, 05:22 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
In PHP you can break out of multiple levels of loops by just going "break 2;" for two levels, "break 3;" for three levels, etc.
__________________
Reply With Quote
  #20  
Old 02-03-2008, 07:13 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Based on a Case-Study done in Code Complete 2ed, by MSPress... This is what they concluded about the use of goto's:

( pg. 408 )

Quote:
The Argument Against gotos

The general argument against gotos is that code without gotos is higher-quality code.

The famous letter that sparked the original controversy was Edsger Dijkstra's "Go To
Statement Considered Harmful" in the March 1968 Communications of the ACM.
Dijkstra observed that the quality of code was inversely proportional to the number of
gotos the programmer used. In subsequent work, Dijkstra has argued that code that
doesn't contain gotos can more easily be proven correct.

Code containing gotos is hard to format. Indentation should be used to show logical
structure, and gotos have an effect on logical structure. Using indentation to show the
logical structure of a goto and its target, however, is difficult or impossible.

Use of gotos defeats compiler optimizations. Some optimizations depend on a program's
flow of control residing within a few statements. An unconditional goto makes the flow
harder to analyze and reduces the ability of the compiler to optimize the code. Thus,
even if introducing a goto produces an efficiency at the source-language level, it may
well reduce overall efficiency by thwarting compiler optimizations.

Proponents of gotos sometimes argue that they make code faster or smaller. But code
containing gotos is rarely the fastest or smallest possible. Donald Knuth's marvelous,
classic article "Structured Programming with go to Statements" gives several examples
of cases in which using gotos makes for slower and larger code (Knuth 1974).

In practice, the use of gotos leads to the violation of the principle that code should flow
strictly from top to bottom. Even if gotos aren't confusing when used carefully, once
gotos are introduced, they spread through the code like termites through a rotting house.
If any gotos are allowed, the bad creep in with the good, so it's better not to allow any of
them.

Overall, experience in the two decades that followed the publication of Dijkstra's letter
showed the folly of producing goto-laden code. In a survey of the literature, Ben
Shneiderman concluded that the evidence supports Dijkstra's view that we're better off
without the goto (1980), and many modern languages, including Java, don't even have
gotos.

The Argument for gotos

The argument for the goto is characterized by an advocacy of its careful use in specific
circumstances rather than its indiscriminate use. Most arguments against gotos speak
against indiscriminate use. The goto controversy erupted when Fortran was the most
popular language. Fortran had no presentable loop structures, and in the absence of
good advice on programming loops with gotos, programmers wrote a lot of spaghetti
code. Such code was undoubtedly correlated with the production of low-quality
programs, but it has little to do with the careful use of a goto to make up for a gap in a
modern language's capabilities.

A well-placed goto can eliminate the need for duplicate code. Duplicate code leads to
problems if the two sets of code are modified differently. Duplicate code increases the
size of source and executable files. The bad effects of the goto are outweighed in such a
case by the risks of duplicate code.

The goto is useful in a routine that allocates resources, performs operations on those
resources, and then deallocates the resources. With a goto, you can clean up in one
section of code. The goto reduces the likelihood of your forgetting to deallocate the
resources in each place you detect an error.

In some cases, the goto can result in faster and smaller code. Knuth's 1974 article cited a
few cases in which the goto produced a legitimate gain.

Good programming doesn't mean eliminating gotos. Methodical decomposition,
refinement, and selection of control structures automatically lead to goto-free programs
in most cases. Achieving goto-less code is not the aim but the outcome, and putting the
focus on avoiding gotos isn't helpful.

Decades' worth of research with gotos failed to demonstrate their harmfulness. In a
survey of the literature, B. A. Sheil concluded that unrealistic test conditions, poor data
analysis, and inconclusive results failed to support the claim of Shneiderman and others
that the number of bugs in code was proportional to the number of gotos (1981). Sheil
didn't go so far as to conclude that using gotos is a good idea—rather, that experimental
evidence against them was not conclusive.

The evidence suggests only that deliberately chaotic control structure degrades
[programmer] performance. These experiments provide virtually no evidence for the
beneficial effect of any specific method of structuring control flow.
—B. A. Sheil

Finally, the goto has been incorporated into many modern languages, including Visual
Basic, C++, and the Ada language, the most carefully engineered programming
language in history. Ada was developed long after the arguments on both sides of the
goto debate had been fully developed, and after considering all sides of the issue, Ada's
engineers decided to include the goto.
I hope that gives a premise of debate on the topic.

If you wish to read more on the topic, you could read it, if you register for free, using the http://cc2e.com/ website.
Reply With Quote
  #21  
Old 02-03-2008, 03:49 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
Quote:
Originally Posted by cbkbud View Post
goto would be a complete nightmare when trying to read code.

Think about it; in languages such as BASIC they have it, but that is not object oriented, and does not have functions.

Think about this ...

function foo() is called. It goes to CAT which is in function bob(), which goes to DOG which is in function moo() ... then eventually does it go back to the original function foo()? Or does it keep advancing?

And THEN, what happens if you GOTO a function, and then the function ends? Your whole script has stopped.

That's not the way GS2 is supposed to work. After you call one function, it goes back to the function it was in before when it's completed. This is how it should work. goto would completely screw this up.

In Java, goto is actually a reserved variable name (you cannot name a function or variable it). I guess they REALLY don't like it.

If you need to quit a loop, return is your best option, or to use a variable I suppose.

Simply structure your code better is my suggestion.
C++ is OOP and they have it :P
__________________
Reply With Quote
  #22  
Old 02-03-2008, 03:53 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Basically all the arguments FOR goto can be done with functions, and the rest of them don't really apply to Graal.

Gotos are largely used in languages with no functions or logical structure.

EDIT:
Yes, C++ has it, but if it was added into Graal it would just be a mess. I'm not saying it would be bad for every object oriented programming language, sorry if it came out that way, but it would mean searching through code to find that label, or however you do it, and then executing from there. The if the function ends, the code stops, because he was saying that he wants it to break from loops. Here is an example:

PHP Code:
function onCreated()
{
  for ( 
temp.foo )
  {
    if ( 
temp.== "bar" )
    {
      goto 
crap;
    }
  }
  
player.chat "gah"// won't happen
}
function 
myHouse()
{
  
label crap// however this is done
  
player.chat "yey im out";
// osht, the code is done running. 
__________________
Reply With Quote
  #23  
Old 02-03-2008, 09:35 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by projectigi View Post
C++ is OOP and they have it :P
Much like saying cocaine abuse is around us. Doesn't necessarily mean we should use it.

I generally prefer to steer clear from gotos. Functions are much better to use.
Reply With Quote
  #24  
Old 02-03-2008, 10:49 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Codein View Post
Much like saying cocaine abuse is around us. Doesn't necessarily mean we should use it.
It doesn't? That guy in the white Sedan was lying to me!
__________________
Reply With Quote
  #25  
Old 02-04-2008, 12:30 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
C++ supports a very limited version of "goto", of course you cannot jump into other functions or even outside of the current scope (when you have declared variables). The compiler is basicly breaking the code down to several if-else statements. That is exactly what you should do too, it will make the code look more clean.

In some other languages you can break a specific loop by adding a label in front of the loop and then saying "break labelname". It might be easier to stay with stuff that everyone knows though, makes code more readable instead of introducing a lot of GS2-specific constructs.
Reply With Quote
Reply


Posting 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 +2. The time now is 07:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.