FTW?
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
:zzz: Just a different take on a common situation.
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
lol, arguments in code comments.
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
Even more surprising is that it appeared convinced this was true even though the compiler gives an unreachable code warning and tell you that the check will always return true. But he probably didn't notice it hidden amongst the other 200 warnings. Sigh.
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
By the way, C# compiler (with optimization option 'on') generates these IL instructions for set accessor:
ldarg.0
ldarg.1
stfld bool <reference_to_local_field>
ret; so, at the C# level it whould be:
this._<reference_to_local_field> = value;
; So, this construction is obviously needless :-D
modified on Monday, January 19, 2009 1:56 AM
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
A colleague says perhaps this guy just plain didn't trust that said field would be checked actually *in* the serialization code...not that anyone would want to risk an exception getting thrown for serializing a
bool
anyway. Since when werebool
variables evernull
? Besides isn't that equivalent tofalse
, or am I not a "C# Expert?" -BrianSincerely Yours, Brian Hart
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
-
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault { get { return \_defaultSelected; } set { // no, check isn't pointless, because serialisation can assign a null to a bool if (value != null) { \_defaultSelected = value; } else { \_defaultSelected = false; } } }
Rotted Frog wrote:
because serialisation can assign a null to a bool
Isn't the bool variable default initialized to false?