Announcement: Remember: you are giving away your fantastic ideas for free, and somebody else might even make money from them (or appear to). That's just how the world works! If you're worried about it, maybe you shouldn't post your ideas here.


Caravel Forum : DROD Boards : Feature Requests : Loops in DRODscript (Wanted For a While.)
New Topic New Poll Post Reply
Poster Message
hyperme
Level: Smitemaster
Avatar
Rank Points: 1062
Registered: 06-23-2006
IP: Logged
icon Loops in DRODscript (+1)  
Currently you can made loops in DROD using go tos and ifs. But Goto is considered harmful, and also nested loops end up hard to read.

While is simple I think, since you can just do the If.. type syntax. For loops might need new interfaces.

Break and Continue would also be nice for completeness.

Obviously, End Loop goes at the end of a loop.

(While and For should make If Lines with End Loop if they become a thing.)

____________________________
[Insert witty comment here]
Qzvlkx?
10-15-2015 at 07:38 PM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
Banjooie
Level: Smitemaster
Avatar
Rank Points: 1645
Registered: 12-12-2004
IP: Logged
icon Re: Loops in DRODscript (0)  
Someone briefly fill me in on why GOTO is harmful?
10-15-2015 at 08:59 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
Pinnacle
Level: Smitemaster
Avatar
Rank Points: 1129
Registered: 06-10-2004
IP: Logged
icon Re: Loops in DRODscript (+1)  
https://xkcd.com/292/

____________________________
Once (adv.): Enough.
Twice (adv.): Once too often.
~Ambrose Bierce, The Devil's Dictionary
10-15-2015 at 11:10 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Someone Else
Level: Smitemaster
Avatar
Rank Points: 1300
Registered: 06-14-2005
IP: Logged
icon Re: Loops in DRODscript (0)  
To be slightly more wordy, it's because goto breaks regular program flow, so if there's a bug it's nearly impossible to track down. Also, if there's a possible exploit, it's much harder to spot. It's valid in exactly one case, IIRC: to break out of multiple nested loops.
10-16-2015 at 05:02 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Loops in DRODscript (0)  
hyperme, skell and I held an extended conversation about this while hyperme helpfully prototyped some options.

hyperme has completed an implementation called "Goto Smart" that essentially provides some classes of streamlined scripted control flow for 5.2. (A big "thank you!")

PR


Edit: note how execution flow conventions like for/while/break/continue/switch/case are actually gotos in disguise. But they're "smart" gotos...and they're not called "goto", so that makes them okay in everyone's eyes. Hip developers love to hate on goto.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 10-19-2020 09:02 PM]
10-19-2020 at 08:55 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Loops in DRODscript (0)  
@hyperme, is there a way currently implemented to not display the smart Goto labels in the selection list (see CCharacterDialogWidget::PopulateGotoLabelList)?

In RPG, we don't want these options to be selectable for the "Each attack/defend/use" jumps.

Option: Maybe have these options greyed out for these specific script commands?

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 11-10-2020 02:17 AM]
11-10-2020 at 02:17 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Someone Else
Level: Smitemaster
Avatar
Rank Points: 1300
Registered: 06-14-2005
IP: Logged
icon Re: Loops in DRODscript (+2)  
mrimer wrote:
Edit: note how execution flow conventions like for/while/break/continue/switch/case are actually gotos in disguise. But they're "smart" gotos...and they're not called "goto", so that makes them okay in everyone's eyes. Hip developers love to hate on goto.

To be a little pedantic: Underlyingly, they're jump commands. Yes, they could be simulated with gotos, but a jump command is not equivalent to a goto (or else you would have included if and function calls in your list). Goto, in the common(ish) parlance, really refers to unrestricted goto which cannot be replaced by one of the usual constructs.
11-10-2020 at 03:29 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Loops in DRODscript (+2)  
Someone Else wrote:
a jump command is not equivalent to a goto (or else you would have included if and function calls in your list).
Hmm...actually, I just cited a few examples, based on the context of what we're talking about in the topic. I didn't exclude these on purpose.

I'm interested in being educated on what you're describing here. How are if and function call jumps not equivalent to gotos under the hood?
Goto, in the common(ish) parlance, really refers to unrestricted goto which cannot be replaced by one of the usual constructs.
Ah. Good to know.

It seems that by this you mean that unrestricted gotos are the most powerful and flexible form of jump. Which makes it a bit easier to shoot yourself in the foot. Am I getting that right?

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 11-10-2020 07:12 PM]
11-10-2020 at 07:09 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Someone Else
Level: Smitemaster
Avatar
Rank Points: 1300
Registered: 06-14-2005
IP: Logged
icon Re: Loops in DRODscript (+2)  
I was going to post a long detailed argument, but then I looked up jump commands and realized I was wrong. :blush

mrimer wrote: It seems that by this you mean that unrestricted gotos are the most powerful and flexible form of jump. Which makes it a bit easier to shoot yourself in the foot. Am I getting that right?
More or less, yeah. The resistance to GOTO is about managing complexity, because you can't do that easily if you can just jump to anywhere in the code. That's why we have all the syntactic sugar; it's to make it easier to not write a whole pile of spaghetti.

There's also the bit about GOTOs making lots of things harder: it's harder to write tests and it's harder for the compiler to optimize (because you have fewer guarantees about what values variables can take), and it's harder to prove your code works as intended (because you don't have encapsulation).
11-11-2020 at 07:06 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
skell
Level: Legendary Smitemaster
Avatar
Rank Points: 3734
Registered: 12-28-2004
IP: Logged
icon Re: Loops in DRODscript (+1)  
I'd argue that for an average person resistance to GOTO is axiomatic, they saw that GOTO is evil and never stopped to think about it. Beyond that I agree that in modern code in modern machines there is really no place for GOTO.

I am fairly sure it still has its place when programming micro-controllers and other things where you have extreme limits but since I haven't worked on those that's pure speculation.

____________________________
My website | Facebook | Twitter
11-11-2020 at 08:37 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts High Scores This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD Boards : Feature Requests : Loops in DRODscript (Wanted For a While.)
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.