Questions tagged [naming]

Give meaning and explanation with the fewest number of characters in a form that is most accepted by your team or community at large.

Naming applies to areas like the following:

  • Naming convention for code (objects, routines, etc.)
  • Processes (projects, version numbers, etc.)

There are existing standards from which you can choose, for example Hungarian.

This area can be filled with strongly held opinions. Be mindful of Stack Overflow's view of subjective. Keep in mind employers might set the standard and this tag is for those who need to better understand those set standards.

653 questions
320
votes
4 answers

Should package names be singular or plural?

Often, in libraries especially, packages contains classes that are organized around a single concept. Examples: xml, sql, user, config, db. I think we all feel pretty naturally that these packages are correct in the…
Nicole
  • 28,111
  • 12
  • 95
  • 143
230
votes
19 answers

Why is naming a table's Primary Key column "Id" considered bad practice?

My t-sql teacher told us that naming our PK column "Id" is considered bad practice without any further explanations. Why is naming a table PK column "Id" is considered bad practice?
161
votes
6 answers

Should the variable be named Id or ID?

This is a bit pedantic, but I've seen some people use Id as in: private int userId; public int getUserId(); and others use: private int userID; public int getUserID(); Is one of these a better name than the other? Why? I've seen this done very…
Adam
  • 2,141
  • 2
  • 16
  • 15
140
votes
18 answers

Is there an excuse for short variable names?

This has become a large frustration with the codebase I'm currently working in; many of our variable names are short and undescriptive. I'm the only developer left on the project, and there isn't documentation as to what most of them do, so I have…
KChaloux
  • 5,773
  • 4
  • 35
  • 34
128
votes
13 answers

What "version naming convention" do you use?

Are different version naming conventions suited to different projects? What do you use and why? Personally, I prefer a build number in hexadecimal (e.g 11BCF), this should be incremented very regularly. And then for customers a simple 3 digit…
117
votes
7 answers

Why is Inversion of Control named that way?

The words invert or control are not used at all to define Inversion of Control in the definitions that I've seen. Definitions Wikipedia inversion of control (IoC) is a programming technique, expressed here in terms of object-oriented programming,…
Korey Hinton
  • 2,656
  • 3
  • 20
  • 30
106
votes
6 answers

What is a term for a function that when called repeatedly, has the same effect as calling once?

(Assuming a single-threaded environment) A function that fulfills this criterion is: bool MyClass::is_initialized = false; void MyClass::lazy_initialize() { if (!is_initialized) { initialize(); //Should not be called multiple times …
Rufus
  • 1,437
  • 3
  • 9
  • 11
106
votes
16 answers

What is the benefit of not using Hungarian notation?

One of the things I struggle with is not using Hungarian notation. I don't want to have to go to the variable definition just to see what type it is. When a project gets extensive, it's nice to be able to look at a variable prefixed by 'bool' and…
user29981
104
votes
11 answers

What's the name of the antipattern opposite to "reinventing the wheel"?

The "Reinvent the wheel" antipattern is a pretty common one - instead of using a ready solution, write your own from scratch. Code base grows needlessly, slightly different interfaces that do the same thing but slightly differently abound, time is…
SF.
  • 5,078
  • 2
  • 24
  • 36
98
votes
8 answers

Should interface names begin with an "I" prefix?

I have been reading "Clean Code" by Robert Martin to hopefully, become a better programmer. While none of it so far has been really ground breaking it has made me think differently about the way I design applications and write code. There is one…
Charles Sprayberry
  • 1,606
  • 1
  • 12
  • 21
94
votes
5 answers

Naming classes, methods, functions and variables

There are 3 important naming conventions: with_underscores PascalCased camelCased Other variants are not important because they are not commonly used. For variables it seems that the one with underscores is the most used by developers so I'll…
Alexa
  • 1,281
  • 1
  • 11
  • 9
90
votes
10 answers

How and why to decide between naming methods with "get" and "find" prefixes

I always have trouble figuring out if I should name a certain method starting with getSomething versus findSomething. The problem resides in creating helpers for poorly designed APIs. This usually occurs when getting data from an object, which…
knownasilya
  • 3,074
  • 3
  • 17
  • 16
89
votes
15 answers

Is it bad to use Unicode characters in variable names?

I recently tried to implement a ranking algorithm, AllegSkill, to Python 3. Here's what the maths looks like: No, really. This is then what I wrote: t = (µw-µl)/c # those are used in e = ε/c # multiple places. σw_new = (σw**2 * (1 -…
badp
  • 1,870
  • 1
  • 16
  • 21
84
votes
4 answers

What's the difference between "to" and "as" method name prefixes?

What's the difference between "to" and "as" method name prefixes like toList(), asList(), etc... When to use which when designing a method?
Daniel Hári
  • 701
  • 5
  • 7
83
votes
4 answers

Classes naming: singular or plural?

It is always difficult for me to choose between singular and plural forms for classes names: CustomerRepository vs. CustomersRepository CustomerService vs. CustomersService CustomerController vs. CustomersController And for composite names it is…
SiberianGuy
  • 4,753
  • 6
  • 34
  • 46
1
2 3
43 44