Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![João Ignácio Brito](https://secure.gravatar.com/avatar/818a4906002dda7caeec64742a98e116?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
João Ignácio Brito
1,201 Pointsthis./m
In:
class PezDispenser{
private String mcharacterName;
public PezDispenser(String characterName) {
mcharacterName = characterName;
}
public String getCharacterName() {
return mcharacterName;
}
}
Wouldn't it be easier if Craig just did like this(following code)? Is there a particular reason why he did this way? I mean he would use less m's and would use less time, right?
class PezDispenser{
private String characterName;
public PezDispenser(String mcharacterName) {
characterName = mcharacterName;
}
public String getCharacterName() {
return characterName;
}
}
1 Answer
William Li
Courses Plus Student 26,868 PointsThere's no particular reason. Craig said so on the video timestamp 5:40.
there have been many attempts at trying to be more explicit because of it. There was at one time a very popular style of prefixing your private member variables with a lower case m.
And in the code. private String mcharacterName;
this line defines the private member variable, hence prefix it w/ m in its variable name, I guess m stands for "member variable".
This is just a popular variable naming convention, whether you choose to follow it is up to you, but there's no denying that picking a good variable name does help reader make senses of your code.
Personally, I don't like prefixing with m. I learned Java in my college years, back then the style was.
public PezDispenser(String characterName) {
this.characterName = characterName;
}
I still think this is the best way, even though some people may find the this
keyword confusing.