It looks like you're new here. If you want to get involved, click one of these buttons!
I think lua doesn't offer a continue statement, but would that be easy to add to Codea?
if your in a function you can "return"?
Sometimes, not always. I dont really get the motivation behind not having continue. Main advantage for me is that makes code easier to read.
I was just reading the other day that Lua 5.2 came out and has support for goto statements (I know it's heresy just to mention goto's) among other things. You could more or less simulate continue with goto if Codea moves to 5.2.
Not sure if TwoLivesLeft has any plans to put Lua 5.2 on the roadmap for Codea though.
I like goto statements. Without looking at it yet, I think we'd like to upgrade to Lua 5.2 as soon as possible.
goto is evil.
But upgrading to 5.2 won't force me to use it. :-) and y'all can learn by getting burnt.
It should be fully backward compatible, and I see "new library for bitwise operations" in the changelog, SWEET!
+1 for 'continue' inside a loop.
'goto' is evil. But conditional 'goto' is not. 'break' and 'continue' are the examples of conditional 'goto'.
In the beginning there was BALR R1, R2
AHHG! You guys like goto loops! It doesn't effect me, but it drives me crazy when people use goto. I prefer functions. I used goto when I first learned to program. I froze my computer (an eMac). Literally froze my entire computer. Back then, I didn't know why insanity meant. I kept trying to run the program and restart my computer. Eventually, I decided to look at the code. Good ol' days... :-)
Goto is easily misused, but it presents some elegant solutions to problems that have to be solved with temporary state variables. Particularly loops with multiple exit points.
Other than basic a long time ago, i've never really used goto. What popular modern languages offer it?
Generally speaking, do you stay in the same scope when going-to?
What popular programming languages have goto? C, C++,Go, Fortran, Ada... and that's just off the top my head :-)
Stay in the same scope? No, there's no need for goto in that case. Stay in the same function? Usually, but with nearly any interpreter it's important to be able to get back to the REPL to recover from an error at any stack depth. In C you do it with setjmp/longjmp, in Lua with xpcall.
heh - you skipped "modern". Fortran is lovely - but modern it ain't. Ada is... shudder... I've used Ada. With Ada it's more "what isn't there?".
The need to use goto is almost always an indicator you should rethink how you're doing your code. The places where it's an elegant solution to things are very, very rare - 99% of goto usage in a modern language that still offers it is misuse rather than use.
Agreed - except that misuse of goto by the many is a poor reason to forbid it for the 1% of cases where it does make your code more readable. ;-)
Maybe an in-app purchase for the "right" to use it? Or misuse it? :-D
I agree - with reluctance.
Goto should be in there because they put it in 5.2, end of story. But - it wasn't in 5.1 and earlier, and we were fine.
I don't like it not because it could be misused - but rather because I view Codea's place in the world (other than making money for twolivesleft) as an educational/hacking/play tool. I have the job I have today because I got an 8 bit computer and I spent a ton of time learning it, and until Codea came along, that opportunity was gone; I can see a kid spending time with Codea and learning to code and years from now pointing back at it, in the same way I point back at my Atari 400, and saying "That's the thing that put me on this career". And it would just be nice if they learned to do it without goto.
Because I had goto. I learned BASIC. And it was fun, and good, and I had to re-learn later how to do it "right". And I would spare the next generation that - bad habits die hard.
I think it's really interesting that there's someone out there making these decisions about what to include in the language and they've just now in v5.2 decided that goto should be included afterall
Agree with @bortels. Personally I haven't found any cases that exclusively need goto as the only solution. But 'continue' is still a good language construct. If it's possible, 2LL should provide 'continue' and forbid 'goto' in the next Codea update (though it would use Lua 5.2).
@ruilov: Yes, I wonder about that too. :)
Disagree there - stock Lua, most recent stable version, is the way to go. Compatability with regular Lua code is very important - I would hate to run into libraries we can't use because goto was eliminated for ideological reasons.
Well, if 2LL will put stock Lua, that's fine. But at least 2LL shouln't encourage goto usage by not mention it in the docs nor in the samples. Keep it there in the dark corners somewhere common users won't see it, but still let the advanturer users to find it. ;)
Just wanted to mention this: Why I don't want goto():
Lua has tail-call optimisation (http://en.wikipedia.org/wiki/Tail_call), which means tail calls are gotos. You can rewrite an iterative algorithm that would use break/continue as a recursive function and Lua will run it pretty much as fast as a loop (same computational complexity, any way), but the code will better express what you are calculating because the Lua interpreter takes care of how the calculation is computed.
Nat, but changing loops into recursive functions makes the code messier, longer, less natural. The main advantage of continue to me is that the code becomes shorter. Continue statements are never strictly needed, they're just nice and useful.
Edit: break statements are also not needed, but lua has them. It is truly bizarre to me that lua doesn't have continue.
How about a while...wend loop?
The only use of goto I can condone is for breaking out of a nested loop structure.
Its cleaner than using a temporary variable and checking it in each nested loop's invariant (especially so if you have even more nesting then 2 levels).
That said, lua uses gotos internally when the error function is called from a cfunction, jumping outside of the interpreter and printing the error. They have wrapped it in a well defined interface, with well defined conventions like always putting a return after the error function to indicate that your calling function will not continue executing, even though the return will never be called, so it works well.
It seems like the most elegant solution in that case.
When it comes to continue, you could structure your code like so:
do the other thing
do more stuff
it could become
do the other thing
do more stuff
There is no real need for continue as far as I can see, though there are some cases (multiple exit points) where continue would probably be nicer. If that is the case though, you are probably better off using Tail Recursion like @Nat mentioned and using return instead of continue. I've always found recursive functions easier to reason about anyway, but its a matter of opinion.
2.5 years passed. Still no goto in Codea? WTF?!
For you that may be.
You can tackle your situation without it believe me
If goto is used properly, it's no different than any other command. If used improperly, it can be a disaster in a large program when changes are required. Before I retired, I was the only programmer that used goto. That was because the younger programmers learned to program with a language/compiler that didn't allow goto's. So they never learned the proper way to use it and kept telling me I was wrong to use it. I had no problems with it. Codea doesn't allow goto's, so I have no problems not using it. It's all a matter of what you get used to.
Yeah, noobs keep saying it's not good, when it's actually them who are not good. Exactly what I had in mind, Dave.
Goto is fool programmers' code particle (I'm not saying, I'm against it) :D
Edit: goto can be a safe valve... Or an evil sink >:)
Did I sound a bit religious or mystical? [-O<
There's no case for Goto being necessary, because modern languages don't have it, and nobody notices. I'm afraid the professional concensus is that it was dangerous, so unless you think you know better than all the experts, it's brave to say that this is stupid.
(I go back a long way with basic, so I know Goto well. But I stopped using it many years ago, because I realised it did make coding more dangerous. I never missed it after that).
Do you know what Donald Knuth thinks about "goto"? ;)
Edit: is "goto" like a gun? 8-X
@Ignatz Actually every language has a goto. It's just renamed as continue, break, function, if then else, etc., and it limits where you can go to, so the programmer doesn't mess things up too bad.
Re Knuth: there's no "goto" in TeX. 'Nuff said.
I guess all that really matters is that Codea doesn't have goto, never will have, end of story...
@Ignatz: Well...unless TLL decides to upgrade Codea to use Lua 5.2 or greater.
You're forgetting the biggest goto that Codea has. It's called restart. That's just like the Longjmp and Setjmp commands in "C". It's just that we can't access Setjmp which is always set to the beginning of the code, so Longjmp (restart) always goes back to the beginning.