Questions tagged [conventions]
123 questions
116
votes
6 answers
Is it better to use assert or IllegalArgumentException for required method parameters?
In Java, which is more highly recommended, and why? Both types will throw exceptions, so in that regard handling them is the same. assert is slightly shorter, but I'm not sure how much that matters.
public void doStuff(Object obj) {
assert obj…

Daenyth
- 8,077
- 3
- 31
- 46
101
votes
10 answers
Should I follow a bad coding style just to follow the established conventions at my workplace?
I've been working at my job for about a year. I primarily do work in our GUI interface which uses methods from a C backend, but I generally don't have to deal with them except for return values. Our GUI is structured pretty reasonably, given our…

Justin
- 913
- 2
- 6
- 8
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
79
votes
3 answers
"state" or "status"? When should a variable name contain the word "state", and when should a variable name instead contain the word "status"?
Reading code and discussions pertaining to code, I often see the words "state" and "status" used interchangeably, but the following tendencies seem to exist:
When a variable holds a value intended to indicate that something is in a certain state,…

Will
- 901
- 1
- 6
- 7
57
votes
5 answers
Should I really use all uppercase for my constants?
I am a Python programmer primarily who uses pylint for linting source code. I am able to eliminate all of the warnings except one: Invalid name for a constant. Changing the name to all caps fixes it, but am I really supposed to do that? If I do it,…

Abhishek Kumar
- 681
- 1
- 5
- 7
49
votes
3 answers
Why does convention say DB table names should be singular but RESTful resources plural?
It's a pretty established convention that database table names, in SQL at least, should be singular. SELECT * FROM user; See this question and discussion.
It's also a pretty established convention that RESTful API resource names should be plural.…

smitelli
- 599
- 1
- 4
- 4
38
votes
8 answers
Is there a conventional way to combine file path strings?
In an example:
var assets = "images/"
var sounds = assets+"sounds/"
Is it more conventional to put the slash on the back of a file path?
var assets = "/images"
var sounds = assets+"/sounds"
Is there another method that is a good common practice?

iiridescent
- 499
- 1
- 4
- 7
36
votes
5 answers
Is it enough for methods to be distinguished just by argument name (not type)?
Is it enough for methods to be distinguished just by argument name (not type) or is it better to name it more explicitly?
For example T Find(int id) vs T FindById(int id).
Is there any good reason to name it more explicitly (i.e. adding ById)…

Konrad
- 1,529
- 2
- 17
- 32
21
votes
6 answers
Is it okay to go against all-caps naming for enums to make their String representation simpler?
Several times I've seen people use title-case or even all lower-case naming for enum constants, for example:
enum Color {
red,
yellow,
green;
}
This makes working with their string form simple and easy, if you want to do throw new…

codebreaker
- 1,694
- 1
- 18
- 24
20
votes
4 answers
Why do trees grow downward?
Why do trees grow downward in computer science?
I have a feeling it goes back to a printer, and that a program traversing a tree first prints the root, and uses the notion of a bottomless stack of paper to express the indefinite levels of recursion…

maxpolk
- 433
- 3
- 10
19
votes
10 answers
[YYYY].[MM].[DD].[hh][mm] vs. [major].[minor].[revision]
Possible Duplicate:
What “version naming convention” do you use?
I am currently debating between the traditional versioning convention [major].[minor].[revision] and my own, almost whimsical, [YYYY].[MM].[DD].[hh][mm] for a new project I am…

ef2011
- 301
- 2
- 6
15
votes
3 answers
How to deal with Classes having the same name (different packages)
Me and my R&D team maintain a large codebase. We've divided our business logic into multiple packages. some of which have classes with identical names.
As you can guess, the names conflict when both classes are referenced in the same Java…

Jossef Harush Kadouri
- 273
- 1
- 3
- 9
14
votes
3 answers
Naming convention for functions which have side effects?
I heard somebody say their language has a convention where the names of functions which mutate state must end with an exclamation point. I'm trying to write more functional code and I like the idea of somehow marking functions according to their…

Roger Heathcote
- 383
- 2
- 7
14
votes
4 answers
Why is the use of conjunctions in method names a bad naming convention?
In my team, we work closely with a few software architects. They approve all design decisions of our projects, do some code reviews etc.
Our projects consist mainly of backend functionality implemented in PHP using the Symfony 2 framework. So…

Radu Murzea
- 1,810
- 2
- 18
- 24
12
votes
1 answer
Naming convention for iOS/OSX open-source projects
Not always but most of the time, you will find iOS or Mac OS X open-source projects with names starting with the initial letters of the author first and last names. If a project were to be authored by Nick Leblanc, the project would be read as…

Stéphane Bruckert
- 344
- 1
- 12