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.

549 questions
70
votes
20 answers

Using single characters for variable names in loops/exceptions

I've had a couple of discussions with a co-worker about the use of single letter variable names in certain circumstances inside our codebase, at which we both disagree. He favours more verbose naming convention for these, and I do not. There are…
Dan Atkinson
  • 243
  • 1
  • 4
  • 8
40
votes
13 answers

Handling Coding Standards at Work (I'm not the boss)

I work on a small team, around 10 devs. We have no coding standards at all. There are certain things that have become the norm but some ways of doing things are completely disparate. My big one is indentation. Some use tabs, some use spaces, some…
Josh Johnson
  • 1,141
34
votes
20 answers

What should be in a coding standard?

What should be in a good (read:useful) coding standard? Things the code should have. Things the code shouldn't have. Should the coding standard include definitions of things the language, compiler, or code formatter enforces? What about metrics…
C. Ross
  • 2,926
32
votes
16 answers

What parts of your coding standard contribute to quality code?

In response to This Question, I ask: What are the best parts of your coding standard? What are the best practices that help with code quality, reliability, maintainability, readability, etc. Please include the language, the item from the standard,…
AShelly
  • 5,793
18
votes
4 answers

Adding Units To Magic Numbers

Considering this question and the most upvoted answer, and his specific example of public static final int THREE = 3; might it make sense to allow this sort of usage if we added units to the declaration? I mean like this: public static final int…
Onorio Catenacci
  • 2,947
  • 3
  • 27
  • 37
13
votes
10 answers

Is it OK to reformat another developers code while modifying/adding to a module?

While developing in a group atmosphere and adding or modifying features in some code base. Is it considered offensive or impolite to reformat the previous developers code to bring it up to current coding standards? I understand that standards have…
wfoster
  • 483
13
votes
9 answers

Does having to scroll horizontally make code less readable?

Well, does it? Is it considered bad practice? IMO, it is less readable. I hate having to scroll to the right, then back left, right, left, and so on. It makes coding more painful and confuses me sometimes. For example, anytime I am coding a long…
Mr. Ant
  • 431
8
votes
11 answers

When, if ever, can code standards be ignored?

My company has decided to use stored procedures for everything dealing with the database (because they didn't know of any other way besides raw SQL), and as the saying goes "When in Rome..." so I try to follow. Recently I had to add a hack fix that…
Wayne Molina
  • 15,684
5
votes
2 answers

Should functions always return a success/failure status?

Possible Duplicate: When and why you should use void (instead of i.e. bool/int) What is the reasoning behind making all functions (and methods!) return a uniform type, usually int, as a status? To me it feels odd; especially when you're calling…
4
votes
3 answers

Organization level Coding Standard

I have been asked to document coding standards for javascript at my organization level. Does maintaining coding standards at my organization level sound worth enough? kind of old timers? with the way, how javascript evolving with frameworks like…
4
votes
4 answers

Naming convention for a method that both sets and gets

Let's say we have a method setFoo that sets a flag in a Bar object e.g. class Baz { public void setFoo(String foo)( ... } } inside setFoo, the method is doing some expensive load of the Bar object from the database. class Baz { …
Eran Medan
  • 1,043
3
votes
1 answer

Naming convention for main arguments

I recently started using arguments in my main program (here written in C++ but could be any programming language) #include int main(int argn, char* argv[]) { // do stuff depending on argv[1], argv[2], etc. } For now I am using…
vanna
  • 337
2
votes
2 answers

Is a try-catch-finally clause appropriate for production code?

While browsing around on SO, I came across an answer that suggested using a try-catch-finally clause to fix the problem he was having. (A rare bug that sometimes happened to his users). Someone commented that it was a valid solution, but he said it…
Milo
  • 225
1
vote
4 answers

What is the disadvantage of learning to code by doing?

It seems like the consensus is to learn by doing when it comes to programming, well that seems like the advice given to most beginners. How will beginners learn to write efficient code when they dive head first?
0
votes
4 answers

Where to find common database abbreviations in Spanish

I'm doing a little pro bono work for an organization in Central America. I'm ok at Spanish and my contacts are perfectly fluent but are not techincal people. Even if they don't care what I call some fields in a database I still want to make as clean…
user37735