what is prefix m in variables?

Put your problem here if it does not fit any of the other categories.

what is prefix m in variables?

Postby bqbqhahabq » Wed Nov 18, 2009 7:30 am

Hi, thank you.

I sometimes see declaration like 'MyLocationOverlay mMyLocationOverlay;'

why name is mMyLocationOverlay ? not myLocationOverlay ?

I see declaration like is often...

what 'm' means?!
bqbqhahabq
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Nov 17, 2009 6:57 am

Top

Postby padde » Wed Nov 18, 2009 8:19 am

Well.. in old days those notations wheres used to improve readability
of the code. The 'm' prefix means that this variable is a member variable
and therefore express the scope of the variable. There are various
variations like "m_" or just "_" that are used for the same purpose.

Some kind of standard notation used in old days is called the "Hungarian
notation" .. read HERE the Wikipedia entry :)

Nowadays there is really no need anymore for those naming conventions.
We have code highlighting and all that fancy stuff in our IDEs that makes
those old notations unnecessary and render them useless.

In many cases when u read code today that uses notations they
are used wrong because someone saw them somewhere and thinks
"uuuh that looks Pro" and begins to use it no matter what.
The other cases i guess are old school coder that cant get rid of this habit :lol:
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby qlimax » Wed Nov 18, 2009 2:15 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyClass{
  2.  
  3.         String mName;
  4.        
  5.  
  6.         public MyClass(String name) {
  7.                
  8.                mName=name; // here you istantiate the mName class field
  9.                
  10.         }
  11.  
  12. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyClass{
  2.  
  3.         String name;
  4.        
  5.  
  6.         public MyClass(String name) {
  7.                
  8.                this.name=name; // here you istantiate the name class field
  9.                
  10.         }
  11.  
  12. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyClass{
  2.  
  3.         String name;
  4.        
  5.  
  6.         public MyClass(String name) {
  7.                
  8.                name=name; //here you reassign the constructor parameter !
  9.                
  10.         }
  11.  
  12. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


if you use m prefix for the class fields, then you don't have to use this to referring it.

bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby Emmanuel7 » Wed Nov 18, 2009 10:10 pm

padde wrote:The other cases i guess are old school coder that cant get rid of this habit :lol:


I may be "old schooler that can't get rid of this habit", but for my real life work ( ie outside Android ), I'm working with a huge C/C++ code base, and, even with fancy IDE ( and even Fancy plugins for the IDE ), some sort of naming convention is a real time saver to understand code from others !

The IDE highlight is a good thing, but it only give informations on one variable at a time...

Another point is, all the project I've seen, all the middleware I used were using a naming convention. They can't all be wrong !!

( but I won't go as far as Hungarian notation )
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby padde » Wed Nov 18, 2009 11:23 pm

I was talking about private developing not huge commercial projects.
In the professional development you have to use the naming conventions
and notations that were specified. Affectations and wishes of a single developer
doesnt count in that environment.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests