From: "Robert C. Martin" Date: Wed Sep 20, 2000 1:18pm Subject: RE: [XP] Class variable and argument names I use a set of prefixes to separate instance variables, class variables, arguments, local, and global variables. global int GnumberO''''''fMarriages; class Person { public: virtual void Marry(Person theSpouse) { Person aPreacher; } private: double itsHeight; bool isMarried; static int theirPopulation; }; The above shows the convention. Globals are prefixed with capital G. Instance variables are prefixed with 'its' unless they are boolean in which case they are prefixed with 'is'. Arguments to methods are prefixed with 'the', and local variables are prefixed with 'a' or 'an' as appropriate (write ''aPerson'' but ''anIterator''). I add one other simple rule to this convention. If a method is short (as nearly all are) and if it makes sense to use single character argument or local variable names, then I will. void f(int n) { for (int i=0; i''' in CeeLanguage/CeePlusPlus. Before learning these languages, I programmed extensively in Pascal, where one writes '''^.''' (i.e. as in '''objectPtr^.memberName'''). As a result, I pronounce '''->''' as hat-dot (usually not aloud, but I have done so on occasion and confused the heck out of the person I was working with). -- StefanVorkoetter ---- ''It seems to me this is just a variation on HungarianNotation...'' I tend to use a variation on this convention, but my intent is to increase readability. It is just a by product that scoping information may be inferred from the name. It also helps eliminate naming conflicts between class variables and parameters, primarily in constructors. English uses prepositions and possesives and including them in your variable names allows your code to read more like standard English and less like pidgen English. I tend to use a format like "IAm..." for class booleans. This leads to lines like: if IAmEnabled rather than if isEnabled This also allows me to use "isEnabled" unamgibuously as a method name for lines like: if theObject.isEnabled() In general, I use first person for class variables, i.e. my.., IAm..., IHaveBeen.., etc. I use "the..." for almost all other variables, with the exception of using "a..." or "an..." for items in a collection, array, list, or whatever. The precise rules for when to use which one are not really that important, but trying to make code read like grammatic English is, I feel, important. I HaveThisPattern. I'll take it to other types of accessors - flagIsSet(), deviceIsReady(), etc. I like the flow in conditionals. ---- I prefer using first person (my, Iam etc) to third person (Its...). It makes more sense to use my when referring to things private to the object. Using 'Its' make one wonder what it is. ''It's generally a frog or a worm.'' In VisualBasic, it fits in with the Me keyword and is less surprising to people who have used the m.. or m_.. scope specifiers before. ---- '''Use Becomes rather than Set''' I am currently experimenting with using the verb "Becomes" rather than "Set" in my code and was curious whether others might find this appealing. For example, instead of myName.Set("First", "Middle", "Last"); try myName.Becomes("First", "Middle", "Last"); After using this for a while, it seems that "Becomes" follows a subject, verb, object pattern while "Set" appears to violate it. Use of "Set" had become automatic for me and "Becomes" looked strange (for all of 5 minutes!) at first, but I now feel it is much clearer. [An aside, as I am typing this in, I wondered if "Becomes" might also be appropriate for nameing class factories. I haven't tried this yet, so I will just wait to see how it looks in real code.] I'm interested in hearing others reaction concerning this. I personally like it, but was wondering whether it would be too jarring for an uninitiated reader. -- WayneMack ''My first reaction is "yuck." (Yes, it is jarring.) It seems more of a description of what happens than a command or a description of what is returned (as most method/function names I've seen are). Also, your myName.Set(...) starting point seems strange; most "set" methods are named as "setSubpart".'' How about setTo()? I often use names like addTo() and removeFrom() and so setTo() would fit right in. ---- it.puts(theLotion, itsSkin) ---- ''How about using the Becomes pattern for objects that transition to another state instead of just changing their inherent state of attributes or properts like in Order.becomes( Invoice ) or something like that? And, how is your progress with the 'becomes' pattern as a whole?'' ---- See also IdentifierPrefix. ---- CategoryNaming