What a gem.
-
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...
-
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...
I don't know what language uses a * between two strings. * is usually used to multiply two numbers. EG 123*4 = 492 + is used to add two numbers. EG 123+4 = 127. 123+"4" = error & is used to join two numbers, strings or a number and a string. EG 123 & 4 = "1234" If a language returns 492 or "492" from 123*"4" then in my opinion the language needs an update. The following Visual Basic 5 code:
Private Sub Form_Load()
Dim a As Integer ' or as Long or Double
Dim b As String
a = 123
b = "4"
MsgBox a * b
End Subdisplays 492, but should display an error acording to other versions of Basic.
-
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.
-
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.
Well, I can see he has time to do code :))))))))))
-
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.