Ermahgerd goto
-
And how would it work in a language with throw?
//(...) return value; exceptionHandler: throw new ArgumentException("Something bad happened");
-
Exception myEx;
int myRetval;try { ... code snipped ... } catch (Exception e) { myEx = e; } if (myEx != null) throw myEx; else return retVal;
-
Ugh. That's gonna screw up stack traces in C#
-
Ugh. That's gonna screw up stack traces in C#
Yes but it's as close to "single return only" as I could think of when adding in exception handling.
-
Exception up; int myRetval; try { ... code snipped ... } catch (Exception e) { up = e; } if (up != null) throw up; else return retVal;
FTFY
-
```
//(...)
return value;
exceptionHandler:
throw new ArgumentException("Something bad happened");You mean we have to use `goto` for that monstrosity? ;)
-
You mean we have to use goto for that monstrosity?
Of course not!
//(...) return value; } while(0); throw new ArgumentException("Something bad happened");
-
But think of the complexity that could ensue if you have multiple possible exceptions! And what if you need to handle additional logic after each of those exceptions! Much easier to just do this:
try { // All your codez return value; } catch (exception e) { // "Special" handling throw e; }
-
public object summin() { Exception up; int myRetval; try { ... code snipped ... } catch (Exception e) { up = e; } return (up == null) ? retVal : up; }
FTFY
-
That's so bad it should be hidden in a spoiler.
-
Notice how my company uses it:
http://what.thedailywtf.com/t/inner-platform-effect-sql-utilities-edition/982
-
EDIT: ANOTHER DISCOURSE BUG!!!!!!!!!!!!!!!!!!!!!
@codlnghorror said:
CLOSED: ASDESIGNEDWONTFIX
Filed under: You're Doing It Wrong™
-
Hard to keep track of all these damn bugs.
Follow the example set by the Discourse team and don't even care.
Filed under: Problem solved
-
public class ReturnValueException : Exception
{
...snip implementation...
}void myFunction() { ReturnValueException up; try { ... code snipped ... up = new ReturnValueException(...actual return value here...); } catch (Exception e) { up = new ReturnValueException(ERROR, e); } throw up; }
-
OMG MARKDOWN!!!!! Keeps removing that first section from the code block even though the preview window shows it in the code block!
Mott's First Law of Discourse: I WILL encounter a Markdown bug every single time I try to post on TDWTF.
-
Evil ideas thread is that way
-
OMG MARKDOWN!!!!! Keeps removing that first section from the code block even though the preview window shows it in the code block!
@codlnghorror said:
You're clearly Doing It Wrong™
-
It strips spaces in the first line it seems.
Just out of curiosity...
-
Discourse: Where Doing It Wrong™ is 250x easier and more discoverable than Doing It Right™.
-
Fucking broken piece of shit!
public class ReturnValueException : Exception { ...snip implementation... } void myFunction() { ReturnValueException up; try { ... code snipped ... up = new ReturnValueException(...actual return value here...); } catch (Exception e) { up = new ReturnValueException(ERROR, e); } throw up; }
So yeah, your first line of content gets trimmed, breaking the code.
-
-
There you go, just had to get mad and curse at it a bit.
-
-
Discourse: Where Doing It Wrong™ is
250∞x easier and more discoverable than Doing It Right™.FTFY
-
Doing It Right™
[quote="codlnghorror]
LIES! That's not even a thing!CLOSED: CANNOTREPRODUCE
[/quote]
-
-
Still missing 9 hours after @Keith's post.
It's like you people think I'm going to go back and revise a post I've already been called out on. That's just unseemly.
-
And how would it work in a language with throw?
You're thinking a lot harder about it than my predecessors did. There were a lot of instances of try blocks with empty or no
except
blocks (Delphi's equivalent ofcatch
mostly to swallow exceptions from failed numeric conversions and third-party components. Had you attempted to argue with them, you would probably be chided for not closing your 20 tickets* du jour fast enough, or criticized for being a slow programmer because you didn't copy-paste** a module as the starting point for your current assignment.*Some were 5 minute fixes, some were 4+ hour jobs. **"You need to make a new monthly statement report for Bazquux, Inc.? Just copy the one we did for Foobar LLC, change the fonts and a couple of the queries and it's done! C'mon, you are SO slow with these! You NEED to get these out faster. What's technical debt?"
-
...curly_loop:
emoji suggestions supplied by discourse?
Filed under: who knew? (Clearly, not me)
-
-
<?php eval("a:"); eval("goto a;"); ?>
Does that work?
-
Didn't Jeff say that quoting breaking everything was by design?
-
Both evals choke, the first on : and the second on an unexpected string.
-
Didn't Jeff say that quoting breaking everything was by design?
Breaking almost everything is by design. Doesn't make it a good design.
-
<?php a: eval("goto a;"); // undefined label 'a' eval("a: goto a;"); // works ?>
according to a commenter on the php manual page.
-
I can see the first one failing because of the implied change of scope (you can't change scopes with a
goto
) but the second should fail for the same reason.Then again I was testing with codepad.org because I was too lazy to run it locally, they might have an old version of PHP that doesn't support goto.
-
Didn't Jeff say that quoting breaking everything was by design?
He doesn't seem to care much for quotes. It's a position that doesn't seem very thought through, and all the more viciously held for it.
-
Just like the rest of Discourse then?
-
The evil ideas thread is that way
-
Or the rest of Jeff's opinions.
-
Or the rest of Jeff's opinions.
Wait, those are opinions? With all his blog referencing, I thought it was all fact.
-
You folks aren't thinking nearly evil enough.
Consider continuations (which are sort of a generalization of goto, after all)..
Now consider the call-with-current-continuation function, and the sort of havoc one can wreak with it.
Now consider PHP with full call/cc(), and allowing continuations at any arbitrary statement.
-
Considering that PHP doesn't allow unbastardised gotos anyway, and I don't think it's purely a design decision, I suspect the engine doesn't especially allow it, averting the worst possible outcome
-
You could go with coroutines instead. They're simultaneously evil and sane enough for PHP.
-
PHP 5.5 is your friend then.
-
Can you yield from a function called inside the top-level function of a coroutine? That enables much greater
evilpower of expression!
-
I haven't played with yielding and generators. I find that since I'm still struggling to herd my userbase onto current versions that it's really not worth my time to invest in playing with the shinies until they're already on maintenance-only life support.
I only just got out of the habit of writing 5.1-compatible code in favour of 5.3+ only stuff recently. Yay me and my users.
-
I haven't played with yielding and generators.
If it goes deep properly, you can use them to implement cooperative multitasking. That's pretty hairy and supports lots of evil.If you can yield from an interrupt of some kind (e.g., in a signal handler) then you can do preemptive multitasking. This would, of course, require a really top-notch implementation to not die in a miserable heap. If it works, you've got some classic evil powers at your disposal.
If you can only yield from the top-level function of the coro/generator, you've got something meh. Evil-lite. The Castlemaine XXXX of evil.
-
I'm still struggling to herd my userbase onto current versions
This is a reason why static linking is better. Drop a single executable on the server, run it, and you're done. No need to update dependencies. The dependencies are part of the executable.
-
No, not in my case. I build PHP scripts, distribute them. I can't play with anything useful because they mostly use oldschool hosts.