Coding standards a set of conventions and practices used in software, such as naming classes, variables, and files.
379
votes
17answers
24k 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 ...
23
votes
20answers
3k 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:
...
57
votes
13answers
12k 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?
28
votes
16answers
997 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.
...
51
votes
14answers
6k 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, ...
18
votes
3answers
2k 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 ...
3
votes
1answer
504 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 ...
34
votes
20answers
1k views
What should be in a coding standard? [closed]
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, ...
11
votes
10answers
4k 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 ...
9
votes
7answers
816 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);
}
...
175
votes
7answers
24k 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?
73
votes
56answers
10k views
Worst coding standard you've ever had to follow? [closed]
Have you ever had to work to coding standards that:
Greatly decreased your productivity?
Were originally included for good reasons but were kept long after the original concern became irrelevant?
...
68
votes
17answers
13k 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 ...
93
votes
18answers
5k 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 ...
62
votes
19answers
11k 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 ...
47
votes
16answers
4k 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 ...
51
votes
20answers
4k 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 ...
28
votes
6answers
5k 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 ...
14
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 ...
16
votes
17answers
3k views
What should be the maximum length of function
In your opinion what should be the maximum length of function, and if there are cases which are exception to this. Also give reasoning (if any) behind the answer.
15
votes
7answers
2k views
What is the appeal of Systems Hungarian?
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 ...
55
votes
24answers
3k 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 ...
27
votes
15answers
2k views
Space around operators? a=b/2; or a = b / 2; What are the arguments?
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 ...
16
votes
8answers
950 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
502 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
1k 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 ...
5
votes
5answers
879 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 ...
2
votes
2answers
297 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 ...
6
votes
2answers
114 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 ...
3
votes
2answers
78 views
What is your way to find the good conventions in your area? or any area?
What is your way to find the good conventions in your area?
My specific interests are anything connected to the Apache foundation, Ruby, RoR, PHP, MySQL, NoSql etc.
Is there a convention directory out ...
58
votes
17answers
3k 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 ...
62
votes
12answers
2k 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 ...
15
votes
8answers
840 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 ...
35
votes
12answers
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 ...
28
votes
7answers
3k views
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 ...
19
votes
19answers
5k 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;
...
16
votes
12answers
11k 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 ...
15
votes
14answers
1k 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 ...
33
votes
11answers
2k 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? ...
12
votes
1answer
620 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 ...
7
votes
4answers
452 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
944 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 ...
2
votes
8answers
515 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 ...
28
votes
13answers
2k 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 ...
9
votes
9answers
415 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 ...
2
votes
2answers
160 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 ...
10
votes
12answers
840 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
6answers
904 views
What to do with bad source code? [duplicate]
I have been contracted to modify an application for a software company and the source code is quite frankly, a mess. It's not commented much and the author is inconsistent with coding conventions. The ...
7
votes
7answers
962 views
Why would an employer ask for a 'long' code sample?
What would a large project that spanned multiple files and >1000 lines show to an employer that a few individual files and a couple hundred lines couldn't capture?
6
votes
8answers
574 views
How should I introduce a coding standard to my team?
First a bit of background: My current development manager is taking another opportunity the end of this week, leaving our team with four fulltime developers, a part-time intern and a web designer ...