Coding standards a set of conventions and practices used in software, such as naming classes, variables, and files.

learn more… | top users | synonyms (1)

503
votes
21answers
43k views

Where did the notion of “one return only” come from?

I often talk to Java 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 ...
22
votes
21answers
6k views

Self Documenting Code Vs. Commented Code

I had a search but didn't find what I was looking for, please feel free to link me if this question has already being asked. Earlier this month this post was made: ...
64
votes
13answers
16k views

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

Isn't the whole point of an interface to for multiple classes to adhere to a set of rules and implementations?
13
votes
10answers
8k views

Should I use switch statements or long if…else chains?

Often when I hear about the switch statement, its put off as a way to replace long if...else chains. But it seems that when I use the switch statement I'm writing more code that I would be just ...
29
votes
16answers
1k views

What parts of your coding standard contribute to quality code? [duplicate]

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. ...
25
votes
3answers
3k views

if ('constant' == $variable) vs. if ($variable == 'constant')

Lately, I've been working a lot in PHP and specifically within the WordPress framework. I'm noticing a lot of code in the form of: if ( 1 == $options['postlink'] ) Where I would have expected to ...
63
votes
17answers
12k views

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 ...
70
votes
10answers
13k views

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, ...
5
votes
1answer
2k views

Database Application Design Best Practices [duplicate]

Once upon a time it was common practice for both the business logic and database logic to be written in the same language (eg PL/SQL, Transact SQL, etc), more recently the practice is to separate the ...
36
votes
11answers
3k views

Why are cryptic short identifiers still so common in low-level programming?

There used to be very good reasons for keeping instruction / register names short. Those reasons no longer apply, but short cryptic names are still very common in low-level programming. Why is this? ...
74
votes
16answers
18k views

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 ...
10
votes
7answers
1k views

In C and C++, what methods can prevent accidental use of the assignment(=) where equivalence(==) is needed?

In C and C++, it is very easy to write the following code with a serious error. char responseChar = getchar(); int confirmExit = 'y' == tolower(responseChar); if (confirmExit = 1) { exit(0); } ...
2
votes
2answers
413 views

Collaborative work (small team) - Best practices [closed]

I'm currently working in a very small team of programmers (2-3) and I'm looking for advices/best practices on how to organise our work. We're all working on the same application using PHP. Today we're ...
254
votes
9answers
57k views

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?
61
votes
17answers
4k views

Recommendations for teaching junior programmers good coding style

I am a big fan of good coding style, producing clean, clear code that runs well and is easy to use and integrate into larger systems. I believe that we programmers are essentially craftspeople who ...
104
votes
18answers
8k views

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 ...
65
votes
19answers
12k views

How important is it to reduce the number of lines in code?

I am a Software developer who works on J2SE (core java). Often during our code reviews we are asked to reduce the number of lines in our code. It's not about removing redundant code, it's about ...
38
votes
6answers
16k views

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 ...
55
votes
20answers
6k views

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 ...
17
votes
10answers
2k views

Does your company have a coding standard?

I recently saw that Microsoft released a coding standards document (All-In-One Code Framework Coding Standards) and it got me thinking... The company that I work for has no formal coding standards at ...
33
votes
7answers
9k views

Excessive use “final” keyword in Java [duplicate]

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 ...
21
votes
18answers
4k views

What should be the maximum length of a function? [closed]

What should be the maximum length of a function? And are there cases which are an exception to this?
10
votes
5answers
4k views

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 ...
37
votes
13answers
2k views

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 ...
16
votes
8answers
2k views

What is the appeal of Systems Hungarian? [closed]

In What naming guidelines do you follow?, the author says: Also I prefer to code using hungarian notation from Charles Simonyi. I've run in to several programmers who still prefer to use ...
16
votes
14answers
2k views

Coding standards and coding style, is it that much important?

There are a lot of ways of typing code, but I can't understand what is the good reason to adopt a certain standard or style if it does not change the way the code can be read and understood. Everyone ...
27
votes
15answers
4k views

Space around operators? a=b/2; or a = b / 2; What are the arguments? [closed]

