I have some developers who are rather green when it comes to object oriented development, and I was looking for a way to explain to him the concept of casting and a few other things. I was doing a code review on some of his code and I find things like
protected Guid LastValue { get { if (ViewState["LastValue"] == null) return Guid.Empty; else return new Guid(ViewState["LastValue"].ToString()); } set { ViewState["LastValue"] = value; } }
I would rather he have an understanding of this so I don't need to fix things like this for him all the time.
protected Guid LastValue { get { return (Guid)(ViewState["LastValue"] ?? Guid.Empty); } set { ViewState["LastValue"] = value; } }
In general, for the developer, ToString() see to always be the answer, even if a string is already returned...
i.e.
return Request.QueryString["Value"].ToString();/sigh
Also, just hardcoding of strings, and
public bool IsOk(string value) { if (value.Equals("One") || value.Equals("Two")) return true; else return false; }
I can fix this code, but if they never go back and look at it, they aren't ever going to know any better.
Usually I would pull this person aside, but they are in China and I'm in the US, so I think some things get lost in translation, so any resources anyone has run across that they found helpful would be great.
Thanks, Dave