| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |
|
Frist ...
My brain hurts |
|
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "frist" Then
Return "frist" |
|
My first frist!
|
|
Must be nice to be paid by LoC
|
|
Mathematical calculations drain the battery too much.
|
|
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 ..." |
|
Yeah, this could be drastically improved with a switch statement.
|
Re: The Percent Conversion
2012-02-02 09:10
•
by
DonaldK
(unregistered)
|
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... |
|
Does SystemInformation.PowerStatus.BatteryLifePercent.ToString always return 2 d.p? The documentation for BatteryLifePercent doesn't say either way.
|
|
Fail. The strings should be loaded from an XML file.
|
Not enterprisey enough; what if they need the values in different bases? Needs XML:
[Edit] RichP - you just beat me to it |
|
Maths by decimel is not being hard. Invented by Indian in fact at Hyderabad Unaversity:
|
The interesting thing is that as the battery charge gets lower, this function will consume more and more battery power. 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! :-( |
|
This is what we in the business call "paid by the line".
|
|
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.
|
Re: The Percent Conversion
2012-02-02 09:44
•
by
Decius
(unregistered)
|
Hopefully not- the code assumes that it returns 1 place in the cases of 10%, 20%, 90%, and presumably the other decades. Properly, the code preserves that lack of precision by displaying 90% instead of 90.% or 9.0*10^1, or any other method which would indicate the precision of the measurement. |
|
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. |
Re: The Percent Conversion
2012-02-02 09:49
•
by
Anon
(unregistered)
|
Oooh. Good point. I didn't even notice that part. So does this code even work then? |
|
What if the battery power is 0.0?
|
Re: The Percent Conversion
2012-02-02 10:07
•
by
Myth
(unregistered)
|
Then how is the code going to run? |
|
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!
|
Re: The Percent Conversion
2012-02-02 10:11
•
by
The Great Lobachevsky
(unregistered)
|
|
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) |
Re: The Percent Conversion
2012-02-02 10:18
•
by
Shutterbug
(unregistered)
|
ROFLMAO! capture: pecus - just pecus |
|
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".
|
Re: The Percent Conversion
2012-02-02 10:22
•
by
Shutterbug
(unregistered)
|
Only about 80.3% of the time ... |
Oh yeah, this is the guy who is always in front of you when you're in a rush when the penny counting granny has the day off... |
|
so, 0.991 is NA...
|
|
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.
|
|
Dear Sweet Lord. I'm not a coder, just a lowly network geek... and *I* wouldn't write a script like that.
|
Re: The Percent Conversion
2012-02-02 10:29
•
by
java.lang.Chris;
|
When the device is attached to a charger and turned on after the battery's gone flat? |
Re: The Percent Conversion
2012-02-02 10:37
•
by
PedanticCurmudgeon
|
That depends on who is appointed to the licensing board. If the licensing board were full of bad programmers, we might have our licenses suspended for using design patterns. |
|
Obligatory "The real WTF is VB..."
Now back to getting paid to write VB ... sigh ... |
|
I had to look carefully for the WTF in this code. Then it came to me all at once:
Public ReadOnly Property BatteryPercent() As String 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. |
Re: The Percent Conversion
2012-02-02 10:53
•
by
Matt
(unregistered)
|
Don't worry, there is a similar function for rounding numbers like that to the hundredths. |
You can be running off of power cable while having a defective battery which is dead. This happen to my laptop from 8 years ago, so it showed 0.0% charged (or if it was running this code N/A) and Unable to charge. |
|
It baffles me how people like this continue to get jobs as developers.
|
I agree 100%. Now the only think left for you to do is to throw yourself into a wood chipper. I'm sure you would make great compost. |
|
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:
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.2" Then ElseIf BatteryLifePercentString = "0.2" Then |
|
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)
|
|
The best part is how this becomes more and more power-inefficient as the user's power goes lower! What a great feature!
|
|
Hey this is VB, why don't they just mulitply the string by 100 and concatanate the "%" character?
|
|
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.
|
|
http://pastebin.com/jDa45U9h
If he keeps this up, he'll get a bonus for the extra LOC! |
Re: The Percent Conversion
2012-02-02 11:34
•
by
Crisw
(unregistered)
|
I used to be a comedian like you, until a mob beat me senseless for overusing a forced meme. |
|
Shouldn't it also be an "==" instead of '='? Or is that just in java?
|
|
I am 100% sure there is a better way to do that.
|
FTFY |
Edit: I derped a little there. |
*cloth on his head* I'm going to operate!!!! |
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |