Questions tagged [naming-conventions]

Do not use this tag to ask what you should name something. Naming conventions refer to general rules governing names assigned to programming constructs such as variables and methods. These conventions facilitate readability, and thus improved maintainability of code by enforcing naming consistency across disparate modules.

Naming conventions refer to general rules governing names assigned to programming constructs such as variables and methods. These conventions facilitate readability, and thus improved maintainability of code by enforcing naming consistency across disparate modules.

Examples

4026 questions
289
votes
6 answers

Is the underscore prefix for property and method names merely a convention?

Is the underscore prefix in JavaScript only a convention, like for example in Python private class methods are? From the 2.7 Python documentation: “Private” instance variables that cannot be accessed except from inside an object don’t exist in…
Kenny Meyer
  • 7,849
  • 6
  • 45
  • 66
281
votes
11 answers

How to name Dockerfiles

I'm unsure of how to name Dockerfiles. Many on GitHub use Dockerfile without a file extension. Do I give them a name and extension; if so what? Or do I just call them Dockerfile?
Lloyd R. Prentice
  • 4,329
  • 3
  • 21
  • 31
280
votes
6 answers

What are naming conventions for MongoDB?

Is there a set of preferred naming conventions for MongoDB entitites such as databases, collections, field names? I was thinking along these lines: Databases: consist of the purpose (word in singular) and end with “db” – all lower case: imagedb,…
Andrey
  • 20,487
  • 26
  • 108
  • 176
279
votes
11 answers

Should a "static final Logger" be declared in UPPER-CASE?

In Java, static final variables are constants and the convention is that they should be in upper-case. However, I have seen that most people declare loggers in lower-case which comes up as a violation in PMD. e.g: private static final Logger logger…
dogbane
  • 266,786
  • 75
  • 396
  • 414
276
votes
5 answers

Redis key naming conventions?

What is the standard naming convention for keys in redis? I've seen values separated by :, but I'm not sure what the standard convention is. For a user, would you do something like:user:00 If the user's id was 00 Are you able to query for just the…
fancy
  • 48,619
  • 62
  • 153
  • 231
275
votes
8 answers

Why do variable names often start with the letter 'm'?

Looking at the Android tutorials such as the Notepad tutorial, I noticed that almost all variables are named starting with the letter 'm'. What convention is this, and where does it originate from?
Kallja
  • 5,362
  • 3
  • 23
  • 33
269
votes
10 answers

Java Naming Convention with Acronyms

What is the correct name for the following Java class: DVDPlayer or DvdPlayer?
DD.
  • 21,498
  • 52
  • 157
  • 246
261
votes
6 answers

JavaScript naming conventions

I know there is a lot of controversy (maybe not controversy, but arguments at least) about which naming convention is the best for JavaScript. How do you name your variables, functions, objects and such? I’ll leave my own thoughts on this out, as I…
peirix
  • 36,512
  • 23
  • 96
  • 126
259
votes
2 answers

What is the etymology of 'slug' in a URL?

Is "URL slug" a completely arbitrary word? Or does it stand for something? I used the word in a conversation with someone and when they asked me why it's called that I realized I didn't know. I know what it means of course. The Stack Overflow tag…
Matthew
  • 15,282
  • 27
  • 88
  • 123
259
votes
12 answers

Why is the asterisk before the variable name, rather than after the type?

Why do most C programmers name variables like this: int *myVariable; rather than like this: int* myVariable; Both are valid. It seems to me that the asterisk is a part of the type, not a part of the variable name. Can anyone explain this logic?
WBlasko
  • 2,893
  • 2
  • 17
  • 11
255
votes
11 answers

Should you use .htm or .html file extension? What is the difference, and which file is correct?

What is the difference between the .htm and .html file extension? Why there are two of them? Which is correct?
CannibalSmith
  • 4,742
  • 10
  • 44
  • 52
238
votes
2 answers

Naming of enums in Java: Singular or Plural?

Is there an "official" recommendation of how to name Java enums? enum Protocol { HTTP, HTTPS, FTP } or enum Protocols { HTTP, HTTPS, FTP } I know in the .Net world the recommendation is to use singular except for enums that represent bit flags.…
friederbluemle
  • 33,549
  • 14
  • 108
  • 109
235
votes
7 answers

Why are dashes preferred for CSS selectors / HTML attributes?

In the past I've always used underscores for defining class and id attributes in HTML. Over the last few years I changed over to dashes, mostly to align myself with the trend in the community, not necessarily because it made sense to me. I've always…
Andrew Vit
  • 18,961
  • 6
  • 77
  • 84
234
votes
11 answers

For a boolean field, what is the naming convention for its getter/setter?

Eg. boolean isCurrent = false; What do you name its getter and setter?
user496949
  • 83,087
  • 147
  • 309
  • 426
234
votes
76 answers

What's the best name for a non-mutating "add" method on an immutable collection?

Sorry for the waffly title - if I could come up with a concise title, I wouldn't have to ask the question. Suppose I have an immutable list type. It has an operation Foo(x) which returns a new immutable list with the specified argument as an extra…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194