When Gobbledygook, Do Nada (Except Break the Build)
-
Dim strBrowser As String = Request.Browser.Browser.ToString()
Dim strBroswerVersion As String = Request.Browser.Version.ToString()
If strBrowser.ToString() = "IE" Then
If IsNumeric(strBroswerVersion.ToString()) Then
If strBroswerVersion < 9 Then
' Do absolutely nothing. Really, nothing at all.
End If
End If
End IfWhile fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:
- Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
- Compilation breaks when trying to compare a string against a number.
- Anything this would have done has been commented out, so it does nothing.
- Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
- Comparing strings without ignoring case.
- The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
- Hungarian notation.
Can I cry yet? :((
-
Dim strBrowser As String = Request.Browser.Browser.ToString()
Dim strBroswerVersion As String = Request.Browser.Version.ToString()
If strBrowser.ToString() = "IE" Then
If IsNumeric(strBroswerVersion.ToString()) Then
If strBroswerVersion < 9 Then
' Do absolutely nothing. Really, nothing at all.
End If
End If
End IfWhile fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:
- Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
- Compilation breaks when trying to compare a string against a number.
- Anything this would have done has been commented out, so it does nothing.
- Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
- Comparing strings without ignoring case.
- The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
- Hungarian notation.
Can I cry yet? :((
-
Dim strBrowser As String = Request.Browser.Browser.ToString()
Dim strBroswerVersion As String = Request.Browser.Version.ToString()
If strBrowser.ToString() = "IE" Then
If IsNumeric(strBroswerVersion.ToString()) Then
If strBroswerVersion < 9 Then
' Do absolutely nothing. Really, nothing at all.
End If
End If
End IfWhile fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:
- Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
- Compilation breaks when trying to compare a string against a number.
- Anything this would have done has been commented out, so it does nothing.
- Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
- Comparing strings without ignoring case.
- The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
- Hungarian notation.
Can I cry yet? :((
-
Dim strBrowser As String = Request.Browser.Browser.ToString()
Dim strBroswerVersion As String = Request.Browser.Version.ToString()
If strBrowser.ToString() = "IE" Then
If IsNumeric(strBroswerVersion.ToString()) Then
If strBroswerVersion < 9 Then
' Do absolutely nothing. Really, nothing at all.
End If
End If
End IfWhile fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:
- Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
- Compilation breaks when trying to compare a string against a number.
- Anything this would have done has been commented out, so it does nothing.
- Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
- Comparing strings without ignoring case.
- The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
- Hungarian notation.
Can I cry yet? :((
You should see some of the crap *wonderful* third-party VB code I've been asked to help with! ;P Here's a typical example:
Public Shared Function GetBitNr(ByVal TestInteger As Integer, ByVal Nr As Integer) As Integer
If TestInteger < 0 Then
If Nr = 32 Then
Return 1
End IfTestInteger = TestInteger + CInt(&H80000000)
End If
Dim i As Long = 30
Dim str As String = ""
Do While (i > -1)
If 2 ^ i <= TestInteger Then
str = str & "1"
TestInteger = CInt(Math.Round(TestInteger - 2 ^ i))
ElseIf Left(str, 1) = "1" Then
str = str & "0"
End Ifi = i - 1
Loop
Dim result As Integer
If Len(str) >= Nr Then
result = CInt(Mid(str, Len(str) - Nr + 1, 1))
Else
result = 0
End IfReturn CInt(result)
End Function
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
You should see some of the crap *wonderful* third-party VB code I've been asked to help with! ;P Here's a typical example:
Public Shared Function GetBitNr(ByVal TestInteger As Integer, ByVal Nr As Integer) As Integer
If TestInteger < 0 Then
If Nr = 32 Then
Return 1
End IfTestInteger = TestInteger + CInt(&H80000000)
End If
Dim i As Long = 30
Dim str As String = ""
Do While (i > -1)
If 2 ^ i <= TestInteger Then
str = str & "1"
TestInteger = CInt(Math.Round(TestInteger - 2 ^ i))
ElseIf Left(str, 1) = "1" Then
str = str & "0"
End Ifi = i - 1
Loop
Dim result As Integer
If Len(str) >= Nr Then
result = CInt(Mid(str, Len(str) - Nr + 1, 1))
Else
result = 0
End IfReturn CInt(result)
End Function
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Richard Deeming wrote:
CInt(&H80000000)
Probably i should not ask but from pure curiosity: What is this ?
&H is VB prefix for Hex constant: so &H100 is 256, &H200 is 512, and so forth. So it's converting a 32 bit hexadecimal integer constant value to a 32 bit integer value... :doh:
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
&H is VB prefix for Hex constant: so &H100 is 256, &H200 is 512, and so forth. So it's converting a 32 bit hexadecimal integer constant value to a 32 bit integer value... :doh:
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
But if this is a signed integer, wouldn't it just add -1 to the input instead of turning the sign around? Or is Cint() a conversion to unsigned int? Also converting the whole number when you only need one bit, thats "just great". :rolleyes:
Well - no. What it will do is throw an OverflowException "Value was either too large or too small for an Int32." when you try to do the convert in the C# version, or "Arithmetic operation resulted in an overflow." when you add the two together in the VB... :laugh:
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
But if this is a signed integer, wouldn't it just add -1 to the input instead of turning the sign around? Or is Cint() a conversion to unsigned int? Also converting the whole number when you only need one bit, thats "just great". :rolleyes:
Not to mention converting the string manually instead of using Convert.ToString(TestInteger, 2)[^]. Or concatenating up to 31 strings during the conversion. Or extracting a single character as a string instead of a character. Or using
CInt
when you know it will be either"0"
or"1"
. Or even the fact that the whole method could be replaced with:Return If(TestInteger And (2 ^ (Nr - 1)) = 0, 0, 1)
And as for the fact that the function was only ever called with a single value of
Nr
, so that all the calls could be replaced with:'If GetBitNr(someValue, 7) = 1 Then
If (someValue And 64) <> 0 ThenX|
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
You should see some of the crap *wonderful* third-party VB code I've been asked to help with! ;P Here's a typical example:
Public Shared Function GetBitNr(ByVal TestInteger As Integer, ByVal Nr As Integer) As Integer
If TestInteger < 0 Then
If Nr = 32 Then
Return 1
End IfTestInteger = TestInteger + CInt(&H80000000)
End If
Dim i As Long = 30
Dim str As String = ""
Do While (i > -1)
If 2 ^ i <= TestInteger Then
str = str & "1"
TestInteger = CInt(Math.Round(TestInteger - 2 ^ i))
ElseIf Left(str, 1) = "1" Then
str = str & "0"
End Ifi = i - 1
Loop
Dim result As Integer
If Len(str) >= Nr Then
result = CInt(Mid(str, Len(str) - Nr + 1, 1))
Else
result = 0
End IfReturn CInt(result)
End Function
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Now I see the point of lessons on Assembler... One of the first tasks was to "convert a decimal number to a binary representation and output to the console". If you have to write something in ASM, you desperately look for a smallest an easiest solution possible. Everybody should have such lessons. It teaches how the computer arithmetic works better than a houndred of calculus lectures.
Greetings - Jacek