What a gem.
-
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
-
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
What a shortcut! A qualified programmer would have accounted for the fact that BatteryLifePercent is floating point, and may not be in increments of 1/100th. What if it's 0.975? Obviously this should have been written as:
If SystemInformation.PowerStatus.BatteryLifePercent <= 1 And
SystemInformation.PowerStatus.BatteryLifePercent > 0.99 then Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent <= 0.99 And
SystemInformation.PowerStatus.BatteryLifePercent > 0.98 then Return "98%"
...:)
-
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
They are clearly just coding around a bad framework. There's a field called BatteryLifePercent, but it's not actually a percentage number. Obviously the framework is incorrect.
-
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
Option Strict is off or the Property would have an As clause! Correct would've been:
Public ReadOnly Property BatteryPercent As Percent
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
' No implicit conversions with Strict On!
Return Convert.ToPercentage("100%")
' Etc...Now that just made a world of difference :)
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
Could be wrong but it looks like a case of lack of knowledge, not knwoing/understanding that there is a better/more effecoent way to achieve teh same goal. I work in RDBMS (sepcifcally SQL Server) and I routinely see this same kind of bad design choice and usually its due to a lack of knowledge/eductaion on the product/system. For example when the develoepr needs to store a bolean value ( 0 and <>0 ) they use a NUMERIC data type which [by default) uses 9 bytes instead of using the smaller BIT data type.
-
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
This is why degrees are useful. You may not be the best programmer in the world after graduating, but at least you should learn enough to avoid code like this. Having a get-r-done attitude is fine and all, but a get-r-done intelligently attitude is much better.
Somebody in an online forum wrote:
INTJs never really joke. They make a point. The joke is just a gift wrapper.
-
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
-
Could be wrong but it looks like a case of lack of knowledge, not knwoing/understanding that there is a better/more effecoent way to achieve teh same goal. I work in RDBMS (sepcifcally SQL Server) and I routinely see this same kind of bad design choice and usually its due to a lack of knowledge/eductaion on the product/system. For example when the develoepr needs to store a bolean value ( 0 and <>0 ) they use a NUMERIC data type which [by default) uses 9 bytes instead of using the smaller BIT data type.
That's horrible. Everyone knows that you should use a varchar and store it as 'True' or 'False'.
Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
-
Stumbled across this gem today. http://pastebin.com/4Nx8yggU[^] For preservation sake, here is a snippet, but you get the idea:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
... etcWow is all I can say.
That is a joke right? Does this joke include enough to go all the way to 0%?
-
This is why degrees are useful. You may not be the best programmer in the world after graduating, but at least you should learn enough to avoid code like this. Having a get-r-done attitude is fine and all, but a get-r-done intelligently attitude is much better.
Somebody in an online forum wrote:
INTJs never really joke. They make a point. The joke is just a gift wrapper.
You were joking right? I saw graduates that couldn't tell a variable from an array from a class from an object (etc...). Oh, and they weren't like barely getting their grades, in fact, they were top of the class (due to compensating programming with communication or economics, plus getting their projects done by others).
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood 'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
And well commented. I think we can all appreciate the thoroughness of the approach.
_____________________________ Give a man a mug, he drinks for a day. Teach a man to mug... The difference between an ostrich and the average voter is where they stick their heads.
-
You were joking right? I saw graduates that couldn't tell a variable from an array from a class from an object (etc...). Oh, and they weren't like barely getting their grades, in fact, they were top of the class (due to compensating programming with communication or economics, plus getting their projects done by others).
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood 'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
Nope, not joking. Not everybody who goes through college is a better programmer than a non-college programmer. Though I'd say more college grads have better sense. Of course, that's from my anecdotal experience*, so YMMV. *For example, I wrote my 558 Lines of QuickBasic Glory before I went to college. Relying on file IO, "unnecessary" optimizations, and third party libraries seemed like too much work at the time.
Somebody in an online forum wrote:
INTJs never really joke. They make a point. The joke is just a gift wrapper.
-
Don't know what language this is, but I'm sure you could use the following to reduce the code length:
' ...
Return (SystemInformation.PowerStatus.BatteryLifePercent.ToString *100) & "%"
' . End of function.There you go, thinking like a programmer again. Where's that going to get ya? :)
_____________________________ Give a man a mug, he drinks for a day. Teach a man to mug... The difference between an ostrich and the average voter is where they stick their heads.
-
Nope, not joking. Not everybody who goes through college is a better programmer than a non-college programmer. Though I'd say more college grads have better sense. Of course, that's from my anecdotal experience*, so YMMV. *For example, I wrote my 558 Lines of QuickBasic Glory before I went to college. Relying on file IO, "unnecessary" optimizations, and third party libraries seemed like too much work at the time.
Somebody in an online forum wrote:
INTJs never really joke. They make a point. The joke is just a gift wrapper.
I guess if you take a statistical sample of graduates vs non-graduates, the average is better, and the deviation lower. I was worried that you'd equate degree with competence ;)
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood 'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Don't know what language this is, but I'm sure you could use the following to reduce the code length:
' ...
Return (SystemInformation.PowerStatus.BatteryLifePercent.ToString *100) & "%"
' . End of function.Actually, it's:
Return (SystemInformation.PowerStatus.BatteryLifePercent * 100).ToString() + "%"
You did the
ToString
before the multiplication. Note that this:SystemInformation.PowerStatus.BatteryLifePercent.ToString("p")
...does create a percentage conversion, but since it has decimals and a space it is not equivalent.
-
Actually, it's:
Return (SystemInformation.PowerStatus.BatteryLifePercent * 100).ToString() + "%"
You did the
ToString
before the multiplication. Note that this:SystemInformation.PowerStatus.BatteryLifePercent.ToString("p")
...does create a percentage conversion, but since it has decimals and a space it is not equivalent.
-
It couldn't have been done with a generic approach, look at the last line:
Else
Return "NA"That required a custom solution! Just kidding ;) BTW, shouldn't that be 'N/A'?
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood 'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Wow! This is only not worse than what I've seen, because the DB field length related to what I found is small:
public string GetStringToDatabase(int value)
{
if (value > 99999999)
return "0" + value.ToString();
else if (value > 9999999)
return "00" + value.ToString();
else if (value > 999999)
return "000" + value.ToString();
.
.
.
}"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
I did something like this when I was programming in assembly language back in college. I was making a way to get a value out of a register out to the terminal in an integer form. Then, we only had 16 bit registers and could only output -32738 to 32737. But, there was no library routines to output to the terminal.
-
I did something like this when I was programming in assembly language back in college. I was making a way to get a value out of a register out to the terminal in an integer form. Then, we only had 16 bit registers and could only output -32738 to 32737. But, there was no library routines to output to the terminal.
Well, although in assembly one can develop a routine for that, it's forgivable if you don't, specially in college while learning. What's unforgivable is having this in a high level language in production code for a mission critical application.
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
-
I used & and not + as & can join a string and a number. + will only add two nunbers or attach two strings. I would usually use CStr$() but as I was not to sure what language this was, used & as it's used in a number of languages.
The "+" operator does work here, it implicitly converts the number to a string and concatenates it to the other. But yes, the "&" operator is for concatenation explicitly. However, in your example, my key point was that you used the "*" operator between a number and a string...