Annoying code samples


Take a look at this code sample:
 
public class Index: System.Web.UI.Page
{
   private void Page_Load(object sender, EventArgs e)
   {
      Ajax.Utility.RegisterTypeFOrAjax(typeOf(Index));
   }
}
 
Did you notice typeOf(Index) is pointing to the page? Yes, in thsi sample, Index is the name of this page. When you look at it closely, it is obvious, but the word Index also has other meaning, so the code sample ends up confusing. It only caught me up until compile and then I examined the code sample to figure out what went wrong (I had actually named my page something with meaning to the application, which caused the breakdown when copying Page_Load). But, it cost a less experienced coworker even more time.
 
Now, here is my suggestion. If you are building samples, use MyXXX for the name, like MySamplePage. Why? No confusion. It is obvious that My points to something in the app that the developer is playing with.
 
My sample:
————-
public class MyStupidSamplePage: System.Web.UI.Page
{
   private void Page_Load(object sender, EventArgs e)
   {
      Ajax.Utility.RegisterTypeFOrAjax(typeOf(MyStupidSamplePage));
   }
}
 
Or, if you have a full sample app, then provide documentation that shows a code template.
 
Template sample:
——————–
Ajax.Utility.RegisterTypeFOrAjax(typeOf(NameOfPageHere));
 
We can make this difficult on each other or not; i is all in the way in which we present things.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: