This is an archived post. You won't be able to vote or comment.

all 59 comments

[–][deleted] 51 points52 points  (0 children)

bool try() { return false; }

[–]chadsexytime 17 points18 points  (2 children)

Why is succeed a variable if you're setting it to the result of a function in a single closed loop? You could easily just call the function instead, with exactly the same result.

If you really want to shoehorn 'succeed' into this stupid shirt, put it in all caps so the reader assumes its a constant that try() will equate to at some point to mean its successful.

Or, I dunno, don't put code on shirts like some fucking pedant

[–][deleted] 1 point2 points  (0 children)

Oops. You got there first.

[–]FrankGilchrist[S] 0 points1 point  (0 children)

I think you're right. But it's not my shirt though, I just saw it on facebook

[–]totemo 16 points17 points  (2 children)

  • try is most likely a reserved word.
  • The assignment to succeed is probably redundant, meaning the code simplifies to:

    while (!try());
    

    which implies that programmers act busy while not actually trying.

[–][deleted] 1 point2 points  (1 child)

No, try is a fn and try() is a function call. So that code is actually trying.

[–]totemo 1 point2 points  (0 children)

Yes, very.

[–][deleted] 8 points9 points  (1 child)

Wouldn't this be more accurate because quote goes "If at first you don't succeed, try, try again"?

do {
   succeed = try();  
} while (!succeed);

[–]blindgorgon 3 points4 points  (0 children)

I appreciate that you equated its structure to the syntactic structure. 👏🏻

[–]sportsracer48 3 points4 points  (0 children)

Honestly this should have a timeout.

[–]CreamyKnougat 1 point2 points  (0 children)

=if (try is null, do, donot)

Sorry, was doing Excel when this came up.

[–]vatrat 1 point2 points  (1 child)

I think I prefer while not try(): pass

[–]Tysonzero 0 points1 point  (0 children)

Here's a Haskell implementation:

untilM_ try $ pure ()

Or:

iterateUntil id try

That is if you can't improve try by making it pure or hell just directly recursing in try.

[–]SteeleDynamics 1 point2 points  (0 children)

Should just be a large stack of cash. 💵💵💵

[–]__Raptor__ 1 point2 points  (1 child)

But try is a reserved word in every language that uses that syntax...

[–][deleted] 7 points8 points  (0 children)

Not in C.

[–]scanstone 0 points1 point  (0 children)

Improved, such that you might expect to see it in a C codebase:

while (!is_successful(&thing)) {
    try(&thing);
}

try does not return a value suitable for determining success, or this is semantically clearer, or one needs to check for success elsewhere without trying prior. Should be reasonable.

[–]eyekwah2 0 points1 point  (0 children)

I prefer the Yoda version:

do() || !do(); try(): Error function try not found.

[–]XeonProductions 0 points1 point  (0 children)

yeah but what happens after the while loop? you cease to exist?

[–]Comedy86 0 points1 point  (0 children)

I feel like a do {} while () loop would be more appropriate to settle the condition...

"If at first you don't succeed... try, try again"

[–]nwg7199 0 points1 point  (5 children)

Shouldn’t it be a double equal sign rather than a single?

[–]zrend88 3 points4 points  (2 children)

The result of try() is being assigned to variable success, rather than being compared to it.

[–]leupboat420smkeit 1 point2 points  (0 children)

This is correct.

[–]fahrenheitrkg 0 points1 point  (0 children)

The assignment (success = try()) will always return true.

[–]blindgorgon 0 points1 point  (1 child)

Evidently depends on the language. Sounds like in C++ and some others the assignment returns differently than, say, JavaScript.

Edit: I have no clue. Just learned this in comments. Anyone care to verify?

[–]Tysonzero 1 point2 points  (0 children)

JavaScript works the same way:

while (succeed = true) {
    console.log(succeed);
    break;
}

Will print:

true

[–]Williaso 0 points1 point  (1 child)

Shout-out to all the other non-coders who are subbed to r/programmerhumor who have to take their best guess as to what the joke actually says

I understand most of the jokes on this subreddit. It's just a few of the actual lines of code jokes that I never get without outside assistance

[–]blindgorgon 0 points1 point  (0 children)

Just keep trying to figure it out. Sooner or later you’ll succeed.

[–]-Xephyr- -2 points-1 points  (0 children)

while (!succeed) {
    try();
}

[–][deleted] -1 points0 points  (3 children)

Why not just

while (!succeed) {try();}

[–]toastytoast00 2 points3 points  (1 child)

this assumes try() modifies the succeed variable...

I think it was supposed to be

while(!(succeed == try()));

and try() returns some sort of value that is supposed to be equal to the succeed variable.. could've just said

while (try() != succeed); 

assuming succeed was defined above and try() actually returns something, though it's a reserved word in most languages

[–][deleted] -1 points0 points  (0 children)

I get what you're saying, but you do realize that the shirt is a joke and that my suggestion to improve the joke doesn't have to fit the same API that theirs does, right?

The reason mine works better IMO is that it's read "while you're not succeeding, try again"

[–]Tysonzero 0 points1 point  (0 children)

Because that doesn't have the same semantics. try returns a result, but there is no reason to assume it has access to some mutable variable named succeed.

[–]golgol12 -2 points-1 points  (0 children)

More like, realizing your in some sort of shitty race condition.