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
-
He's stupid.
Breaks aren't always stupid. Of course, you shouldn't use it in nested loops, but they have their proper use-cases. -
@filthyranter well in java you have labels for loops so you can break to a specific loop but at school we learn c#...
-
break, continue, and return all have their uses; some uses are better than others. And there is always someone smarter than you who can refactor them away.
-
I don't know the context, you'd like to reduce nesting and continues, but ideally as long as you're not using goto, I'd be mostly fine with it as long as it can't be rewritten in simpler manner with or without break.
-
@bkwilliams I love those words. There’s always someone smarter than you who can refactor. Truth.
As long as they teach me what they did though haha -
I thought putting breaks was a bad practice. In most cases is just bad logic from the programmer.
-
@HelloIsItMe I very much agree. There are some cases where breaks make sense, but thank god for the beauty that is `continue`. I find I use both of them the most when I am writing parsing code, as for some kinds of data the best way to handle invalid data seems to me (I’m self-taught, so take with a grain of salt) to be to ignore it and move on. Better to have something kinda work than crap out on the user.
Related Rants
So my dear programming teacher really hates break statements... I mean really really really. He thinks it's better for readability if you don't break from any kinds of loops (not even ifs) well then we came across a switch statement in class. He says "breaks only exist because it's needed in switches" well how about returning from a fcking swith? or goto? then you need no break...
Is there anyone who could explain why I should NEVER use breaks and why it's bad in any piece of code? Why is it better to just use whiles because fors are apparently evil again? Srsly I just wanna ask him to show me some big code bases without breaks...
undefined
c#
break