i must say that what you have just said is something i have dealt with a lot (not necessarily on smilebasicscource) but from people who take more focus to your mistakes then the help you are requesting. i do assume you are led to this post because of the response that one guy made to me in trying to help someone learn how to situate control inputs in his text based game, and i brought up the goto command because i remember that when i first started with smilebasic i would structure my code with goto commands so isolate specific points in the program that were intended for certain tasks. i later found the flaws with this and have recently began a project with a more understanding way of structuring the code (specifically using def functions to complete tasks that i used to use gosub for, such as a def function i call UP or LEFT or to more complicated things such as CRAFTCHART or SAVEDATA(wich actualy does a lot more then saving data) ) . but the main reason i recommended the goto command was it is (in my opinion) the easiest way to create a loop wich he would need to ensure that his game wouldn't run to end itself . i fully agree in what you said.
Anti-Goto Sentiment Considered Harmful
Root / Site Discussion / [.]
Very often on this site I see replies to beginner programming questions of the form "use functions instead of goto" or "goto is messy and will ruin your life" regardless of the actual situation and question presented.
Often this message is even approved by others who will also lend criticism of the evil Go To statement, further derailing the thread from its initial intent. Initially I did not think much of it -- of course some of the community would be familiar with Dijkstra's writings, and the questions were usually answered satisfactorily by others.
My first remark is that when we talk about questions on the forum we are usually talking about people new to programming. In this community, "new to programming" can mean as young as 10 years old. The GOTO statement in SmileBASIC is nice for beginners because as a single instruction in a small program it is simple. "Continue execution from the label specified." It is not too hard to imagine that a beginner is at first concerned with getting things to work in this "simple" way more than working with unfamiliar constructs such as function calls that we eventually take for granted. It is more than enough to try to understand whatever topic their question was about without having the entire structure of their program condemned. I would also point out that there are plenty of ways to write messy code despite (or, in spite of?) using DEF routines, and adopting DEF does not cure bad practice. As a side-note, I have seen the same comments when using subroutines with GOSUB, as if these are equivalent structures. While functions are preferred to GOSUB in most cases, note that they do not exhibit the same corruption of our ability to understand the static program that Dijkstra argued of Goto, because they, unlike GOTO, must return control back to the point they were called.
My second remark is that, even assuming we would like to urge beginners towards the use of functions and cleaner control flow (remember, label-based GOTO does not suffer messiness to the same degree as Dijkstra's Goto!), the comments I have seen advocating it do a truly awful job of it. Rather than demonstrating the use of a DEFined routine to answer the question with the nudge that it would be more suitable, I see comments meaning as much as "your code is bad." On occasion an obtuse example might be provided, but never an actual explanation of functions, and very rarely a working code example is given using a subroutine-based approach.
I think my point is this: Programming Questions is not a place to flaunt your intellectual superiority. Simple answers are often the best answers, and more often than not it's more appropriate to approach questions as logic questions rather than whole-code solutions anyway. But if you ARE going to suggest abolishing Goto (to someone who doesn't know better), you should at least explain functions sufficiently, to avoid the immediate consequence that Programming Questions becomes a meaningless set of half-answers and frustrated learners.
(I am hoping to publish a resource on the use of functions in SmileBASIC shortly, something that seems to be lacking and may help bridge the gap for learning programmers)
In fear that I be misinterpreted (though perhaps that's what I deserve for writing an opinion piece),
This isn't a call to attack people for critiquing code style and structure, or for suggesting alternative methods nor is it in any way meant to defend GOTO -- Goto for control flow is undesirable, there is no argument about that.
It is solely a reminder that not all users here are at the same level, and that "use functions" is generally not a valid answer to a question.
GOTO is bad, so is GOSUB (I can go off about parameter passing, return values, polluting the global scope, and recursion if you want). You are actively doing a fellow coder a disservice if you don't point out such things.
Imagine a young woman trying out a new gym. She tries the free weights and a meathead comes over. He tells her that her form is wrong, then offers to help. She thinks he is mansplaining and trying to hit on her and decides to join a different gym where men aren't allowed to grunt. A month later she is in a doctors office getting a hernia looked at. Turns out even though she didn't like it, the meathead was being friendly and helpful. Doing things her way got her a heap of pain.
Likewise, a toddler might cry if you yell at them when they try to put their hand on a hot stove, but it was still the right thing to do.
Frankly, I don't think you are giving the ten year olds enough credit. They can memorize their times tables, state capitals, and hundreds of pokemon, but a half dozen looping construct are too much? Really? The new coders can ask for help or elaboration on topics they don't understand too. People will rise to meet a challenge if you let them. You don't need to start a witch hunt for replies you don't agree with.
It seems I can't win. If I leave it short and say please don't do that, it is too terse. If I explain what else is available and why it is better, it is too long. I get berated for trying to put out leading questions that can lead to further conversation too. But hey, if you want to make a thread criticising me go ahead. You can even call me out by name.
Coding is nit picky, and an echo chamber of pleasantries isn't really helpful to anyone.
yikes, now I have to defend myself or become a traitor...
warning: highly opinionated
Label Loops vs Standardized Loops
note: Labels can be used for more than loops, please do so.
Label loops have a somewhat subtle beauty in their readability. As WHILE follows an 'Add 1 for infinite loops!' scheme, label loops are inherently infinite without extra changes.
When it comes to conditional loops, however, the standard loops win in readability. I wouldn't want to read IF !A<C THEN GOTO @LOOP instead of UNTIL A<C.
Also something that is acceptable about label loops: They are named by nature. This means you can merge your description comment into your loop, adding some more readability.
Conclusion: Please don't use label loops unless it's just an infinite loop, it doesn't work with BREAK and looks bad if it's conditional.
Labels vs Functions
If you're calling a subroutine more than once, or it takes values and acts based upon them, then use a DEF. If you're just redirecting to a piece of your game code to clean up your main loop, use a label and GOSUB.
There are many exceptions to this, but I'm not writing anyone else's code so I'll leave it up to you.
Using Labels as Skips, not Loops
I have used an additional label instead of a complicated set of conditional breaks in my FOR loops multiple times. I think this is the only 'true' use for them, but you can decide for yourself.
When your GOTO @IS_BAD:
When a program is structured in a way that everything and anything has its own set of labels, you've probably gone too far. This is messy and unreadable in its own way, leaving artifacts of old and broken loops leading to unplanned execution of subroutines.
Conclusion: Take a deep breath, and start reassembling your puzzle. Add comments too while you're at it, so you can make sense of it later.
Just make it readable
Please, for the love of SB, take advantage of the functions available to you. SPANIM exists for a reason, please remove those sets of @CHRWALK0. Use FOR instead of your REPEAT/INC mashup.
Conclusion: If your code looks bad, then please attempt to fix it.
- chicken
Don't use label loops, kids!
yikes, now I have to defend myself or become a traitor...The above sounds like it comes from a very healthy community (sarcasm). This site should be advocating structured programming and getting people ready for advanced languages, and concepts (object oriented programming for example) instead it is engaging in ancient holy wars. I especially like how 12ME21 had to edit his post. So now my problem is simply not helping fast enough. See what I mean when I say I can't win with you guys? https://www.atariarchives.org/basicgames/showpage.php?page=3, again this is the sort of code you are advocating when you suggest GOTO. Anyone care to read through that and answer me one question? What algorithm is it using to generate the maze? Frankly, I consider this whole thread harmful. If people are teaching bad coding practices they do deserve to get corrected, not mollycoddled.
This site should be advocating structured programming and getting people ready for advanced languages, and concepts (object oriented programming for example) instead it is engaging in ancient holy wars.As a former 10-year old myself, I disagree. This website is called SmileBASIC Source for a reason. The internet is a wide place, filled with tutorials from people who know what they're doing. We don't need to teach them, because it's already out there, and better. Google is everyone's friend, even if you forget to use it every now and then. EDIT: to clarify, oop is nice, but we have to remember that not everyone uses N# - some people just want to make a game.
as a former 10-year-old myself, i have to agree with you, chickenThis site should be advocating structured programming and getting people ready for advanced languages, and concepts (object oriented programming for example) instead it is engaging in ancient holy wars.As a former 10-year old myself, I disagree. This website is called SmileBASIC Source for a reason. The internet is a wide place, filled with tutorials from people who know what they're doing. We don't need to teach them, because it's already out there, and better. Google is everyone's friend, even if you forget to use it every now and then. EDIT: to clarify, oop is nice, but we have to remember that not everyone uses N# - some people just want to make a game.
Not everyone uses SmileBASIC to prepare them for "advanced languages," they use it for fun. If you visit this thread you will see most people already have experience in other languages. There's always going to be continuous learning with programming and the beginners will learn at their own pace. You can't omit the basics and assume everyone is going to have an easy time learning the more advanced stuff. It took me a while to move beyond label loops but again, I did it at my own pace. Let others do the same.yikes, now I have to defend myself or become a traitor...The above sounds like it comes from a very healthy community (sarcasm). This site should be advocating structured programming and getting people ready for advanced languages, and concepts (object oriented programming for example) instead it is engaging in ancient holy wars. I especially like how 12ME21 had to edit his post. So now my problem is simply not helping fast enough. See what I mean when I say I can't win with you guys? https://www.atariarchives.org/basicgames/showpage.php?page=3, again this is the sort of code you are advocating when you suggest GOTO. Anyone care to read through that and answer me one question? What algorithm is it using to generate the maze? Frankly, I consider this whole thread harmful. If people are teaching bad coding practices they do deserve to get corrected, not mollycoddled.
surprise
You also don't have to download/use programs that use label loops!(In reply to seggiepants)
It's still not about saying GOTO is okay. It's about [that] being a whole 'nother thread and something they will learn when they get there.
I don't think refraining from trying to get someone to revise their programming practices is the same as "suggest[ing] GOTO," either.
You said "an echo chamber of pleasantries isn't really helpful to anyone" but that's not what I'm trying to propose either. I don't care if someone is harsh or unpleasant to someone looking for help (maybe that person does)--you could be as rude as you want if you're actually helping with the problem they have. Using the text adventure example...
"Text adventures are hard to do right and you'll never make a good one, so you should just give up now" is 'bad' but "Text adventures are hard and to make a good one you need all of these systems<...> otherwise I hope you're happy with garbage that no one will play" is full of needless words but nonetheless still has the informative content.
"goto is bad" is just one of those things where it's almost always irrelevant, but, because of the popularity of an old debate, happens to be something that comes up frequently here.
Some of your other arguments are very strange or misinterpretations so I think I won't address them unless you still have concerns...
(in reply to lumage)
It doesn't seem that you understand my arguments. Let me try one more time to break it down into small chunks.
- GOTO is bad. This has been well known for decades. The title of the thread even shows that you know I am right, so why are you fighting me?
- It is bad to teach bad coding practices to new coders. GOTO in particular will lead to new coders making messy unmaintainable code. This in turn quickly leads to frustration and quitting prematurely. GOTO should be actively avoided.
- Putting sample code online invites code review. Using GOTO when a more a appropriate construct is available will cause people to point out the mistake. The GOTO argument comes up frequently because the site is effectively causing it to. You should should stand by the code reviews and advocate good coding practices. Ignoring the problem doesn't make it go away, instead it festers.
- Yes, it is nice if the reviewer says how to fix a coding problem. However, the problem still belongs to the person who made it, not the one who pointed it out. It is the coder's responsibility to ask questions and research if they don't understand the problem, not the reviewers.
- You are "shoooting the messenger" when you blame the reviewer for the problem. If a reviewer notes a problem, you deflect it back at them by saying the reply is either too short, too long, or you make up a reason to shoot it down otherwise (you aren't the only one doing this). Basically the real message is constructive criticism is not allowed. (this is the echo chamber of pleasantries part)
- You should be on my side. Not posting passive-aggressive Mean-Girls-esque threads calling me out. Tell the complainers to expect code reviews and to stop using bad code constructs. Encourage growth.
- There is a group-think problem on this site. Anything that doesn't match the group think seems to be enough to brand someone as a traitor. The group think usually matches what the admins think or are assumed to think. Even when it is demonstrably wrong (like say GOTO use). You have a small army of white-knight, boot licking, notice me senpai followers who feel it is their duty to punish the wrong-think for you. This is very bad.
- Do I want to study this?
- Will a degree in this field help me find a job?
- Can I stomach doing this 8+ hours a day 5 days a week until retirement.
I'm sorry that you have (understandably, in context) taken this as a personal attack on yourself (or your beliefs, as it may be). It really was not the intent to single you out--I stated sincerely when I said that this was a pattern I had seen show up more often than necessary, and if it happens that all of those instances I have seen were you, I didn't make note of it.
Maybe it looks like I'm instituting a "rule" or something with this post because I'm the head maid. That is not the case. I would have liked for it to be a reminder about how the community as a whole answers questions, but, thinking that no one would read it, I copied the style of a certain arrogant prick (Dijkstra). This may have impacted its reception very poorly, and for that I apologize.
I'm not going to try to convince you otherwise at this point if you believe that I'm saying that code criticism is not allowed, and I'm not going to try to convince you to stay, so... I hope you find someplace more enjoyable for you.
As somebody working on my computer science degree in university,
Yes, GOTO is bad. But that's not the point. We can teach that GOTO is bad later on. The fact is that you can't cram everything into someone's head at once. You start with the basics: elementary flow control, conditionals, subroutines. Then you move on to the more advanced loops, like WHILE and REPEAT. Only once you get comfortable with those do you switch entirely to them. Bad practice is taught at first, and only later do you move on.
In my formal classes from a very well respected university, you know what they teach first in C? Put everything in main(). Why? Because while you're learning if statements, you don't have time to learn about functions. Once functions are taught, you move on to getting code out of main(). It's how learning works.
Not critiquing someone's use of GOTO is not "preventing them from learning." In fact, it's enabling learning by providing higher rewards and not cramming information.
This proposed hivemind with Lumage as its queen doesn't exist.
I was referring to my defensive stance in my earlier post because I had made several comments and replies (and even a page) simply guiding against using label loops.
I don't use GOTO aside from skips. My code's problem isn't that it has GOTO (because most of the time it doesn't), it's not that it's unmaintainable, it's that it is sometimes just an indented mess to me.
I add comments.
Others add labelled subroutines.
It's not necessarily just "oh GOTO is bad" when we look past the true group-think that is "good coding practice."
You don't need it for everything, and most SB games aren't made to be maintained anyways.
i wish people would put out less effort proving they are right and put out more effort listening to the other side of the table. last i checked, forums were for discussion and providing information for those who don't know the answer to a particular question or want to discus about a topic of interest. instead people would rather try to tell people their wrong and try to tell them how to live their life. if a kid, or teen, or adult wants to make a goto @loop then let them. its their code. their game. they are putting out the hours to make that game and when they are finally happy with how the game looks and plays, they upload it and post the key. and people see it, they play it and have their thoughts. then they take a look at the code and all hell breaks loose. they begin criticizing poor developer 234 for having a goto loop in their programming, then try to tell said developer how to be excepted in the society. as a result developer 234 begins to close out the forums and stops their coding career that they spent so long working toward.
what i am trying to say is if people would be less hell bent on proving their right and telling people they are wrong, maybe there will be more people willing to put out the effort to learn. as stated in this forum, people learn at their own pace. as a fellow 15 year old may learn an average of one coding technique a day, i, also being 15 can learn things a bit faster then other people. that doesn't change the fact that i use a GOTO @GAMELOOP. it is an easy and simple way to keep the game running. i no longer really use goto here and gosub there. i use defs, but i didnt get into that until a few weeks ago despite getting smilebasic in January of this year. in any case, i will code my games the way i want to. developer 234 will code the way they want to. and you will code the way you want to. thats the end. if someone has a question about how to get something working, then help them as well as giving your suggestion. dont completely dodge the question to take the advantage to completely downgrade the asker from "beginner" status all the way to "fetus in development". maybe then will people get more progress and learn and gain the experience necessary to be excepted by the community.
now im prepared to be personally assaulted by at least 1 guy with too much free time and told to piss off in the nearby corner but it doesnt change the facts. i am not saying i am correct, but merely that people need to look at both sides of the situation before griping about all is wrong with the world.
then they take a look at the code and all hell breaks loose. they begin criticizing poor developer 234 for having a goto loop in their programming, then try to tell said developer how to be excepted in the society. as a result developer 234 begins to close out the forums and stops their coding career that they spent so long working toward.Developer 234 could have had a nice life, but he used GOTO, and therefore put way too much work into the code, trying to 'live up' to the other Miiverse programs with subroutines and animation cycles done completely through labels. 234 has a smart brain and a bright future, but the poor dev doesn't know of a magical button that can fix everything... Welcome to the help button. With this cute little guy, anyone with a DS and a brain can understand the function of a loop. "Wait!," said Developer 234, coming back at the last second. "I have a brain! And a 3DS!" Good job, 234. Now we can begin the simple process of teaching you how to use loops.
well i must admit that your turn to my statement brought a laugh out of me but i do seem to realize that its not about having a brain, its about progressing at your own pace. if dev 234 wanted to make his game with a goto loop, it was his choice. i do notice you mentioned a gosub for animation? i do find that kind of outrageous and for that i share your point of view. i manage my sprite animations with a def for 4 directions and a chunk of code before the button imputs. i dont use spanim, at least not yet, but i never used goto for sprite animations.