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
-
D--M22667yThats really dumb.
What happens if the condition never triggers? You've just locked your application. -
No its not genius. the code is fine as is. if you were to move the condition up in the while the entire block would only execute when the condition happens. let's say your condition is a button press. would still (kinda) work but as soon as you introduce more conditions let's say another key press you listen for. youre not only breaking the concept of code being modular as well as keeping code maintainable. i always like to think of while (1)s as very top level structures. they should be kept "clean" and neutral. for example you have 4 different complicated conditions. putting that into your while would make it slow, unreadable and unmaintanable.
Do some research on SOLID. -
@beggarboy I really don't get your point. Obviously i meant to put the negate (!) into the while(). If you need to add conditions just build an expression and put it into the while.
If there is an enormous number of conditions, put into while loop a function which return a boolean based on the conditions.
I think is better than << Ok now i have to read all the while loop body to understand when it stops >>
And i also think that nesting while(1) into while(1) with breaks at more levels of depth, is just hell.
But again, i think i'm missing something because i see this style more often than i expected to. -
D--M22667y@toro2k
What? Why would you have a while loop, or an if statement if the condition is always true?
Why would you intentionally write MORE code that does nothing?
The fuck?
Related Rants
Someone just explain me why. I really can't figure other reason that beeing too lazy to think a condition while writing a "while loop".
At university, a colleague asked me what i think of his code. I see something like that:
while ( 1 ){
...
if (condition)
break;
...
}
Am I a fucking genius thinking that just moving condition into while will improve readability, or am i a fucking stupid ? Really not the first time seeing this, maybe i am missing something.
rant
programming
break
while loop