- 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
My "nope" was "no, a bug is not necessarily a wtf". Certainly there are plenty of "holy cats, what on earth was that guy thinking" moments that are also bugs - but there are plenty of bugs that are just bugs - you say "oops", you fix them, they go away, done. And there are plenty of examples of working code that make a reasonable person's eyes bleed when they look at the source. I know two people who work in MUMPS, and the stuff they describe would make you weep, rend garments, gnash teeth, and so forth, but the stuff does what it's meant to.
So a bug is not necessarily a wtf, though it can be, and a wtf is not necessarily a bug, though it can be.
Okay?
(captcha is "appellatio", which is either a very literate sex act of the name of a manservant in a very posh sort of manor, or both)
Admin
Ow. That phrase seems to have set off a migraine. Not a good day to be me. Maybe I'll go delete Wikipedia. It won't last, but maybe it'll help.
Admin
That's just bloat within a method; I was expecting a 5-level hierarchy of decorators on top of a base implementation of AbstractBeanFactoryConstructorIterator. And reflection. And modifying bytecode. And aspect-oriented cross-cutting every which way.
Oh wait, what language is this again? Oops... I guess complexity is a lot less, err, complex in the C#/.NET world. :)
Admin
Your advanced sarcasm spotter (ASS for short) is defective. Or is mine? I can't tell anymore.
Admin
I think that's one point to me, then.
And watch what you say about my ass.
Admin
Actually, your "nope" was quite right. I was wrong, originally. Hence my re-wording.
You and I are saying the same thing: not all bugs are WTFs, but some are. I get that. No confusion there. The original guy I replied to (way back when) and highphilosopher seemed to assert that bugs and WTFs are mutually exclusive (see his post if you don't believe me), which is downright bonkers. I was merely prodding them for clarification.
Admin
Admin
Quick rewrite:
private void SetRequisitionItem(RequisitionData.RequisitionItem requisitionItem, AccountData.Account account) { if(account == null) return; requisitionItem.AccountID = account.ID; requisitionItem.AccountCode = account.Code; }
Changes:
All branches set the boolean to true, so I removed all branches that dealt solely with setting boolean. Since the boolean is always true, there's no need for it. Just set the values. Instead of nesting all the code inside a != null, I inverted the if and skipped out. I removed the boolean from the method protocol. I renamed the method. You're not setting the account: you're setting the requisition item ;)
One question: did the code originally do something more complex, but then got morphed into this monstrosity?
Also, haven't they ever heard of ReSharper? It would have figured this all out and turned your code into what I said.
Admin
So you're not only changing the function name you're also changing the number of parameters and leaving out an additional function call (IsAccountCodeNull())
Have fun fixing the rest of the code that these changes may have broken.
At the simplest this could be
if (account == null) return requisitionItem.IsAccountCodeNull(); requisitionItem.AccountID = account.ID; requisitionItem.AccountCode = account.Code;
Admin
Admin
Admin
Well, removing the "superfluous" logic would at least make it more obvious that those checks aren't being done in a useful manner as intended. It might make the bugs (if that's what they are) easier to recognize.
Admin
Except that if FILE_NOT_FOUND is non-zero, then the rest of the ELSE IF statements will never be evaluated. "if (42)" should be at the top of the block.
:)
Admin
That was my point. If the problem with the code is the architectural complexity, why not show that? Like someone else already said, show us the aspects cross cutting whichever way they want. Show us the sixteen decorators around SomeClassWithARidiculouslyLongNameForClarityAndDocumentingPurposes.
Instead, we get a simple example of some code that was just a leftover nobody dared fix or a misguided attempt to forsee the future. Sure, a small WTF, but has nothing to do with the architectural stuff the article laid out at first.
Admin
True genius!
Admin
Basing this choice on speed of processing is what I would call premature optimilization. The point of the choice I make is maintainability. The next guy may actually be an ok programmer just not a great programmer. Maintainable code is always better than code which is theoretically better. I'm not saying you have to write things poorly, I'm just saying some choices are unfortunate but better for maintainability.
Admin
If you are iterating through a C++ collection using a loop you should always use ++iter rather than iter++, because the latter will make an unnecessary copy of an object.
Remember that C++ has operator overloading. Pre-increment is
Post-increment is
where inc() is whatever is necessary to advance by one.
Admin
Admin
Admin
Admin
Admin
i hate seeing stuff that reminds me of my own occasional bad code.
Admin
I can almost guarantee that the code had control paths that set it to false in the past, but the that the requirement changed over time causing programmers to go in and change them to true one after another, until it ended up in its current state.
Admin
Well, if your performance is measuremed in lines-of-code, then code like this just flows naturally.
Admin
Admin
Even if the compiler optimizes it away, it still adds unnecessary complexity and strain on the compiler
Admin
http://www.sofunjerseys.com
Admin
It's likely the code originally had both true and false sets, but was modified (either by a developer for debugging/testing purposes, or by a nub who didn't understand it, or as the result of a defect).