Jeff Atwood makes a complaint about "performance programmers" breaking his code.
In his
example, Jeff shows the following snippet of code:
If Value <> "" Then
If nvc.Item(name) = "" Then
nvc.Add(name, Value)
End If
End If
... which was then changed to by the performance programmer.:
If Value <> String.Empty Then
If nvc.Item(name).Equals(String.Empty) Then
nvc.Add(name, Value)
End If
End If
The new code now breaks because if the
NameValueCollection (nvc) does not have an item in the container with
name it'll return null/nothing, which causes the call to
Equals
to fail with a null reference exception. Jeff's code works because null
references can be compared with empty string in C# and VB.NET.
Comparing null references to empty string is not good programming
practice in general (in C++ such a comparison would cause an
exception). Jeff wrote his code knowing that this comparison was safe
because he knew about the language fundamentals in which he was
developing, the performance programmer did not. This is a good example
of the typical traps that most performance crack teams fall into when
tuning an existing application. Developing software is an art form -
writing good maintainable code that works and performs well sometimes
requires the developer to use non-typical syntax, which can throw other
unfamiliar developers of the code into a loop.