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
91
votes
12 answers

Function names in C++: Capitalize or not?

What's the convention for naming functions in C++? I come from the Java environment so I usually name something like: myFunction(...) { } I've seen mixed code in C++, myFunction(....) MyFunction(....) Myfunction(....) What's the correct…
user69514
  • 26,935
  • 59
  • 154
  • 188
91
votes
15 answers

Using underscores in Java variables and method names

Even nowadays I often see underscores in Java variables and methods. An example are member variables (like "m_count" or "_count"). As far as I remember, to use underscores in these cases is called bad style by Sun. The only place they should be used…
Georgi
  • 4,402
  • 4
  • 24
  • 20
88
votes
5 answers

Naming convention for const object keys in ES6

Is there a recommended naming convention for key names within a const object in es6? I haven't been able to find a resource which states if they should be uppercase or lowercase. const COLOR_CODES = { BLUE: 1, RED: 1 }; vs const COLOR_CODES =…
mralexlau
  • 1,823
  • 1
  • 16
  • 23
88
votes
7 answers

Android naming convention

I am looking for a thorough Android naming convention suggestion. I found a little bit here: http://source.android.com/source/code-style.html#follow-field-naming-conventions which says: Non-public, non-static field names start with m. Static field…
dorjeduck
  • 7,624
  • 11
  • 52
  • 66
85
votes
3 answers

"items list" or "item list"

English is not my native language and I can't understand how to write the specified samples right. When you say something what aggregates plural object such as "collection of stamps" you can say alternatively: "stamps collection", am I right? If you…
Slaus
  • 2,086
  • 4
  • 26
  • 41
85
votes
4 answers

Naming conventions of composed package names

I want to create a package named form validator. Is it better to write form_validator, formValidator or formvalidator? I want to mention that I want to avoid form.validator. And that form-validator is forbidden.
Mohamed Taboubi
  • 6,663
  • 11
  • 55
  • 87
85
votes
2 answers

C# method naming conventions: ToSomething vs. AsSomething

As I was writing some extension methods for my business logic objects, I came to the question of renaming the conversion methods. someObject.ToAnotherObject() would go fine with the widely used object.ToString(). However LINQ, for example, mixes up…
Physikbuddha
  • 1,652
  • 1
  • 15
  • 30
85
votes
7 answers

What's the word for "Enable/Disable"?

When I want to comment code about control Enable/Disable and when I want to discuss with people about the control Enable/Disable, I really hope there is actually a word to it instead of typing or saying "Enable/Disable". Currently I use the word…
Led
  • 1,021
  • 1
  • 8
  • 11
85
votes
7 answers

Java data transfer object naming convention?

Given this scenario where you have "transfer objects" (POJO's with just getters/setters) which are passed by a client library to your API, what is the best way to name the transfer objects? package com.x.core; public class Car { private…
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
84
votes
9 answers

Parameter naming: filename or fileName?

I try to be grammatically correct in my naming*. I've always used filename instead of fileName. The java convention also seems to use this, but FxCop prefers fileName. There's a discussion on WikiPedia about it. The more I read, the more I feel…
Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
81
votes
9 answers

Naming Conventions: What to name a boolean variable?

I need a good variable name for a boolean value that returns false when an object is the last in a list. The only decent name I can come up with is 'inFront', but I don't think that is descriptive enough. Another choose would be 'isNotLast'. This…
Berek Bryan
  • 13,755
  • 10
  • 32
  • 43
80
votes
6 answers

Naming convention for a C# Dictionary

How do we name a dictionary variable? Say in my method I have Dictionary> dictionary;, where the keys of the dictionary are country names and the values are lists of province/state names. How should I rename dictionary? I know…
Shuo
  • 4,749
  • 9
  • 45
  • 63
80
votes
12 answers

Naming Conventions: What to name a method that returns a boolean?

I have an interface in C# that helps retrieving of data from a custom archive on server. The interface looks like this: public interface IRetrieveData { bool OkToRetrieve(SomeData data); // Method in question... bool RetrieveToLocal(SomeData…
ashtee
  • 993
  • 1
  • 7
  • 10
80
votes
10 answers

Should a property have the same name as its type?

I've sometimes seen code written like this : public class B1 { } public class B2 { private B1 b1; public B1 B1 { get { return b1; } set { b1 = value; } } } i.e. class B2 has a property named "B1", which is also of…
Moe Sisko
  • 11,665
  • 8
  • 50
  • 80
79
votes
8 answers

Valid characters in a Java class name

What characters are valid in a Java class name? What other rules govern Java class names (for instance, Java class names cannot begin with a number)?
Zach
  • 2,145
  • 3
  • 17
  • 32