Code Smell 96 - My Objects
You don't own objects.
TL;DR: don't use my as a name prefix.
Lack of context
Remove my prefix.
Change to a role suggesting name.
Several old tutorials use the word 'my' as a lazy name. This is vague and lead to context mistakes.
MainWindow myWindow = Application.Current.MainWindow as MainWindow;
MainWindow salesWindow = Application.Current.MainWindow as MainWindow;
Since window is instanciated, we are currently working
with a specialized window playing a special role
- [x] Automatic
We can tell our linters and static checkers to search for this prefix and warn us.
Avoid using my. Objects change according to the usage context.
Thinking about my experience of modifying code, I see that I spend much more time reading the existing code than I do writing new code. If I want to make my code cheap, therefore, I should make it easy to read.
This article is part of the CodeSmell Series.