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.
4,043
questions
1845
votes
18
answers
798k
views
What is the meaning of single and double underscore before an object name?
What do single and double leading underscores before an object's name represent in Python?
1840
votes
41
answers
564k
views
Table Naming Dilemma: Singular vs. Plural Names [closed]
Academia has it that table names should be the singular of the entity that they store attributes of.
I dislike any T-SQL that requires square brackets around names, but I have renamed a Users table ...
1478
votes
12
answers
317k
views
Naming Classes - How to avoid calling everything a "<WhatEver>Manager"? [closed]
A long time ago I have read an article (I believe a blog entry) which put me on the "right" track on naming objects: Be very very scrupulous about naming things in your program.
For example if my ...
1374
votes
7
answers
793k
views
What are some examples of commonly used practices for naming git branches? [closed]
I've been using a local git repository interacting with my group's CVS repository for several months, now. I've made an almost neurotic number of branches, most of which have thankfully merged back ...
1133
votes
16
answers
298k
views
Why would a JavaScript variable start with a dollar sign? [duplicate]
I quite often see JavaScript with variables that start with a dollar sign. When/why would you choose to prefix a variable in this way?
(I'm not asking about $('p.foo') syntax that you see in jQuery ...
1084
votes
15
answers
810k
views
What is the naming convention in Python for variables and functions?
Coming from a C# background the naming convention for variables and methods are usually either camelCase or PascalCase:
// C# example
string thisIsMyVariable = "a"
public void ThisIsMyMethod(...
1065
votes
6
answers
344k
views
What are the rules about using an underscore in a C++ identifier?
It's common in C++ to name member variables with some kind of prefix to denote the fact that they're member variables, rather than local variables or parameters. If you've come from an MFC background, ...
919
votes
23
answers
719k
views
Database, Table and Column Naming Conventions? [closed]
Whenever I design a database, I always wonder if there is a best way of naming an item in my database. Quite often I ask myself the following questions:
Should table names be plural?
Should column ...
817
votes
27
answers
353k
views
Should I use Singular or Plural name convention for REST resources?
Some RESTful services use different resource URIs for update/get/delete and Create. Such as
Create - using /resources with POST method (observe plural) at some places using /resource (singular)
...
795
votes
5
answers
437k
views
What is the purpose of the single underscore "_" variable in Python?
What is the meaning of _ after for in this code?
if tbh.bag:
n = 0
for _ in tbh.bag.atom_set():
n += 1
744
votes
4
answers
52k
views
Why aren't ◎ܫ◎ and ☺ valid JavaScript variable names?
I noticed that in Internet Explorer (but, unfortunately, not in the other browsers I tested), you can use some Unicode variable names. This made my day, and I was absolutely delighted that I could ...
698
votes
15
answers
246k
views
What's the name for hyphen-separated case?
This is PascalCase: SomeSymbol
This is camelCase: someSymbol
This is snake_case: some_symbol
So my questions is whether there is a widely accepted name for this: some-symbol? It's commonly used in ...
664
votes
13
answers
193k
views
Why are exclamation marks used in Ruby methods?
In Ruby some methods have a question mark (?) that ask a question like include? that ask if the object in question is included, this then returns a true/false.
But why do some methods have ...
647
votes
11
answers
510k
views
Unit test naming best practices [closed]
What are the best practices for naming unit test classes and test methods?
This was discussed on SO before, at What are some popular naming conventions for Unit Tests?
I don't know if this is a very ...
573
votes
6
answers
398k
views
Is there a naming convention for git repositories?
For example, I have a RESTful service called Purchase Service. Should I name my repository:
purchaserestservice
purchase-rest-service
purchase_rest_service
or something else?
What's the convention? ...
552
votes
9
answers
348k
views
C# naming convention for constants?
private const int THE_ANSWER = 42;
or
private const int theAnswer = 42;
Personally I think with modern IDEs we should go with camelCase as ALL_CAPS looks strange. What do you think?
539
votes
6
answers
255k
views
What is the convention for word separator in Java package names?
How should one separate words in package names? Which of the following are correct?
com.stackoverflow.my_package (Snake Case using underscore)
com.stackoverflow.my-package (Kebab Case using hyphens)
...
470
votes
12
answers
526k
views
What is the purpose of the dollar sign in JavaScript?
The code in question is here:
var $item = $(this).parent().parent().find('input');
What is the purpose of the dollar sign in the variable name, why not just exclude it?
417
votes
9
answers
320k
views
Java Interfaces/Implementation naming convention [duplicate]
How do you name different classes / interfaces you create?
Sometimes I don't have implementation information to add to the implementation name - like interface FileHandler and class SqlFileHandler.
...
381
votes
3
answers
351k
views
Should I use "camel case" or underscores in Python? [duplicate]
So which is better and why?
def my_function():
or
def myFunction():
371
votes
11
answers
259k
views
Interface naming in Java [closed]
Most OO languages prefix their interface names with a capital I, why does Java not do this? What was the rationale for not following this convention?
To demonstrate what I mean, if I wanted to have ...
371
votes
5
answers
279k
views
What is the javascript filename naming convention?
Should files be named something-with-hyphens.js, camelCased.js, or something else?
I didn't find the answer to this question here.
360
votes
10
answers
247k
views
Enum Naming Convention - Plural
I'm asking this question despite having read similar but not exactly what I want at C# naming convention for enum and matching property
I found I have a tendency to name enums in plural and then 'use'...
359
votes
5
answers
374k
views
Maven artifact and groupId naming
I'm currently in the process of moving some project from Ant to Maven. Conformist as I am, I want to use well-established conventions for finding groupId and artifactId, but I can't find any detailed ...
353
votes
11
answers
138k
views
What does a type followed by _t (underscore-t) represent?
This seems like a simple question, but I can't find it with the Stack Overflow search or Google. What does a type followed by a _t mean? Such as
int_t anInt;
I see it a lot in C code meant to deal ...
332
votes
7
answers
299k
views
Coding Conventions - Naming Enums
Is there a convention for naming enumerations in Java?
My preference is that an enum is a type. So, for instance, you have an enum
Fruit{Apple,Orange,Banana,Pear, ... }
NetworkConnectionType{LAN,...
331
votes
2
answers
262k
views
What is the difference between .yaml and .yml extension? [duplicate]
I read them on YAML-wikipedia but not really understood the main difference between them. I saw there are someone using .yaml extension, however, Symfony2 use .yml extension.
YAML is a human-...
309
votes
3
answers
247k
views
PostgreSQL naming conventions
Where can I find a detailed manual about PostgreSQL naming conventions? (table names vs. camel case, sequences, primary keys, constraints, indexes, etc...)
303
votes
11
answers
235k
views
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?
299
votes
9
answers
96k
views
Correct Bash and shell script variable capitalization [closed]
I run across many shell scripts with variables in all caps, and I've always thought that there is a severe misunderstanding with that. My understanding is that, by convention (and perhaps by ...
295
votes
42
answers
60k
views
Anyone else find naming classes and methods one of the most difficult parts in programming? [closed]
So I'm working on this class that's supposed to request help documentation from a vendor through a web service. I try to name it DocumentRetriever, VendorDocRequester, DocGetter, but they just don't ...
293
votes
6
answers
220k
views
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 ...
290
votes
6
answers
256k
views
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 ...
286
votes
11
answers
87k
views
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 ...
286
votes
5
answers
128k
views
Redis key naming conventions? [closed]
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'...
277
votes
8
answers
99k
views
Why do variable names often start with the letter 'm'? [duplicate]
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?
274
votes
10
answers
107k
views
Java Naming Convention with Acronyms [closed]
What is the correct name for the following Java class:
DVDPlayer or DvdPlayer?
269
votes
13
answers
92k
views
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 ...
266
votes
2
answers
70k
views
What is the etymology of 'slug' in a URL? [closed]
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....
262
votes
6
answers
176k
views
JavaScript naming conventions [closed]
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 ...
260
votes
11
answers
151k
views
Should you use .htm or .html file extension? What is the difference, and which file is correct? [closed]
What is the difference between the .htm and .html file extension?
Why there are two of them?
Which is correct?
243
votes
8
answers
89k
views
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 ...
242
votes
11
answers
276k
views
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?
240
votes
2
answers
54k
views
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 ...
235
votes
18
answers
126k
views
URLs: Dash vs. Underscore [closed]
Is it better convention to use hyphens or underscores in your URLs?
Should it be /about_us or /about-us?
From usability point of view, I personally think /about-us is much better for end-user yet ...
233
votes
76
answers
17k
views
What's the best name for a non-mutating "add" method on an immutable collection? [closed]
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 ...
232
votes
4
answers
142k
views
SQL Server Index Naming Conventions [closed]
Is there some standard way to name indexes for SQL Server? It seems that the primary key index is named PK_ and non-clustered indexes typically start with IX_. Are there any naming conventions ...
230
votes
7
answers
171k
views
Are there best practices for (Java) package organization? [closed]
A little while ago, I saw a question answered here regarding the fine-grained organization of Java packages. For example, my.project.util, my.project.factory, my.project.service, etc.
Are there best ...
223
votes
10
answers
204k
views
Are there any naming convention guidelines for REST APIs? [closed]
When creating REST APIs, are there any guidelines or defacto standards for naming conventions within the API (eg: URL endpoint path components, querystring parameters)? Are camel caps the norm, or ...
214
votes
8
answers
209k
views
Node.js project naming conventions for files & folders
What are the naming conventions for files and folders in a large Node.js project?
Should I capitalize, camelCase, or under-score?
Ie. is this considered valid?
project-name
app
...