- 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
Fixed?
Admin
Hmm... Someone deleted the "how to gracefully fail on NULL" thread?!?
I had intended for my previous answer of emulating SQL's null logic (any 'operation' on a null operand would return a null result, except for specific comparison methods) to be a discussion generator, since i'm actually interested to see what potential drawbacks this strategy might have...
Admin
Admin
Electronics engineers, but I agree. It was very ad-hoc. I suppose the thought was "Oh, it's just software, we can do that."
Admin
As far as value types in C# go, you can just use the "?" operator to make an value-type object nullable.
e.g.
Admin
And this is exactly why it is a WTF. You've already had a half dozen people claim you could reduce the code to two lines. IF this was a bug, you just made it worse by ripping out all the unused logic.
But if it isn't a bug (or the specs changed and all code paths should be set to true) then it is a WTF for leaving complicated code in. The code is complicated enough and hard enough to maintain, don't make it more complicated with unused logic.
TRWTF is some people don't think this is a WTF
Admin
Admin
Admin
SPICE?
Admin
might as well add some things to confuse the reader as well
and so forthAdmin
Admin
Well, assuming Java (and no operator overloading):
Obviously, if you know IsAccountCodeNull() has no side effects, you can eliminate that, too.
Admin
These psuedo-logic control-flow-begging-to-be-deleted snippets are my favorite WTFs. This one from our codebase isn't that bad but I still got a chuckle from it:
As a friend of mine said, "IF ELSE: UR DOIN IT WRONG"
Admin
So they set some properties in a copy of requisitionItem. Yeah you can do that, but later when they try to use it wonder why the properties aren't really set.
Should have passed ref requisitionItem
Admin
Compilers don't look at the text at all. They look at the generated AST that is unambiguous.
Although you are correct about the side effect issue.
Admin
Admin
Admin
They'd better not match. What if x is a function call?
Admin
It's amazing (troubling) to listen to them go on and on about how their solution is better and more flexible than the simplified/refactored method. They will contend that in the long run, if anyone ever needs to change it, having the code written this way will save boatloads of time/thinking/testing.
As a result, you get bloated, overly-and-unnecessarily-complex codebases, much like the one the submitter is describing.
Admin
davidh
Admin
In C++, the following definition of x() makes those statements compile just fine:)
int y = 0; int &x() { return y; }
This is why I don't do C or C++ any longer.
Admin
Out of curiosity:
do you guys think it's bad to slap IEnumerable onto all of your delegator classes (so that their delegatees can be accessed)? I think the for each loop and shorter iteration code when I consume the class later makes it worth it, but I wonder what other people think.
In my context, I do a lot of API writing for internal consumption (in mission-critical apps), and I suspect someone lower on the food chain will have to maintain this crap in future years. Do you think it's business-justified?
Admin
So why does he start off with "architectural complexity" and large projects etc. and then all this is is some unnecessary code, which is either a leftover nobody dares fix or some misguided attempt to foresee the future? Where's the architectural complexity here? Where are the layers upon layers upon layers that are not needed?
Admin
I've already written a compressor that takes any arbitrary file, encodes it as a bunch of C statements and appends them inside a new else...if clause on the end of your sample code, then passes it through a compiler, and it works brillantly! I'm having a little trouble debugging the decompressor, but I'm sure I'll be able to figure it out soon enough. Anyone got any venture funding...?
Admin
Actually, why? There was no spam, trolling or dead horses in them (at least in the first few messages I saw before they were deleted).
Is it because they mentioned "heretic" languages such as C++ and discussing how they're different, and perhaps sometimes better than TPTB's favorite languages?
Well, I must say the quality of this site is really going downhill lately. First the articles, full of non-WTFs and bad copy editing, then the comments turning into a troll/meme fest, and now censorship(?), in one of the few threads with actual content (and perhaps interesting discussion).
Yes, I know, an unregistered user shouldn't complain, but in this situation I don't really feel like registering. And I also expect this comment will be deleted.
Admin
javac does very little optimization, it just translates into Java bytecode. The actual optimization happens in the runtime compiler, where it has access to the machine architecture that it is running on as well as the execution profile of the code. The runtime compiler will definitely take the unneeded branches out, and (since it has access to the code as it's actually running) can also verify that any method calls have no side effects.
Unfortunately, there isn't really a good way to observe the results of the runtime compilation, but you may be able to see the difference in speed for "always false" vs. "randomly true or false".
Admin
Tbh, this looks like the business rules have been changed over the years. The code is very precise, clear structured and well documented. So yeah... You will always find something like this in any code in a changing domain.
Admin
Admin
Admin
You best be trolling, boy.
Admin
Yes, a lot of the discussion about the difference between handling nulls in Java, C# and C++ were deleted. This was a discussion, not spam, and should not have been deleted off. Whilst not directly related to the article, it was a spin-off discussion about the check for null in the function (the one check it appears we need to retain).
I am getting fed up of the over-moderation here. The comments are a conversation that starts with the article and are not necessarily our opinions of the article. It is fun also making comments on what the people above you have posted.
Not sure what he wants us to post exactly. Surely everyone can see what the WTF is and what a better solution would be. If it's not obvious to everyone reading it's not a WTF.
Admin
no. ++x x++ may behave very differently.
http://en.wikipedia.org/wiki/Increment_operator#Increment_operator
I prefer x++ simply because it is the most used form. Even if you think ++x is better you should assume the next programmer is a self taught programmer who learned [c|Java|C#|...] from a ... for dummies book last night while waiting for his illegal porn torrents to finish downloading.
Admin
Admin
Admin
Admin
Exactly. He's going to dumb it down anyway. Why do his work for him?
Admin
But now that you've mentioned the subjectivity of that choice, i really like the "++x" form, since it doesn't need to save the "pre" value and pass it as result. The memory and speed saves are minimal, i concede, but why choose waste simply because "everybody else does it"? :) I fail to see the relevance of that "self-taught" "next guy": if he doesn't know of preincrementing, he should learn about it.
Admin
You're right that each of those will result in "INC x"
However the issue with ++x and x++ is when nested in larger statements.
y = x++; vs. y = ++x;
The result would be the equivalent of y=x x=x+1 vs. x=x+1 y=x
Which means your INC x is either before or after your assignment.
Either way it's really all beside the point.
The real question is, when an optimizer is fed a branch where both branches result in the same code (whether they look the same or not), will it remove the branch.
Obviously in a case like if (doesErrorExist() == true) then return true; else return true; if should NOT optimize it out as doesErrorExist() results in a code jump that may have side effects.
But in the case of bool isError = doesErrorExist(); if (isError == true) then return true; else return true; there is no code jump during the evaluation of the conditional so no chance of side effects and it could be 'safely' optimized out.
Now obviously I'm not suggesting the approach of "well it doesn't matter since the compiler will optimize it away" as it is very bad form to leave superfluous code in place simply because you're too lazy to remove it (especially from a maintenance standpoint) however code like this might have a good reason for staying in the code base, although it really should be commented if it's left in this form so that future devs don't say "oh hey this is pointless lemme delete it."
Admin
No. To optimize that out would require the compiler proving that all current and future implementations of all of those methods (IsAccountCodeNull(), etc) to not have any side-effects.
I know Java doesn't have any language construct that would guarantee that, and I highly doubt C++ or C# would either.
It could optimize out some of the branches, but not the method calls outright.
Admin
Admin
Your slippin'. It took you 12 minutes. Too much partying last night?
Admin
Actually no. You would think it would, but a bug is a failure on the part of the developer, and a WTF is something Worse Than Failure. This implies that it's not just a failure which a bug is.
captcha: decet -- Are there any decet developers here?
Admin
Correct, however it should be able to turn.
if (IsAccountCodeNull()) return true; else return true;
into
IsAccountCodeNull(); return true;
Admin
Two things:
"Worse Than Failure" is a backronym. I think we all know what WTF stands for.
The code in the article is no more a bug than an inefficient algorithm is a bug. A bug just means an unexpected or incorrect result. This code is just an example of superfluous logic.
To answer Mr Boog's question: A bug can be a WTF and a WTF may not be a bug.
Admin
It's not a bug it's a FEATURE
Admin
"Backronym"? Thanks very much, I just vomited. I hope you're happy with yourself. Most of it went in the trash can. Bastard.
Admin
Admin
"any 'operation' on a null operand would return a null result,..."
That's where I was going when I asked "why references but not primatives?".
Shouldn't anything be nullable, passing and assigning null without trouble. Then you check "not null" when the result is important.
Admin
Hold on a minute.
Don't move, just wait right there.
Hmm... let's see... ahh... Ah! Here we are! One of my old favorites:
http://thedailywtf.com/Articles/Seriously,_I_0x27_m_A_Genius.aspx
Now that is a failure on the part of the developer, and it is "a WTF." Your move.
Admin
It's a real word, Wikipedia told me so.
You're welcome. I hope you didn't have milk this morning.