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
145
votes
7 answers

Why does Pylint object to single-character variable names?

I'm still getting used to Python conventions and using Pylint to make my code more Pythonic, but I'm puzzled by the fact that Pylint doesn't like single character variable names. I have a few loops like this: for x in x_values: …
Amanda
  • 12,099
  • 17
  • 63
  • 91
145
votes
9 answers

Using i and j as variables in MATLAB

i and j are very popular variable names (see e.g., this question and this one). For example, in loops: for i=1:10, % Do something... end As indices into a matrix: mat(i, j) = 4; Why shouldn't they be used as variable names in MATLAB?
Shai
  • 111,146
  • 38
  • 238
  • 371
142
votes
5 answers

Method names for getting data

Warning: This is a not very serious question/discussion that I am posting... but I am willing to bet that most developers have pondered this "issue"... Always wanted to get other opinions regarding naming conventions for methods that went and got…
Jason
  • 2,806
  • 2
  • 28
  • 38
140
votes
5 answers

Naming cookies - best practices

What should cookie names look like? Should they be: lower_case CamelCase Underscore_Camel_Case UPPER_CASE Or should they be something else?
Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201
136
votes
8 answers

C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass

What is the recommended approach to naming base classes? Is it prefixing the type name with "Base" or "Abstract" or would we just suffix it with "Base"? Consider the following: type: ViewModel e.g. MainViewModel, ReportViewModel base class:…
Soni Ali
  • 18,464
  • 16
  • 44
  • 53
133
votes
17 answers

What is your naming convention for stored procedures?

I have seen various rules for naming stored procedures. Some people prefix the sproc name with usp_, others with an abbreviation for the app name, and still others with an owner name. You shouldn't use sp_ in SQL Server unless you really mean…
DOK
  • 32,337
  • 7
  • 60
  • 92
131
votes
5 answers

Python naming conventions for modules

I have a module whose purpose is to define a class called "nib". (and a few related classes too.) How should I call the module itself? "nib"? "nibmodule"? Anything else?
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
128
votes
24 answers

Naming of ID columns in database tables

I was wondering peoples opinions on the naming of ID columns in database tables. If I have a table called Invoices with a primary key of an identity column I would call that column InvoiceID so that I would not conflict with other tables and it's…
Arry
  • 1,932
  • 4
  • 15
  • 21
128
votes
12 answers

Java boolean getters "is" vs "are"

I know that the convention in Java for boolean getters is include the prefix "is". isEnabled isStoreOpen But what if the subject is plural? That is, what if instead of wanting to know if a store is open, I wanted to know if all the stores are…
kodai
  • 3,080
  • 5
  • 32
  • 34
127
votes
4 answers

What is a proper naming convention for MySQL FKs?

Being that they must be unique, what should I name FK's in a MySQL DB?
Zombies
  • 25,039
  • 43
  • 140
  • 225
127
votes
8 answers

Naming "class" and "id" HTML attributes - dashes vs. underlines

or
? This site and Twitter use the first style. Facebook and Vimeo - the second. Which one do you use and why?
Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201
123
votes
2 answers

PostgreSQL: default constraint names

When creating a table in PostgreSQL, default constraint names will assigned if not provided: CREATE TABLE example ( a integer, b integer, UNIQUE (a, b) ); But using ALTER TABLE to add a constraint it seems a name is mandatory: ALTER…
Ian Mackinnon
  • 13,381
  • 13
  • 51
  • 67
122
votes
6 answers

Should Python class filenames also be camelCased?

I know that classes in Python are typically cased using camelCase. Is it also the normal convention to have the file that contains the class also be camelCase'd especially if the file only contains the class? For example, should class className also…
m4jesticsun
  • 1,799
  • 3
  • 12
  • 12
122
votes
10 answers

Naming conventions for "number of foos" variables

Let's suppose that I need to store the number of foo objects in a variable. Not being a native English speaker, I always wonder what's the best (= short and immediately clear) name for that var. foo_num? num_foo? no_foo? foo_no? or something…
Giacomo
  • 11,087
  • 5
  • 25
  • 25
122
votes
37 answers

Why shouldn't I use "Hungarian Notation"?

I know what Hungarian refers to - giving information about a variable, parameter, or type as a prefix to its name. Everyone seems to be rabidly against it, even though in some cases it seems to be a good idea. If I feel that useful information is…
Dustman
  • 5,035
  • 10
  • 32
  • 40