[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Why does my CS professor say that break, goto and continue statements

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 44
Thread images: 2

File: Capture.png (521KB, 737x528px) Image search: [Google]
Capture.png
521KB, 737x528px
Why does my CS professor say that break, goto and continue statements are bad style, /g/?
>>
>>60075248
Because academia is full of mental-masturbators who have never worked irl projects where your (((boss))) wants everything done by the weekend...
>>
Well for one, goto is a great way to create marvelously unreadable code. Try it. Use it a bunch on a big project, forget about it for a week and then come back. Try and read your code. You'll be lost
>>
>>60075278
This. Goto sucks
>>
>break
Good in C programs, bad in business or phone software where exceptions are king and if-else statements are not used for imperative/functional reasons.

>goto
Literally gotos a specific line of code. You're not on ASM, don't do this.

>continue statements
Same as why break is bad.
>>
Break and continue aren't bad unless they're abused.

>>60075285
>gotos a specific line of code
C doesn't work like this.
>>
Because he's not a programmer.
Academia is where you go when you can't make it in the professional world.
Like they say, if you can't do, you teach.
>>
File: 1444698625104.png (250KB, 550x535px) Image search: [Google]
1444698625104.png
250KB, 550x535px
>>60075248
>break and continue are bad style
I understand goto but I don't know what's so bad about break or continue.
>>
Goto should be obvious. It's hard to read, and there's just no reason to use it over some if statements or break statements.

Break is fine in most projects, but really only for small only-can-occur-here type of unexpected behaviors where it's just unnecessary to make a new exception and try/catch statement just for this, especially when it's something minor. It's not fine when you're dealing with actual errors or major problems; those should get fixed, not avoided.

Continue is fine for if something was already "handled" and you don't want it to "handle" it again. I mean, it could be avoided by using a huge if statement, but it is more readable to put one if statement and a continue statement inside a large loop block. Continue isn't fine when you have some extra "if this also needs to be done" type of thing, as that could just be put in another method and be handled with an if statement.
>>
>>60075320
Goes to a specific function, my bad dawg.
>>
>>60075405
It's called a label. A function is completely different new friend.
>>
You should ignore anyone who tells you not to use break or continue, as there's not really a better way around them. They're perfectly fine constructs, and break is outright mandatory in C if you use switch statements. Most uses of goto are better accomplished with proper control flow, however, and abuse of goto can lead to the some pretty ugly spaghetti code. Regardless, there are at least two good uses of goto that warrant their continued existence in the C programming language. The first is escaping out of a nested loop, and the second is for dealing with error recovery, where one or more objects may need to be de-allocated, closed, etc... It may make sense to put some cleanup code at the end of the function, that you can just jump to instead of cleaning up and returning in some if statement every single time you come into an error.
>>
He is too busy being a cucked professor instead of making $200k in industry. He likely has no idea what he's talking about. The industry and its standards changes so quickly that something he thought would be static is now gone and forgotten.
>>
>>60075511
kill yourself
>>
>>60075248
They lie to you. Jews hate efficient code.
>>
>>60075248
while True:
if condition:
break

What's wrong with this?
>>
>>60075278
Creating a bunch of retarded objects is also bad though, doesn't mean oop is total garbage. Goto is fine for a few things like parsers and error code returning/cleanup.
>>
>>60075405
Your fucking retarded dude not even asm works like that
>>
>>60076825

Pretty much, it's good when it's the best way to solve a problem. But it's bad when it's used to solve problems that have more elegant solutions. Just so happens it's usually easier to do something the wrong way and have it blow up in your face later.
>>
>>60076857
Agreed but there's something weird where academia made this cargo cult around "goto considered harmful", and remove the context to just mean goto it's bad full stop -- it's not.
And it's weirder that goto is basically this gigantic boogey man while other complicated shit, students have no business doing, gets a pass
>>
>>60075248
>break
>continue
>bad
anyway goto isn't bad either if you only use it in C for early returns with resource cleanup
>>
>>60076822
because you can just do
while not condition:
brainlet
>>
As long as it doesn't make your code unreadable and unmaintainable it's fine.
>>
please don't respond to bait
>>
>>60076955
while !a || !b || !c || !d || !e || !f
>>
>>60077257
I don't know if you're trying to make a point with this but that is retarded as fuck.
>>
>>60077276
>that is retarded as fuck.
that's the point i was making
>>
>>60077285
That's horrible design, the only point you made is that you are incapable of critical thought.
>>
>>60077296
stay retarded I don't care
>>
>>60075387
Code flow should be easily transferable to a functional style. You can't use continue or break in LISP
>>
>>60075273
Don't listen to this bullshit.
Bosses who want everything done yesterday for half the price are the reason we have shitty software that is impossible to use or maintain.
You have a responsibility as a software craftman to refuse to cut corners.
Would a surgeon agree to stop washing his hands before performing because management told him to?
>>
LMFAO not a single fucktwat here gets it. No wonder since we are on the board that considers Rust and functional programming to be the pinacle of software engineering.

Break, continue, goto and midway returns are discouraged only when you need to formally prove your algorithm with Hoare calculus, but it is all the better when you actually implement your crap on the machine. Break, continue and goto are mere jumps in assembly (return is similar). They are perfect for performance and not that unreadable (goto is fine for putting all your cleanup code at the end of a function).
>>
>>60075248
>goto and continue statements are bad style
Because they've never written a line of practical code in their life.

The real skill is to know when a goto statement is absolutely NECESSARY.
>>
>>60076955
what if the condition is not available at the outer level of the while statement?
>>
>>60079506
Using a boolean variable.
>>
>>60079521
why would you expose an otherwise useless variable to the top level?
that is just bad design
>>
>>60079554
Not him, but it's actually good and ideal design, not to mention more readable.

if
A && B && C
implies a condition isGood to be true, it is far more readable to create a top level (top in relation to the loop) member for readability and possible continued use.

isGood = False
while not isGood:


is much better than relying on breaks especially if you have multiple statements that go into determining the boolean value of isGood, because in a week or two looking back on all those breaks will make you wonder what you were thinking, let alone if you are working with somebody else.
>>
>>60079817
Obviously in the case the other guy presented with A || B || C it would change corespondingly, but you get the idea.
>>
>>60075248
because you morons aren't able to discriminate between good uses and bad uses yet, so he has to give you a blanket statement, so that you don't shoot yourselves in the foot
>>
>>60076955
Pretty much this >>60079506 >>60079554
>>
>>60079872
Pretty much this >>60079817
>>
What is a good way to implement finite state machines without gotos?
>>
>>60075248
>Why does my CS professor say

Maybe (you) might ask him?
>>
>>60079817
>>60079892
Here's some magic.
if condition //isGood == true
Thread posts: 44
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.