MyBlogPost
A few years back, I was working on an ASP.NET project and in order to help me meet the tight deadline, my boss brought in a consultant. We’ll call him John. John had done some work with the company before I had started and was available at the time, so the decision was made and he came in and started working. I went over the requirements and the design for the app. I assigned him a portion of the app to start working on and went about my work. A couple days into the project, I asked how he was doing and as I was talking to him I glanced over his shoulder at his monitor and I couldn’t believe what I was looking at. There was a variable in his code-behind file called “MyDataSet”!!
I think my head almost exploded! I asked him about it and did an informal code review, at which point I asked him to update his variable names and to make them more meaningful. I was going to be responsible for all of the code once it launched and I had no interest in trying to interpret the variable and control names. A week later, there were still instances of “MyDataSet” and “MyTextBox” all over the code. Needless to say, he didn’t last long on that project, and I spent a couple of late nights “fixing” the code so I would be able to understand it.
So where did the “my” prefix come from? In his case, it came from books and the msdn site. I saw it just today in a demo, hosted by Microsoft and produced by a Microsoft employee…
When Microsoft and the authors of technical books put together demos, there is typically a contrived scenario that they are supplying code for. Why can’t they look at the code and the scenario and come up with some meaningful variable names? Why does it make sense to name a texbox intended to accept a username, “myTextBox”? Why wouldn’t you call it “UsernameTextbox” or “txtUsername” or just “Username”?
In simple examples, this can be annoying, in larger ones, it can be thoroughly confusing. When taken seriously by a new developer, it can have more severe consequences.
What happened to the naming standards and best practices? What about self-documenting code?
I’ve probably been guilty of this once or twice, in my early years of teaching .NET, but I probably caught it from a book.
It doesn’t take much effort to use more meaningful names and the development community leaders, especially those working for Microsoft, should be held to a higher standard. I propose a ban on using “my<Object Name>” as variable names.
Who’s with me?