Personally I prefer space around operators. For me it makes the code much more readable. What are the arguments not have space around them? Line length? An example from the Python style guide (I ...
17
votes
8answers
1k views

Are 'edited by' inline comments the norm in shops which use revision control?

The senior dev in our shop insists that whenever code is modified, the programmer responsible should add an inline comment stating what he did. These comments usually look like // YYYY-MM-DD <User ...
12
votes
5answers
602 views

Can there be too much uniformity in coding standards?

Is there such a thing as too much uniformity? Where I work we of course have standards including naming conventions, architectures, frameworks to leverage etc. However lately there has been a lot of ...
8
votes
9answers
2k views

What C++ coding standard do you use? [closed]

For some time now, I've been unable to settle on a coding standard and use it concistently between projects. When starting a new project, I tend to change some things around (add a space there, remove ...
7
votes
2answers
127 views

What do you do when working with multiple languages with different capitalization schemes?

I'm making a webapp using Django. The Python convention for naming variables is lowercase_with_underscores, but the Javascript convention is camelCase. In addition, I've seen many people use ...
4
votes
2answers
677 views

What package name to choose for a small, open-source Java project?

I'd like to publish a small open-source library in Java. I wonder what package name should I choose? I'm not a company and I don't have a domain that I could use as the basis for naming the package ...
0
votes
4answers
305 views

Coding convention regarding the usage of underscores [closed]

There seems to be divided opinion on this subject, and I wanted to get people's insights on whether they've found using underscore prefixes and suffixes to be helpful with coding or not. You know, ...
49
votes
17answers
5k views

Working on someone else's code

I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code, either adding new features over the existing ones or modifying the ...
65
votes
12answers
3k views

Is there a point to including a “change log” in every code file when you are using version control?

I was under the impression that a version control system eliminated the need to have "change logs" plastered everywhere in the code. I've often seen the continued use of change logs, including big ...
14
votes
7answers
3k views

Unit test coding standards

Usually when talking about coding standards we refer to the code of the program itself, but what about the unit tests? Are there certain coding standards guidelines that are unique to unit tests? What ...
15
votes
8answers
955 views

How to convince my boss to improve code quality? [duplicate]

The place I'm working for is a service provider. We have a lot of services, which are written to deal with deadline, so their code are really terrible: No coding convention, everyone codes in his ...
20
votes
17answers
9k views

How do you name your private variables in C#? [closed]

What is the best practice, most commonly accepted naming conventions for private variables in C#? private int myInteger; private int MyInteger; private int mMyInteger; private int _myInteger; ...
20
votes
12answers
16k views

What does XXX mean in a comment?

What do people generally mean whenever you see XXX in a comment. Occasionally, I'll see a comment like this: # XXX - This widget really should frobulate the whatsit Of course, I can tell what the ...
14
votes
1answer
2k views

Why Bootstrap 3 changes camelCase to dashes - is it more readable?

I'm wondering what's the reasoning behind Bootstrap's decision to change all camel case names into hyphenated names in v3.0. I searched on Google, and looked in a few books, but I can only find ...
56
votes
24answers
4k views

Is writing comments inside methods not a good practice? [duplicate]

A friend told me that writing comments inside methods is not good. He said that we should have comments only for the method definitions(javadocs) but not inside the method body. It seems he read in a ...
6
votes
3answers
530 views

How to Implement Error Handling [closed]

Even though I've programmed on a professional level for some years I still do not fully understand error handling. Although my applications work fine, the error handling isn't implemented at a ...
2
votes
8answers
762 views

tips, guidelines, points to remember for rendering professional code? [closed]

I'm talking about giving clients professional looking code. The whole nine yards, everything you hardcore professional highly experienced programmers here probably do when coding freelance or for the ...
22
votes
14answers
896 views

How do you overcome your own coding biases when handed legacy code?

As programmers, we often take incredible pride in our skills and hold very strong opinions about what is 'good' code and 'bad' code. At any given point in our careers, we've probably had some legacy ...
7
votes
3answers
729 views

Can anyone recommend coding standards for TSQL?

We've long had coding standards for our .Net code, and there seem to be several reputable sources for ideas on how to apply them which evolve over time. I'd like to be able to put together some ...
4
votes
6answers
2k views

Naming conventions for variables [closed]

When programming, what naming conventions do you use for your variables? I don't mean when the name of the variable should be obvious; ie. sum, total, first, last. But when you name variables that ...
3
votes
2answers
300 views

Are there standard style guides for PHP?

I've been working in a very small team for PHP development and we've been using an ad-hoc, "Invented Here" style guide. Now that our team and codebase is growing, we would like to use a more ...
29
votes
13answers
3k views

Do you prefix variable names with an abbreviation of the variable types? (Hungarian Notation)

In my current job, there are no coding guidelines. Everyone pretty much codes the way he wants. Which is fine, since the company is small. However, one new guy recently proposed to always use ...
10
votes
12answers
1k views

Maintainability of Boolean logic - Is nesting if statements needed?

Which of these is better for maintainability? if (byteArrayVariable != null) if (byteArrayVariable .Length != 0) //Do something with byteArrayVariable OR if ((byteArrayVariable != ...
9
votes
9answers
443 views

Studies on code documentation productivity gains/losses

After much searching, I have failed to answer a basic question pertaining to an assumed known in the software development world: WHAT IS KNOWN: Enforcing a strict policy on adequate code ...