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

learn more… | top users | synonyms (1)

1
vote
6answers
2k views

Static classes and/or singletons — How many does it take to become a code smell? [on hold]

In my projects I use quite a lot of static classes. These are usually classes that naturally seem to fit into a single-instance type of thing. Many times I use static classes and recently I've started ...
1
vote
2answers
146 views

Which do you code first, MVC? [on hold]

I have been coding for a good bit, and I found a project I want to work on -- a python web app using django + mongodb. I know what I want my web app to do. When you are in this circumstance (just ...
218
votes
9answers
36k 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?
29
votes
6answers
3k views

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 ...
11
votes
10answers
7k 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 ...
17
votes
8answers
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 ...
3
votes
4answers
474 views

Hungarian Notations/Systems Hungarian Should I? [closed]

I was wondering would it be worth using a form of standard such as Hungarian Notation/Systems Hungarian? Why would I bother if everything I'm doing now is working fine?
0
votes
1answer
32 views

How using tab affects commands like diff

In the page at http://pear.php.net/manual/en/standards.indenting.php, it is advised to use space instead of tab as it causes issue with diff, patches. Here is the excerpt from the page. Use an ...
3
votes
3answers
310 views

Is it common to use code you don't understand? [closed]

I have been working on a project recently that uses a pretty comprehensive framework built by someone else. The framework is free to use commercially and privately as anybody sees fit, so there are no ...
2
votes
3answers
349 views

Coding standards for c# [duplicate]

I wanted to know if there are some default standards for writing c# code. By default I mean may be something officially from Microsoft, or any other organization. I am looking for something where I ...
19
votes
11answers
1k views

Are long functions acceptable if they have internal structure?

When dealing with complicated algorithms in languages with support for nested functions (such as Python and D) I often write huge functions (because the algorithm is complicated) but mitigate this by ...
21
votes
14answers
837 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 ...
1
vote
1answer
65 views

Are there any standards for separating different kinds of comments (explanatory, debug, to-do, etc.)?

For a while now I've been in the habit of differentiating different kinds of comments in my code. //this is an explanatory comment //!this line was commented out for debug purposes, DO NOT SHIP WITH ...
22
votes
21answers
5k 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: ...
1
vote
1answer
209 views

HTML DOM in .NET: following specification vs. following language standards [closed]

Let's say we're implementing HTML DOM in C#. Naming conventions are different: HTMLCollection interface/class vs. IHtmlCollection/HtmlCollection, body attribute vs. Body property etc. Behavior is ...
0
votes
3answers
100 views

Long vs short scripts? Big vs small scripts? [closed]

As a programmer, I have always wondered whether it is preferable to write (a) short modular functions that are each stored in their own script (i.e., file) or (b) long comprehensive scripts that ...
3
votes
2answers
566 views

Are there any industry standards that define code quality?

Our specific situation is that we are creating an agreement between ourselves and another team for shared control or use of a PHP based web application that we have been building. We have a set of ...
0
votes
4answers
150 views

What is the industry norm for naming standard for gui object event handlers in C# [closed]

Lets say you have a button objects on a form with a click event (c#/.Net). How is the event handler normally named throughout the industry? fooButton_Click fooButtonClick (or if you like ...
5
votes
2answers
225 views

Is Convention Over Configuration “Knowledge in the World” or “Knowledge In Your Head”?

In Don Norman's seminal work "The Design of Everyday Things", the author coined the phrases and explains the difference between "Knowledge in the World" and "Knowledge In Your Head"; an example of ...
0
votes
0answers
121 views

Commenting MVC applications [duplicate]

I've recently realised that my workplace doesn't comment their ASP.NET MVC applications. By 'doesn't document', I mean there is probably 1 line of comment per model/view/controller. No file purpose, ...
3
votes
1answer
113 views

Do you have to ban atomics to get good tool support for race detectors?

It seems that Helgrind treats atomics the same way as normal read/write operations. So, using atomics will result in lots of false positives. I don't know exactly how ThreadSanitizer deals with ...
-1
votes
5answers
178 views

Is there a history behind the placement of code block markers? [closed]

When I started learning programming, I noticed that everybody (lecturers, authors, brainwashed fellow students, et cetera) placed code block markers in the following way: if(userIsBest==true){ ...
36
votes
6answers
13k 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 ...
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?
1
vote
2answers
95 views

Coding convention question about AS3 duplicate variable definition

AS3's got some awkward rules about variable scope, due to its use of hoisting. I don't like pointlessly leaving a bunch of compiler warnings lying around, but it's more important to me for my code to ...
1
vote
4answers
1k views

Is using `continue`, `break` in non-`switch` loops and `?:` bad practice? [duplicate]

Back in college I've been told that using break; and continue; outside switch statements (e.g. to escape for or while loops) is wrong, bad practice and bad habits at the same time because it only ...
0
votes
1answer
87 views

PHP - PSR 0 - Configuration Constants

This question is about PSR-0 autoloaded libraries and the way main configuration constants should be declared and used. From your point of view (lib/framework developer), where/how should be declared ...
10
votes
6answers
1k views

Javascript naming conventions

I am from Java background and am new to JavaScript. I have noticed many JavaScript methods using single character parameter names, such as in the following example. doSomething(a,b,c) I don't like ...
1
vote
2answers
99 views

Should I Aggregate Web API Errors?

The Situation We are writing a REST API that performs validation up-front. The code is written such that it tries to find as many errors as possible. However, each error might correspond to a ...
3
votes
2answers
129 views

Unit testing method name standard for overloaded methods

I have read several posts which discuss coding standard for naming the unit test methods for improving readability. I follow this NameOfMethod_ExpectedBehavior_WhenSomeScenario, but now I am confused ...
22
votes
8answers
1k views

Should comments say WHY the program is doing what it is doing? (opinion on a dictum by the inventor of Forth) [duplicate]

The often provocative Chuck Moore (inventor of the Forth language) gave the following advice[1]: Use comments sparingly! (I bet that's welcome.) Remember that program you looked through - the ...
12
votes
7answers
2k views

Avoid too complex method - Cyclomatic Complexity

Not sure how to go about this method to reduce Cyclomatic Complexity. Sonar reports 13 whereas 10 is expected. I am sure nothing harm in leaving this method as it is, however, just challenging me how ...
3
votes
4answers
3k views

Is using “out” or “ref” parameters in Java methods to return extra values bad?

I happened to create a mutable class like this: class Mutable<T> { private T value; public Mutable() { this.value = null; } public Mutable(T value) { this.value = value; } T ...
4
votes
4answers
294 views

Why is the following naming guideline different between OO and non-OO languages?

I am working with a non-OO language and I'm trying to name my routines consistently. I came acrross the following guideline from Steve McConnell's Code Complete: To name a procedure, use a strong ...
0
votes
1answer
186 views

Where does the tradition of shell prompts in code snippets come from?

Most code samples I see that demonstrate shell code preface each command with $. Having a prefix makes sense, but I'm confused as to why $ is used in particular. Some other symbol, like !, that can be ...
469
votes
21answers
38k 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 ...
0
votes
1answer
119 views

Should the helper function in class be defined before the usage or after

I need to do the code review of fellow members. One of the member always defined the helper functions at the bottom and use them at top e,g class Sample { public function SendFile(){ file = ...
0
votes
4answers
280 views

Usage of magic strings/numbers [closed]

This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
4
votes
4answers
425 views

Using a function's return value as an if condition, good practice?

Do you think it is a good practice to use function return values as if conditions? I'm coding in PHP atm but it holds for many other languages. if(isTheConditionMet($maybeSomeParams)) { } or $res ...
1
vote
3answers
232 views

“state” or “status”? When should a variable name contain the word “state”, and when should a variable name instead contain the word “status”? [closed]

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 ...
27
votes
15answers
3k 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 ...
12
votes
9answers
990 views

How important are code formatting guidelines? [closed]

Coding standards are common in any software development organization, but how important are they to follow? I can understand the need for some consistency, but when dealing with simple things like ...
2
votes
0answers
101 views

Script language native extensions - avoiding name collisions and cluttering others' namespace

I have developed a small scripting language and I've just started writing the very first native library bindings. This is practically the first time I'm writing a native extension to a script ...
-1
votes
1answer
49 views

Convention for using super class functions and members

Is there a Convention or common way for using super class functions and members? For example the super class has the function protected void Foo() and protected int myInt; In subclass would I want ...
48
votes
12answers
3k views

Is it reasonable to null guard every single dereferenced pointer?

At a new job, I've been getting flagged in code reviews for code like this: PowerManager::PowerManager(IMsgSender* msgSender) : msgSender_(msgSender) { } void PowerManager::SignalShutdown() { ...
13
votes
3answers
524 views

When is it appropriate to use colour in a command-line application?

Currently I have a command-line application in C called btcwatch. It has a -C option that it can receive as an argument that compares the current price of Bitcoin with a price that was stored ...
2
votes
2answers
286 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 ...
49
votes
17answers
4k 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 ...
4
votes
1answer
245 views

Is CType() ever the preferred option?

Is there any time CType() is the proper option over other methods? I did plenty of thinking on this myself, but wanted to put the question in hopes there would be answer to my question so I can put ...
6
votes
2answers
596 views

Java convention for if/else if order

I have an if/else if structure that on some cases does nothing. From the code I have seen in my career, the "empty" case is normally left out. But when I wrote my code, it just doesn't feel right to ...