Welcome to the Treehouse Community
Looking to learn something new?
Brendon Butler4,242 Points
'this.' prefix vs 'm' prefix vs nothing?
When I first learned how to program I would always use no prefixes at all mainly because I didn't know about 'this.' So if I had conflicting variables I would just have to change one of the variables.
Once I learned about 'this.' I continued to have conflicting variables, but I would just use 'this.' for member variables. I never really knew about using 'm' or 'I' or any other types of prefixes for naming conventions, just kind of stumbled across it when reading other's code.
My question is: Should I continue to use 'this.' for my member variables, or should I get in the habit of using the 'm' prefix?
Hey Brendon, for what it's worth, my personal opinion is that you should use whatever is clearest for you to write... and debug!
I think the "m" and "l" prefix convention is supposed to make it clearer for learners, when they aren't confident with variable scope yet. I haven't really seen this used outside of a learning environment myself.
In Java, "this." is a reference to the actual instance of the object... which is definitely a best practice to use, since it sounds like you understand variable scope.
But since you're thinking about it, and naming your variables descriptively -- you're already doing great! When you work on a larger project (with other programmers), there will probably be standards, or a "style guide" to follow.