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
-
From what I know, it doesn't make any sense whatsoever. I mean I understand what she's trying to say but that statement doesn't make sense
-
The while loop is not fully declared and assuming try() doesn't fail unexpectedly 'succeed = try()' would evaulate into true which would in turn just eval to false because of the ! which would cause the while loop not to run, ever.
-
As far as i understand this she's trying to assign a not further declared method to a variable. This could work if try() returns a Boolean i think. Though this whole loop is kinda messed up.
It's obviously more about the message than being written correct. -
@WhAtEvErYoUmEaN so basically she's saying that we all should just give up and don't try even once. Just like turn around and walk away again.
-
@KittyMeowstika let's hope she's not a cs graduate though. Because that would be a little embarrassing
-
woops83456y@nicogramm that's why i i stared at it for 5 minutes, she is a CS graduate.
well i guess she wanted to say while !(sucess){try;} but that assignment had me like what the shit is am i disabled and forgot the fundamentals -
@KittyMeowstika which would mean that success is defined outside of our scope and try() accesses it or outside of the call stack. So her code is bad in every way.
I propose:
while(goal.attemptToReach()){
if (goal.attemptSucceeded)
{
break;
}else{
goal.strategy = new Strategy();
}
} -
@WhAtEvErYoUmEaN reminds me of the different StackOverflow devs: you would definitely be the certified i-follow-every-coding-convention type xD
-
Help me out here:
Try returns false , it became true because of !, And the while executed one more time. This time try returns true, it became false and while stopped.
Seems okay to me. -
@rookiemaverick we don't know the data type if succeed or what the return value of try()'s gonna be. but the process of assigning a value to a variable evals to true if it succeeds.
-
It does make sense
In C:
(Succeed = try()) is an expression which evaluates to the new value of success
!(...) is 0 if '...' was 1 otherwise 1
And then just a simple while loop
So it's saying
While(try() evaluates to not 1) -
woops83456ywhy would someone assign the return value to a variable on a while statement?
why not jut while !(try()) assuming try returns a value -
@WhAtEvErYoUmEaN and that kind of code is useful especially for error handling in C, it seems
-
@Bitwise But there is no inside of this while loop. It is terminated with a ; right after declaration.
If it really is valid code I'd say it's a very bad way if putting it that requires an overly amount of time to understand and maintain. -
@j4cobgarby I definitely learned something today...
1: This is possible and valid
2: Never write code like this. -
@electrineer you're right sorry, I was being stupid, I got it right in the first sentence though xD
-
@WhAtEvErYoUmEaN from wikibooks.org:
An expression statement consists of an optional expression followed by a semicolon (;). If the expression is present, the statement may have a value. If no expression is present, the statement is often called the null statement. -
Succeed keeps getting assigned to the result of try function. If it returns null, the loop is broken out of.
-
I guess I won't be touching C anytime soon. Sweet sweet high level managed languages it is for me.
For now. -
@Bitwise or then try() just returns some useful value like the grade and it's used later.
-
sSam14836y@electrineer it can be really good code depending on the context and since there's no context, there's nothing to discuss as it CAN be sensible.
-
taglia5716yDoes REALLY anyone have never seen stuff like that?!
This is also valid in Java (or, at least, it was with SE 7):
while((line = br.readLine()) != null){
// Do stuff
}
The loop's condition is always evaluated, so the function "try()" is executed at least one time. If that functiom returns false, the loop is executed one more time. This means "if you fail, continue trying until you succed".
She totally deserves her graduation.
Jesus, you are all arguing on what that try function returns. STOP BEING ASSHOLES, this isn't StackOverflow. The concept of that code is really simple (and syntax is correct too), so please stop wasting time arguing about bullshits.
Peace.✌ -
benrooke836yThe semicolon makes sense to me, that’s a way to block execution without actually writing a loop.
-
benrooke836y@Bitwise
A while loop with just a semicolon and no body is a common practice for blocking execution until the condition is false.
I understand that it’s valid. I don’t think you and I disagree. -
catadoxa4166yI am amused by all this debate when you could, like, test it?
It looks like C to me and it looks like it should work fine. To make sure, I wrote it up and ran it. Of course you have to define 'succeed' and 'try()', but once you do it absolutely runs exactly the way she intended it to. I actually think it is kind of a pretty cool line of code, although I can't think of a use case offhand. Also seems like perfectly readable and understandable C code that would not throw me at all if I ran into it in a code base. -
there is nothing wrong with the code. the try function might be actually returning any kind of data type. maybe a boolean ( false ) if something goes wrong in the try function and also a useful information to work with
while ( ! ( success = try () ) );
( sucess = try() ) expression is first of all executed, the value of try() is assigned to sucess if that value is false the while loop will continue until the value of success is something else. it is still the same thing as
var success = try();
while ( ! success ) {
success = try();
} -
benrooke836y@NoMad
This is best understood with semaphores, in my opinion. Imagine you have a portion of a function that has a critical section, it might be written like this:
// Entry Section
wait(S);
// Critical Section
if (0 < V)
V--;
// Exit Section
signal(S);
But what does that wait(S) call do? There’s probably a while loop terminated with a semicolon, like this:
while(!lock.attainedLock()); -
devios157016yIt makes sense in C. It’s a while loop that does nothing but continuously check a condition. That condition assigns a success value (presumably) to the success variable, which also becomes the result of the assignment in C, which checks whether it is != 0 then flips it with the !.
I’d say it’s legit. The semicolon is the body of the loop but it does nothing. All the logic is in the condition. -
Sefie16446y@j4cobgarby
Php, C# and Javascript handle the statement likewise, if I recall correctly. And AFAIK there is no need for a loop body in those language.
So it's barely readable and awful style, but technically correct in at least 4 languages. -
NotARobot536y@NoMad WHY DID YOU TAG MY USERNAME ON DEVRANT FOLLOWED BY A NUMBER, FELLOW HUMAN? I DON'T UNDERSTAND, PLEASE HELP ME UNDERSTAND.
-
thecrius76y@j4cobgarby I was beginning to go crazy. Thank god there is someone that still know how to code.
You can definitely assign value in a evaluation and evaluate the resulting assignment. -
@Sefie I think it's quite elegant code, if you wanna see some horrible syntax then:
int**(*f)(int**,int**); -
justmove7316yboolean succeed = false;
while(!succeed) {
succeed = try();
}
guess you can do it like in the rant but it's more readable this way -
@justmove not quite the same, you'd have to set the initial value of success to try() instead of false
(Also tempted to point out 'false' isn't valid in C, but I'm not entirely sure it this is C) -
geaz2896yTotally valid code. In most languages. It hasn't an empty while body. The body is just pulled into the while expression. So literally just another way of writing:
while(!succeed){ succeed = try(); }
The original code is also way neater. But ok... -
Nah it makes sense. If she trys and it returns false, she failed and the loop goes again. If try() returns true then she succeeded and she can stop....
I mean personally I try to keep pushing through the good times and the bad, but hey, whatever floats your boat. -
Ummmm...
While (!succeed) { try(); }
While (!(succeed = try()))
Even someone who doesn't code would be able to guess which one is right... -
First of all, apart from the empty body, assigning return values inside the conditional part of the loop is a common way in most dynamic languages. In PHP it is the norm for traversing many collections:
while( $row = $stmt->fetch() ) {
// do something with $row
}
The fetch method gets the next row in the result until the end of the result set, in which it returns false to indicate EOR (end of results).
Also, as I see others rewrite the given example to be:
while( !success ){ try(); }
I see infinite loop, unless they access "success" as a global variable inside "try()". Not a good rewrite at all, but I'll give the benefit of the doubt about pseudo code, even if they took the code written literally.
I also agree that the code as written has many uses for blocking/waiting. It also bears similarities with the run-loop for games and other gui applications that wait for the user to do stuff, and depending on what, quit the app by exiting the loop.
(and yes, pseudo code)😉
// init stuff
while( runloop() );
// cleanup on isle 3
bool function runloop(){
// do lotsa stuff
// if abort by user return false
// else react to user bs
// sleep some short time
// return true
} -
meyhem2236yIt does make sense, in C. It has sme redundancy but its a valid code. Assignment is also an expression so the fllow is following.
1. Call try()
2. Assign its retudn val to var succeed
3. Expression of assignment is value assigned itself
4. negate the expr value
5. you know what while does, so... -
Sefie16446yMy coworker pointed out the real issue here: try is a reserved keyword in most languages and may not be used as a function name.
-
This kind of statement is also often used to read files
string line;
while ((line = file.readLine()) != null) ...
Saw a girl from my uni upload a photo of her graduation with the following text:
while(!(succeed = try()));
I'm staring at it for 5 mins and i can't figure out if i'm retarded and should drop out of uni or that statement doesn't make sense.
random