- 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
Frist ...
My brain hurts
Admin
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "frist" Then Return "frist"
Admin
My first frist!
Admin
Must be nice to be paid by LoC
Admin
Mathematical calculations drain the battery too much.
Admin
Hm. It appears mathematics, or even plain arithmetic, was not one of the original developer's strengths? How do people like this deal with everyday arithmetic problems like, say, checking their change?
"That'll be $3.78, sir."
"Thanks." [Hands over $5 bill, receives $1.22 in change]
"Umm..." [stares blankly at bill and coins]
"Is there a problem, sir?"
"Um ... I don't know ..."
Admin
Yeah, this could be drastically improved with a switch statement.
Admin
Quite. Storage for big binaries is not an issue these days, and heavy mathematical calculations (such as multiplying by 100 and rounding / trimming) cause high CPU usage, which warms up our planet. We should do our part against global warming...
Admin
Does SystemInformation.PowerStatus.BatteryLifePercent.ToString always return 2 d.p? The documentation for BatteryLifePercent doesn't say either way.
Admin
http://www.codeproject.com/feature/HallOfSHame.aspx?msg=4106906#xx4106906xx
Same source?
Admin
Fail. The strings should be loaded from an XML file.
Admin
[Edit] RichP - you just beat me to it
Admin
Maths by decimel is not being hard. Invented by Indian in fact at Hyderabad Unaversity:
[image]Admin
Say, there's a bug for you: What if the BatteryLifePercent went up (charging) right in the middle of the (up to) 99 calls to ToString? (You'd get NA)
What if you're running on a desktop? You'll always get "NA", the worst case for this code. But hey, you're plugged in, so who cares?
The planet cares! :-(
Admin
This is what we in the business call "paid by the line".
Admin
Incredibly enough, this code lives in its own method, which is properly named. This WTF would be much better if it was found buried inside a mess of templates or in the Paint() method.
Admin
Admin
That's terrible code. What happens if the method for converting from decimal to percent changes?
It doesn't even try to deal with adding the leap-percent that comes around every few years, or to adjust for local Percent Savings Time.
Admin
Oooh. Good point. I didn't even notice that part. So does this code even work then?
Admin
What if the battery power is 0.0?
Admin
Then how is the code going to run?
Admin
Maybe we need to start forcing programmers to have a license to be able to operate - just like we do for many other professions. This person would definintely have to have their license suspended for at least a year!
Admin
When I was a real little kid, about 3, and I would go to the store with my family, I totally didn't get the concept of giving change.
In this situation, my little child brain believed that the $5 bill was now only worth $3.78, and wondered how they kept track of it only being worth that instead of the amout printed on it. :)
I have a feeling the original developer still thinks the way I did when I was 3.
captcha: mara - Mara preserve us! (insert lame "arrow in the knee" joke here)
Admin
ROFLMAO!
capture: pecus - just pecus
Admin
The funniest thing is that it runs the method SystemInformation.PowerStatus.BatteryLifePercent.ToString so many times that it could actually drain the battery by 1% in the middle of the function and give the wrong answer. Or, if the battery is charging, it could skip the right answer and fall all the way down to "NA".
Admin
Only about 80.3% of the time ...
Admin
Admin
so, 0.991 is NA...
Admin
You should look at the StackOverflow. There's gazillion questions that resemble amateurs such as this one. A ton of self-called programmers out there don't want to use more brains than it's needed to simply copy-paste code.
Admin
Dear Sweet Lord. I'm not a coder, just a lowly network geek... and I wouldn't write a script like that.
Admin
When the device is attached to a charger and turned on after the battery's gone flat?
Admin
Admin
Obligatory "The real WTF is VB..."
Now back to getting paid to write VB ... sigh ...
Admin
I had to look carefully for the WTF in this code. Then it came to me all at once:
I'm not certain what everyone is going about. A switch will only be more efficient if the entire jump table can fit into standard memory. Once you've gone beyond 6.4 cases, embedded if's are the only way to go.
Admin
Admin
Admin
It baffles me how people like this continue to get jobs as developers.
Admin
Admin
What awful code. I mean, he should have assigned SystemInformation.PowerStatus.BatteryLifePercent.ToString to a variable first. That would have saved him a bunch of typing. Here are some comparison snippets:
Admin
TRWTF is of course that the API apparently returns a fraction of the battery life (0-1) instead of a percent as the member name 'BatteryLiferPercent' suggests (see also this MS bug report)
Admin
The best part is how this becomes more and more power-inefficient as the user's power goes lower! What a great feature!
Admin
Hey this is VB, why don't they just mulitply the string by 100 and concatanate the "%" character?
Admin
I get it, the problem is he didn't give that the return type is a string, let alone add a version that returned an integer instead.
Admin
http://pastebin.com/jDa45U9h
If he keeps this up, he'll get a bonus for the extra LOC!
Admin
I used to be a comedian like you, until a mob beat me senseless for overusing a forced meme.
Admin
Shouldn't it also be an "==" instead of '='? Or is that just in java?
Admin
I am 100% sure there is a better way to do that.
Admin
Admin
Edit: I derped a little there.
Admin
cloth on his head I'm going to operate!!!!