Questions tagged [coding-standards]

Coding standards, or coding conventions, are sets of rules or guidelines designed to govern the process of code production in a software project. They're usually based on industry best practices or generally accepted conventions. They include naming conventions, style, prohibited features, and more.

Coding standards, or coding conventions, are, in essence, sets of rules or guidelines designed to govern the process of code production in a software project, based on industry best practices, and, as such, they have been around for almost as long as programming itself. They are often applicable to a specific programming language, library, framework or environment, but they can also be language-independent, focusing mostly on style.

While coding standards can be somewhat informal, defined by a small team or corporation for internal use, most adopted standards aim to provide a formal definition of their rules, the reasoning behind each rule, and whether (and how) compliance with those rules may be verified. The main advantage of adopting coding standards, regardless of the formality and reasoning of a standard, is to have consistency across a code base.

In practice, to a programmer, complying with coding standards means restricting oneself to a subset of the programming language's features or syntax rules, in virtue of consistency, robustness and code readability. This tends to result in increased team productivity and reduced maintenance and production costs.

Here is a short description of programming style from Wikipedia:

Programming style is a set of rules or guidelines used when writing the source code for a computer program.

545 questions
1330
votes
14 answers

Where did the notion of "one return only" come from?

I often talk to programmers who say "Don't put multiple return statements in the same method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's confusing." When they show me solutions with a single…
670
votes
9 answers

Why is 80 characters the 'standard' limit for code width?

Why is 80 characters the "standard" limit for code width? Why 80 and not 79, 81 or 100? What is the origin of this particular value?
fredley
  • 6,451
  • 3
  • 15
  • 17
326
votes
15 answers

Do I need to use an interface when only one class will ever implement it?

Isn't the whole point of an interface that multiple classes adhere to a set of rules and implementations?
Lamin Sanneh
  • 3,975
  • 3
  • 19
  • 19
245
votes
15 answers

Is it wrong to use a boolean parameter to determine behavior?

I have seen a practice from time to time that "feels" wrong, but I can't quite articulate what is wrong about it. Or maybe it's just my prejudice. Here goes: A developer defines a method with a boolean as one of its parameters, and that method calls…
Ray
  • 2,460
  • 3
  • 15
  • 10
150
votes
17 answers

Coding standard for clarity: comment every line of code?

I've worked in shops that produce life critical software and I've dealt with commenting rules that were meant to keep the code readable and potentially save lives. In my experience though the requirement becomes a brain dead chore to be ticked off…
149
votes
14 answers

Why does Uncle Bob suggest that coding standards shouldn't be written down if you can avoid it?

While I was reading this question, the top voted answer quoted Uncle Bob on coding standards, but I was confused by this tip: Don't write them down if you can avoid it. Rather, let the code be the way the standards are captured. This bounced in…
Nolan Akash
  • 1,294
  • 2
  • 10
  • 11
136
votes
4 answers

Excessive use "final" keyword in Java

While I understand what the final keyword is used for in the context of classes and methods as well as the intent of its use for in regards to variables; however, the project I just started working on seems to have an excessive number of them and…
rjzii
  • 11,274
  • 6
  • 46
  • 71
135
votes
10 answers

Why do most of us use 'i' as a loop counter variable?

Has anyone thought about why so many of us repeat this same pattern using the same variable names? for (int i = 0; i < foo; i++) { // ... } It seems most code I've ever looked at uses i, j, k and so on as iteration variables. I suppose I picked…
kprobst
  • 641
  • 2
  • 6
  • 9
133
votes
19 answers

Can a function be too short?

Whenever I find myself writing the same logic more than once, I usually stick it in a function so there is only one place in my application I have to maintain that logic. A side effect is that I sometimes end up with one or two line functions such…
Mark Brown
  • 603
  • 2
  • 6
  • 7
127
votes
6 answers

Method vs Function vs Procedure

Simple question, but I often hear these three terms defined with such ferocity, but which have been known to me to mean different things over the years. What are the "correct" definitions of "Procedures", "Methods", "Function", "Subroutines", etc?
Django Reinhardt
  • 1,510
  • 3
  • 13
  • 18
112
votes
4 answers

Does a `long` ban make sense?

In today's cross-platform C++ (or C) world we have: Data model | short | int | long | long long | pointers/size_t | Sample operating systems ... LLP64/IL32P64 16 32 32 64 64 Microsoft Windows (x86-64…
Martin Ba
  • 7,578
  • 7
  • 34
  • 56
106
votes
16 answers

What is the benefit of not using Hungarian notation?

One of the things I struggle with is not using Hungarian notation. I don't want to have to go to the variable definition just to see what type it is. When a project gets extensive, it's nice to be able to look at a variable prefixed by 'bool' and…
user29981
105
votes
47 answers

Make a big deal out of == true?

There is a colleague of mine who constantly writes: if (someBool == true) It drives me up the wall! Should I make a big deal of it or just drop it?
JoelFan
  • 7,025
  • 4
  • 38
  • 53
98
votes
8 answers

Should interface names begin with an "I" prefix?

I have been reading "Clean Code" by Robert Martin to hopefully, become a better programmer. While none of it so far has been really ground breaking it has made me think differently about the way I design applications and write code. There is one…
Charles Sprayberry
  • 1,606
  • 1
  • 12
  • 21
94
votes
14 answers

How can I avoid always feeling like if I completely rebuilt my program from scratch I'd do it much better?

I have learned a significant amount of coding, however, it's always been in a scientific environment (not computer science), completely self-taught without anyone to guide me in the right direction. Thus, my coding journey has been ... messy. I've…
1
2 3
36 37