- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
//and by comment your code I mean sarcastically comment your code
Admin
A single flag with a single return point, a home-brew search-and-replace ...
It's like I'm really sat in front of a C64 in 1985.
Admin
Admin
FRIST! // And my 'Frist', I mean fourth.
Admin
that's not a comment. THIS is a comment!
Admin
Your mom is a comment.
Admin
Multiple return points are bad for the same reasons GOTO's are mostly bad. Also, they tend to be used a lot by people who don't know what an exception is.
Admin
If there's one redeeming quality in Java, it's that you can't do half of the things suggested in this wtf.
Admin
Admin
Admin
// reinvent the wheel
'nuff said.
Admin
The code is bad, but this bit really concerns me:
I can only guess what MatchWord must look like.Admin
Your point is well taken if you are implementing exceptions. But even in a language which supports exceptions natively, exception handling can result in much slower code. Thus, it is often not used in embedded code. In that case, I think multiple return points can actually result in much faster and more maintainable code.
Admin
At least it only has one return.
Oh wait - I don't give a crap.
Admin
The really sad part about that is, afaik, in C, there really is only one return point. A return inside the method is implemented as a goto the real return...
Admin
and in what way is that at all sad?
The problem with goto's is that developers get confused - not because there is anything actually wrong with the construct
Admin
The coding style espoused by TPD mandated all methods be commented, and those comments indicate which methods called the current method.
I never saw a TPD method comment that was anything more than a list of other method names that could have been more reliably retrieved by tapping Shift-F12 in Studio. There were certainly never any comments about what the method actually did. After all, it should be obvious from the code!
TPD did like to throw together empty, pointless wrappers (like you suggested there) quite a lot, though.
Admin
I really love how you pass by ref something that will never change, seriously that string is that long? Oh.. it changes! I realize that I made a lot of WTF when I'm on a hurry, but reinventing the weel deserves a stand up ovation!
Admin
Admin
I only suggested the pointless wrapper as a guess; my fear is that the real MatchWord makes use of the ChangeWord method in a far more convoluted and sinister way.
Admin
So anyway, if you're in the middle of a subroutine and you want to return, you can use 3 bytes to return or 2 bytes to jump to the end of the subroutine and piggyback onto its return instruction.
If you have several small subroutines all packed into one consecutive 256 byte space, they can all share a single return instruction, with the other subroutines using jumps to exit.
The mad geniuses who programmed Atari BASIC made generous use of this technique, saving dozens of bytes in total. And they had to, because by the time it was done there were (as I recall) only about 7 leftover unused bytes from the memory allocated to things like this.
Admin
What? Doesn't the library ToUpper() handle this correctly across multiple codepages? Oh, wait, I forgot, the library doesn't have a replace function.
Admin
Admin
Nagesh? Is that you?
Admin
That was of course because they also outlawed goto as in
if (someError()) { result = ERROR_CODE; goto done; } ...
done: return result;
and similar not so bad goto using patterns...oh wait this is a bit like:
try { if (someerror()) throw ERROR_CODE; ... } catch (int status) { result = status; } return result;
captcha transverbero
Admin
Thanks ToUpper()!
Admin
Hey man, love the name. But, sadly, you're a fucking idiot. I hope you suffocate on an enormous bull penis.
Admin
He probably rolled his own ToUpper() too.
Admin
If I find myself writing a method / function / subroutine which demands either multiple returns or a convoluted mess, I take a step back and see whether I might be able to refactor by extracting all the lumps between the returns into separate methods of their own.
OTOH when I'm doing parameter checks I may well have a few returns up near the top, if for some reason it's inappropriate to throw an exception:
if (inputParam == null) return;
... or whatever.
There are no unbreakable rules, not even this one.
Admin
Besides, if they were really mad geniuses they would have cached the address of the start of each FOR loop, instead of doing a line-by-line search from the start of the program for every. single. iteration.
Admin
[Wife:] "Oh, you're up already? Wow!"
Thanks, ToUpper()!
Admin
Oh and it occurs to me why they call it "reinventing the wheel".
It's because the code so described tends to be in a loop, and it goes round and round and round and round and round and ...
Admin
I'm not saying multiple returns are ALWAYS bad, especially in an embedded system without {insert several unreasonable constraints here}.
BTW, I don't like this:
I also don't like this:
Inserting a new condition beween 1 and 2 means, at best, re-indenting all that code and at worst getting completely lost.
As to the guy who asked why are GOTOs bad, well, they are bad because 99% of us aren't trying to write an operating system kernel or paying attention to how much the code is screwing with the CPU's cache in order to shave a few cycles off our 3D game engine.
Just my 2 cents.
Admin
Admin
// reinvent the troll
'nuff said.
Admin
My favorite part is the comment 'create a copy - you can't have too many copies'!
Admin
Ehm... How is this reinventing the wheel? It can do a case-insensitive replace. Does the framework support this? I don't really find this function terrible - heck if I were marking this as an exam-question I'd probably let it pass.
I am NOT trolling, OK. And for the record, if I was tasked with having to implement this function myself, I'd probably head straight to MSDN for help before starting to reinvent the wheel (to see if the framework supports caseinsensitive replaces)
Admin
Admin
Yeah yeah yeah but that's just too bleeding obvious to even mention. Doesn't anyone have a fucking sense of humour on this fucking website any more?
Admin
@Frank: Exceptions can be used to bypass the call stack, resulting in much faster result in (some) recursive functions. However, I agree that have multiple returns can make the code more readable sometimes.
@An Old Hacker: Implementation is compiler dependant, not language dependant; and I would be very surprised if compilers like GCC or LLVM implemented it using [i]jmp[\i] to have a single "return point"
Admin
If your language has scoping rules such that there's some pretty significant cleanup to be done when returning from a function (running destructors and such), then it's actually pretty likely for a compiler to have that cleanup code in there once and jump to it for every other return, instead of duplicating it for every single point of exit.
Admin
Admin
Admin
hey zunesis, someone mentioned 'tail recursion'
Admin
It's funny how Wikipedia lists "Structured Programming" as an alternative to using goto.
Admin
Wow. Real irony.
Admin
Developers blessed with The Gift should completely ignore that rule, since it tends to make crystal-clear, well-factored code even clearer, and you'll probably never need to mentally reverse-execute their code anyway.
Admin
I thought it was: Ha ha ha!
Admin
Admin
You know what? You're right. Multiple returns versus some other penultimate flow control are equally complex to solve. I stand corrected.