Click here to Skip to main content
13,001,686 members (67,478 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 25 Jul 2008

Naming Conventions: Grouping within a Class

, 25 Jul 2008
Rate this:
Please Sign up or sign in to vote.
We provide a challenge to conventional wisdom of verb first to aid in grouping of names.


A common practice when selecting a naming convention is to use verb first resulting in names that read like an English phrase like GetThisThing. While establishing and sticking with a naming convention is wise, other factors are presented that may prove helpful, especially grouping concerns.

Although English words are used as the structure of virtually all programming languages, not all developers speak English as their native tongue. Non-English developers will frequently use English terms for their public classes and may go as far as commenting their code in English.

However the English sentence structure may not be the best when we are attempting to form a valuable descriptive phrase. We should consider the benefits of different sentence structures, most notably the position of the verb, when we form names.

If we have a class that has a value that we need to get, set and toggle we might have functions GetThisThing, SetThisThing and ToggleThisThing. We write our class with our three functions plus 38 more. A month later when it is no longer fresh in our minds, or when Joe Developer in the other department needs to make use of our class and work with an instance of ThisThing it is natural to use IntelliSense to find the functions we need.

We can assume that if we start typing .g that IntelliSense will quickly get us to the GetThisThing function. The same is true for our set function. However, since we don't remember or are not familiar with the code, we may not know that there is a toggle function that we require and end up doing the get, toggle, set sequence ourselves. IntelliSense will show us the toggle function, but not until we start with .t. When there are a lot of functions in our class, we are unlikely to notice it.

If we put the verb on the end, our function names would be ThisThingGet, ThisThingSet, ThisThingToggle. Now when we are working with an instance of the class and we need to work with ThisThing and we start typing .t we end up with all of our functions that address ThisThing together.

The use of namespaces allows us to group functional areas together which aids in code manageability. Grouping functions within a class by beginning names with its group accomplishes the same for a class.

We need to balance readability in an English sense and usability from a developer’s perspective. After all, the code is intended to be read by developers and not a general audience.


  • 25th July, 2008: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Founder ShofarNexus Corporation
United States United States
ShofarNexus™ is software project started in 1998 with a lot of testing and rejecting of methodologies. Our goals were fast startup and execution, a clean presentation and reliable data distribution. We take ReST to the extreme. We focus some on eye-candy and mostly on the meat and vegetables that are good for business.

ShofarNexus™ mentality is well described by Antoine de Saint-Exupéry who wrote “Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”

ShofarNexus™ is single-handedly written by John Kozlowski, with over 35 years of software development experience and a lot of hardware design in the first two decades.

You may also be interested in...

Comments and Discussions

QuestionWhy not make the article a forum post and add something useful? Pin
Dave Jellison26-Jul-08 13:42
memberDave Jellison26-Jul-08 13:42 
AnswerRe: Why not make the article a forum post and add something useful? Pin
emilio_grv27-Jul-08 6:11
memberemilio_grv27-Jul-08 6:11 
GeneralRe: Why not make the article a forum post and add something useful? Pin
Dave Jellison27-Jul-08 6:52
memberDave Jellison27-Jul-08 6:52 
No, I don't know of any IDE that supports a word cloud type of interface using reflection/method names, etc. Of course, I must admit I work solely from Visual Studio and don't have time for much else. I would love to check out Mono again and haven't for a few years now. So, as far as I know (humbly) it's still an original idea but feel free to run with it and send me a link to your completed VS Add-In by all means Smile | :) Maybe I'll actually contribute my first Code Project article...

I do agree if "nothing changes nothing changes". I do try to recommend naming conventions, standards and patterns at least in new development with projects that I work on. Of course, sometimes you get a hard nosed C++ guy in the dev lead chair that actually still wants some flavor of hungarian notation... What to do? A possible "strip hungarion" option in intellisense might be cool but it's so rare these days (thankfully) that it's probably not worth the effort.

As far as grouping methods one feature I do like is #region. What I would really like is a tool that gathers methods and properties in a MSDN approach defined by regions. By that I mean I would like to righ-click on a class in the Class View inside of Visual Studio and have a "Organize Regions" option. This would then reflect the class and place methods/properties in regions by access level. e.g.

#region "Private Fields"
#region "Protected Fields"
#region "Protected Properties"
#region "Public Properties"
#region "Private Methods"
#region "Constructors"
and so forth...

Since I figured out the key-combination to collapse/expand regions and other code groupings (CTRL+M+M by default) I can't live without this feature. The problem of course is classes are typically either not grouped in regions at all, or worse just properties, fields, constructors and methods scattered all over the place. Access level (public/private, etc.) is a very good starting point to find what you're looking for if you're a consumer of a class. For instance you can typically ignore most of the private fields, methods, properties (if any), etc. If I find a product that accomplishes that, possibly with some configuration options I'd purchase it in a heartbeat. I have looked and found nothing so if anyone knows something I don't...

I realize some of this comes from the point of a contract/independent software developer but I've worked with corporations as well. Not to mention, I'm working with large teams source code in the first place that almost always suffers from these types of code convention and organizational problems.
GeneralRe: Why not make the article a forum post and add something useful? Pin
DirectorWare28-Jul-08 6:55
memberDirectorWare28-Jul-08 6:55 
GeneralRe: Why not make the article a forum post and add something useful? Pin
Dave Jellison28-Jul-08 7:25
memberDave Jellison28-Jul-08 7:25 
GeneralRe: Why not make the article a forum post and add something useful? Pin
DirectorWare28-Jul-08 8:13
memberDirectorWare28-Jul-08 8:13 
QuestionWhy voting 1 ? Pin
emilio_grv25-Jul-08 21:36
memberemilio_grv25-Jul-08 21:36 
AnswerRe: Why voting 1 ? Pin
DirectorWare26-Jul-08 7:50
memberDirectorWare26-Jul-08 7:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 25 Jul 2008
Article Copyright 2008 by ShofarNexus
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid