Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Prutser2228yGood way to teach, teacher!
I've been taught that it should be avoided as much as possible, because it disturbs the flow of the program, decreases readability and increases the chance of introduces strange bugs.
And to be honest: I haven't seen any c# code where it would be necessary/useful. -
All these anti-goto evangelists are responsible for all the boolean vars with if section you could have avoided with a simple GOTO! They all just repeat a phrase someone told them like "no fart'n burp in public" without thinking about it! It is possible to abuze goto, but they are to dumb to explain.
-
Prutser2228yAlso... as a quick example based on your "making one loop instead of two":
- Using goto requires conditions to determine if you need to go back to the loop. If you don't cover all the angles, then you've basically got an infinite loop. Covering all angles inside a large application can be quite a big task.
- If an exception is triggered inside your loop, which iteration of the loop triggered the exception? The first time or the goto-one? -
@Prutser You don't neccessarily need conditions for that, it depends on the loops though. And the debugging is fairly easy, if an exception is thrown, because of Checkpoints.
-
@Prutser Disturbs the flow? Not quite: Visual Studio autonatically indents them differently.
-
@alexanderholman I only use goto if it shortens my code by a few lines, and I also indent it. So far, there have been no problems in readability. Of course, you shouldn't overuse/abuse goto.
-
Prutser2228y@filthyranter it sure depends on the situation if you need conditions.
I assumed the next situation:
-Loop
-Some code
-Goto Loop
In that case you do need conditions.
And I didn't mean indentation when I talked about the flow of the application. I meant the path the code follows during execution.
Anyway... personally, in your given example, I would put the loop in a method and just call the method when the loop is needed -
mrstebo9308yThe one thing goto is good for, is for allowing you to go on a nice little adventure through your code. Reminds me of the text books at school... go to page 50, go to page 185, etc... (Maybe eventually leading back to page 50) 😱
In my whole 10 years developing I have never been in a situation where I thought "goto" was the best solution 😬 -
boottape1008yIf your teacher can't give you proper reasoning for anything then why don't you google and see what experienced devs say. That way you should be better prepared for the outside world.
Sidenote: I've never saw a goto statement in production code, nor have I ever thought to use it. Most cases I'd imagine you're breaking SOLID in some way or another. -
Not only goto should be avoided but loops too. In C# it's shorter and simpler to use IEnumerable extensions or linq. Much cleaner, shorter and more readable also it allows parallelism if you'd like. Loops are "low level" constructs that may help in optimizing some complex iteration, but even then there's probably a better way of doing that.
-
@StefanH I was about to say something similar. TL;DR, I think goto is an easy fix for bad design.
I have used goto once in an FSM, where after implementing almost all of the state machine I realized that I needed to double the amount of states with nearly identical states. The proper way to fix it would have been to start over and find a better representation, but a simple goto saved my ass and let me continue on with the existing design without duplicate states. It was no longer an FSM and the logic behind everything became a lot more complex, but it saved me time. -
@Prutser there's actually one, pretty rare, situation in C# where a goto statement is the recommended course of action, which is falling through switch cases.
-
I felt exactly the same for the first time, but functions are better and easier to follow than GOTO
-
stisch48148yGoto gets a bad rap. It solved one of my biggest computer science problems: others messing with my code
-
Well, at least some of you guys had reasons behind why goto isn't too good for you, but for me, it's very useful.
-
@filthyranter can you show an example where? Maybe I can show you a better approach or maybe you'll enlighten me.
-
rmahey5988y@filthyranter
It is okay to be wrong, you will learn soon, that GOTO is a construct inherited by many languages by older ones who did not have better systems in place to cope with such situations. Today, GOTO is NEVER a good option. Perhaps you feel emotionally negative towards this teacher thus attempt to rebel their advice - do not let it be so. See the truth fore it enlightens you and without it you will not grow.
Related Rants
-
elgringo41Student - Teacher renaming .c to .exe make the program executable ? Teacher - Yes A group of people stand up...
-
kescherRant14Our programming teacher had a surgery on his left eye and will not be able to do the lessons with us. Guess wh...
-
sam966931Difference between C# and Javascript Me: Hold my cup of tea. C#: That's not a cup of tea. Me: Hold my cup o...
So, the other day, my teacher told me not to use goto in C#, with only the reason that "it is bad".
Okay teacher, I'm going to continue using it until you give me a valid reason. For example for making one loop instead of two. .-.
undefined
teacher
goto
bad reasoning
c#