Thursday, August 18, 2011

minimize Magic Strings

This is superior to what is given below as it does not identify Session variable by way of a magic string.

string foo = "bar";

string baz = "";

if(Session[foo] != null)

{

   Session[foo] = "qux";

} else {

   baz = Session[foo] as string;

}

 
 

This use of a magic string is a code smell.

string baz = "";

if(Session["bar"] != null)

{

   Session["bar"] = "qux";

} else {

   baz = Session["bar"] as string;

}

No comments:

Post a Comment