Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you work with SharePoint, you'll see classes like SPList, SPSite etc.

I've seen variations of this on other projects, in other technologies, e.g. for a CRM project, classes named CRMLoggingFactory, CRMEntity etc.

This stands out when you look at the code and you know what the prefix corresponds to, but when do you draw the line? What are the conditions for a class to be prefixed by the project name, company name, etc. (i.e. the "domain name" of the project)?

share|improve this question

closed as primarily opinion-based by durron597, GlenH7, Ixrec, Snowman, MichaelT Aug 15 '15 at 20:40

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 6 down vote accepted

This will at least partly depend on the language. Id say it is, in general, bad practice in languages that provide proper namespace facilities but good practice in languages that don't.

share|improve this answer

This is an indication that the environment has weak namespacing facilities, in Java, C++ or C# this is a tautology and a serious code smell. In C with a flat namespace this would be acceptable for public facing API functions.

share|improve this answer
Java Swing prefixes its classes with "J" (JPanel, JComponent, JButton, etc.). Would you say this is a serious code smell? Or is it acceptable for some reason in this case? What would that reason be? – Jason Nov 9 '15 at 22:58
need >=15 characters to say never – Jarrod Roberson Nov 10 '15 at 17:43
Jarrod, I'm not sure I understand your response. I didn't ask a question of "when", which would take an answer like "never". Are you saying that the prefixes in Swing are a serious code smell and the Java team made a mistake because they should never use a project prefix? Or am I missing something? I know I may sound ignorant in this, but I do appreciate the answers! – Jason Nov 12 '15 at 14:47

I would say that the line should be drawn when the class name seems somewhat generic but has a very particular implementation and meaning that is specific to the containing library/framework/api. Also if the library/api/whatever is expected to be used in the context with other compenents that may have classes with similar or identical names. You could also use namespaces to help with such problems, but that may not be available in all languages/environments.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.