1

Possible Duplicates:
Anyone else find naming classes and methods one of the most difficult part in programming?
What’s the best approach to naming classes?

Finding appropriate abstraction names can sometime be time-consuming, especially if your mother tongue is not english. I was wondering if there exists somewhere some sort of online glossary/dictionary describing program-related concepts. We all know about Design Patterns from GoF but I'm looking for a much more complete lexicon, including relationships between concepts.

Thanks

Community
  • 1
  • 1
gawi
  • 13,940
  • 7
  • 42
  • 78
  • 3
    possible duplicate of [Anyone else find naming classes and methods one of the most difficult part in programming?](http://stackoverflow.com/questions/421965/anyone-else-find-naming-classes-and-methods-one-of-the-most-difficult-part-in-pro) or [What's the best approach to naming classes?](http://stackoverflow.com/questions/38019/whats-the-best-approach-to-naming-classes) – Greg Hewgill Jul 01 '10 at 19:53
  • I was not asking for naming guidelines but rather for a list of concepts that I can use during my naming task. Or said another way, I'm looking for a programming-oriented on-line thesaurus, something that will tells me the subtle differences between (example): *item and element *reply and response *query and request *handle, process, execute and perform *attribute and property *clear and reset *start vs. begin *stop vs. end vs. terminate *continue vs. resume *settings, configuration, data, info Being able to browse and navigate between definitions would be interesting. – gawi Jul 04 '10 at 00:57

2 Answers2

1

You know that there are conventions for naming artifacts in a program?

For example, Java has come up with a pretty strong and reliable way of naming classes, methods and attributes.

Wikipedia has this to say about naming convention (not too helpful, but still interesting) http://en.wikipedia.org/wiki/Naming_convention_(programming)

Here is a page from Central Washington University (with Java, but still helpful for other programming languages) : http://www.cwu.edu/~gellenbe/javastyle/naming.html

Other article here : http://drupal.star.bnl.gov/STAR/comp/sofi/soft-n-libs/standards/NamingAdvice

But basically, naming a method usually start with a action, then a noun, etc.

For example:

$obj.addObservers(...);  // action, noun
$obj.setPrice();         // action, noun
$obj.getModelFromDb();   // action, noun, preposition, noun
$obj.setActive(...);     // action, noun
$obj.isActive();         // yes (true) or no (false) statement
$obj.canEdit();          // yes (true) or no (false) statement
$obj.setCanEdit();       // action, attribute
// etc.

Avoid using negative method naming, ex: $obj.cannotConnect(); which will simply confuse everyone. (This is also true when prompting, ex: "You are about to delete this file, do you want to abort?" ... choosing 'no' thinking you are going to delete a file and it was a mistake will do the opposite...)

Back to method naming;

  • your method names should be as short as possible, but avoid using acronyms, unless the method name is too long (this is a judgement call here);
  • methods should be self explanatory and self documented;
  • avoid using prefixes, unless you are working with non-OOP languages (pretty rare these days). Your prefix should be your class, or namespace, etc.
  • each method should have only one function (one purpose) if you method does more than one thing, consider splitting that method into many, and call each of them inside a method (like doActionBatch(), where 'ActionBatch' is the name of the actual action to perform; Ex: doHttpConnect()
  • etc.

A tip I may suggest is to read programs written by the community; they usual adopt best practices in naming conventions and you will get more familiar with "how methods are named"

Yanick Rochon
  • 51,409
  • 25
  • 133
  • 214
0

The main thing is, be consitent with your naming conventions.

I'm a .NET developer, so I found it best to follow the design guidelines used by the .NET Framework.

http://msdn.microsoft.com/en-us/library/ms229042.aspx

ChrisNel52
  • 14,655
  • 3
  • 30
  • 36