A bad Case of comparison
-
I'm tasked, as many of us are, with maintaining a codebase that was written by my predecessor. I'm finding some parts disgusting, and other, more like... fun? Like the use of 'ToLower()' to make string comparison more safe...
if (someString.ToLower().StartsWith("text", StringComparison.OrdinalIgnoreCase))
-> Nice way to waste some cycles and memory for the Garbage Collector to play with!
if (someString.Substring(lastMarkend - 3, 3).ToLower() == "<Index>")
-> My little finger tells me, the functionality under this if must have been tested quite thoroughly. NB: I've only changed the string names.
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
-
I'm tasked, as many of us are, with maintaining a codebase that was written by my predecessor. I'm finding some parts disgusting, and other, more like... fun? Like the use of 'ToLower()' to make string comparison more safe...
if (someString.ToLower().StartsWith("text", StringComparison.OrdinalIgnoreCase))
-> Nice way to waste some cycles and memory for the Garbage Collector to play with!
if (someString.Substring(lastMarkend - 3, 3).ToLower() == "<Index>")
-> My little finger tells me, the functionality under this if must have been tested quite thoroughly. NB: I've only changed the string names.
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
-
#1, if you start counting at the first number.
Jeroen De Dauw (blog | Twitter | Identi.ca)
-
I'm tasked, as many of us are, with maintaining a codebase that was written by my predecessor. I'm finding some parts disgusting, and other, more like... fun? Like the use of 'ToLower()' to make string comparison more safe...
if (someString.ToLower().StartsWith("text", StringComparison.OrdinalIgnoreCase))
-> Nice way to waste some cycles and memory for the Garbage Collector to play with!
if (someString.Substring(lastMarkend - 3, 3).ToLower() == "<Index>")
-> My little finger tells me, the functionality under this if must have been tested quite thoroughly. NB: I've only changed the string names.
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
-
That would work better for sure ;) BTW, the string literal is just that, a string literal, when there are several 'consts'* defined some lines above * without any const specifier or special naming of course!
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
-
#2 is even worse. The literal on the right is 7 characters long, the string on the left only 3.
Well spotted, I did stop at the case mismatch there!
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood