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.

learn more… | top users | synonyms (1)

1
vote
1answer
47 views

When should I use static functions and when should I use non-static ones? [on hold]

Sometimes, when I'm programming, I have to decide between adding a static method to a class that accepts an instance (or more) of that class or adding a non-static method. Here's an example: Static ...
0
votes
2answers
90 views

Getters with data conversion in Java VOs

I am working on a standard Spring application where DAO layer returns entities to service layer and service layer returns VOs to other services and controllers. In a certain scenario, we have a VO ...
4
votes
2answers
437 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 ...
0
votes
0answers
44 views

How To Better Manage Expectations on Iterations in Software Dev [duplicate]

This question is inspired by a current problem I having with a client I am consulting through. A few months ago we were working on a project for a big construction firm. I was working on an hourly ...
1
vote
1answer
130 views

Lines of code that take on too much responsibility [closed]

Intuitively, I know that (in terms of a maintainable, understandable codebase) the following code is bad practice var foo = fooFunc(barFunc(),wooFunc(chewFunc())); and might be better stated as ...
5
votes
3answers
1k views

Should my source code be in UTF-8?

I feel that often you don't really choose what format your code is in. I mean most of my tools in the past have decided for me. Or I haven't really even thought about it. I was using TextPad on ...
7
votes
1answer
162 views

Do we need to validate entire module usage or just arguments of public methods?

I've heard that it is recommended to validate arguments of public methods: Should one check for null if he does not expect null? Should a method validate its parameters? MSDN - CA1062: Validate ...
94
votes
15answers
27k 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?
0
votes
5answers
239 views

Coding guidelines for seamless merging [closed]

I am looking for coding guidelines developers should follow while writing C#/ASPX/SQL code, so that merging into other branches is smooth if not seamless.
-2
votes
2answers
102 views

How to reference one object with two interfaces? [duplicate]

Suppose I have two interfaces I and J that is implemented by Test class. Now I need one object of class Test that is referenced by I and J both interfaces. I can do it by singleton design pattern. But ...
0
votes
1answer
236 views

Is writing code chronologically the best way for readability? [closed]

So I've been writing a lot of JavaScript lately. Despite what many people say I think JavaScript can be a simple and beautiful language. What I've pondered of late is how to structure the code so it ...
6
votes
2answers
783 views

Is there a standard way to indicate that a function returns a new pointer?

Sometimes I want to delegate the construction of objects that a class owns to a separate function. Something like Vertex* new_vertex(const Options& options) { // do stuff... return new ...
5
votes
8answers
851 views

Why is (position < size) such a prevalent pattern in conditionals?

In a condition statement (IF) everyone use (position < size), but why? Only convention or there is a good reason for that? Example: if (pos < array.lengh) { // do some with array[pos]; } ...
2
votes
3answers
271 views

Why should a HashMap be used(in functions) to determine which value to return(for a key) when an if else construct can do the job in better time?

While I was recently working at a big company, I noticed that the programmers there followed this coding style: Suppose I have a function that returns 12 if the input is A, 21 if the input is B, and ...
-3
votes
2answers
73 views

In HTML and CSS what are the standard tab sizes? [closed]

I searched on Google but couldn't find an answer. I'd like to know what are the standard tab sizes for HTML and CSS. Is it 2 or 4?
-3
votes
1answer
90 views

Java - Best way to set properties of an object [closed]

I don't know if there is any difference in performance, or its just a matter of choice, but I am a perfectionist like that, and I'd like to know. Lets say you have the object HolySheet. You can set ...
1
vote
2answers
101 views

Naming convention for getting the primitive backing a type? [on hold]

I have a class that is backed by a double value, and I am wondering about accessor method names that preserve abstraction. Based on my experience in Java, there seems to be at least two precedents: ...
0
votes
0answers
23 views

Modern frameworks method conventions

I've been noticing that modern frameworks tend to have this kind of code style: expect(6 - 4).toBe(2) this can be rephrased as: assert(6-4, 2) Yet the former is much more readable. I would like to ...
327
votes
9answers
87k 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?
20
votes
12answers
2k 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 ...
-1
votes
2answers
47 views

If I #include a file, do I need to have a valid path to any headers #included in the included file [closed]

For example, if I have created a library, libcommon, which uses some other custom, but widely used library in a specific field (some_other), like this: libcommon.h #ifndef LIBCOMMON_H #define ...
0
votes
2answers
476 views

Why would a video game need main(String[] args) in its own class? [closed]

My teacher just told me that whenever I create a class to run something for a video game company that uses Eclipse, I should make a run class with the main and any outputs. He says any arithmetic ...
0
votes
0answers
33 views

Defensive Programming - “Return” placement [duplicate]

Sometimes I see myself writing code in the following way: if(value == null) return null; //... I will have here as many defensive conditions (and returns) as I need //... Continue to execute method ...
1
vote
1answer
210 views

Is it good programming practice to create files with no extension? [closed]

I often store data in external files when Python coding. Should I always save them with an extension - i.e. .txt? Is there any reason not to (other than saving bytes) to not give the extension? I ...
7
votes
4answers
849 views

Is the use of one-letter variables encouraged? [closed]

Is the use of one-letter variables encouraged in Java? In code snippets or tutorials, you often see them. I cannot imagine using them is encouraged because it makes the code relatively harder to read ...
10
votes
7answers
2k views

How to deal with different programming styles in a team?

We have a small dev team (only 3 developers) and we recently got a new team member. While he is a smart coder, his coding style is completely different from ours. Our existing code base contains ...
1
vote
4answers
91 views

Use the company style guide or try to match the incorrect source files? [duplicate]

I'm currently working on a large project in C++. The style guide for this language has been well defined by my company and is available for everyone to see. This particular code-base is being ...
2
votes
7answers
358 views

Vocabulary: Should I call this apply or map? [closed]

So, I'm tasked with organizing the code and building a library with all the common code among our products. One thing that seems to happen all the time and I wanted to abstract is posted below in ...
1
vote
1answer
205 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 ...
22
votes
3answers
2k views

Why does the Lisp community prefer to accumulate all the parentheses at the end of the function?

Why does the Lisp community prefer to accumulate all the parentheses at the end of the function: (defn defer-expensive [cheap expensive] (if-let [good-enough (force cheap)] good-enough ...
1
vote
1answer
85 views

Objective-c anonymous property coding style

If I have an interface defined like @interface MyClass @property (nonatomic, copy, readonly) NSString *myString; @end so that myString is externally visible but can't be written, what would be ...
1
vote
1answer
107 views

How bad is it that my index.php in a Zend Framework MVC application mixes definitions and side effects?

I'm introducing some more coding quality standards and checks via a new project - in particular, the PHP-FIG recommendations. This project using Zend Framework 2, and I have a fairly simple entry ...
64
votes
16answers
4k views

Recommendations for teaching junior programmers good coding style [duplicate]

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 ...
0
votes
3answers
80 views

Handling source code table alignment

Sometimes there is need to have tables (big or small) in source code. ItemType const SomeTable[] = { // id name min max ITEM( 3, "Foo", 70, 180), ITEM(13, "Bar", 30, 50), ...
1
vote
6answers
538 views

What to use instead of IDs in selectors in CSS

I recently installed a csslint package for my Atom text editor. I keep getting warnings saying "Don't use IDs in selectors." I found this weird since I've always been using IDs in selectors in CSS, ...
1
vote
4answers
3k 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 ...
3
votes
3answers
382 views

No exceptions C++ and partially constructed objects

Looking over Joint Strike Fighter Air Vehicle C++ Coding Standard, rule AV 73 states something on the lines: Default c++ constructors should be avoided if that means leaving object in a partially ...
0
votes
2answers
42 views

SQL - for some attributes specific to different clients' users, how to handle schema?

I have clients, each of whom have an app with a bunch of users. Their user data could be pretty different, but there is also a lot of overlap. Ex: all their users have "gender" and "age" and plenty ...
1
vote
3answers
169 views

Are project naming conventions more important than language naming conventions? [closed]

I'm working on a project with a senior developer and he doesn't really abide by the naming conventions of the language that we're using. The project is in Go and he uses underscores for everything. ...
0
votes
7answers
211 views

In ifs inside for loops, prefer checking for true, or for false and continue?

I'm discussing this with a work colleague. Say we want to sum the numbers from 0 to 9 skipping 5. He prefers this: int sum = 0; for(int i = 0; i < 10; ++i) { if(i == 5) { continue; ...
2
votes
1answer
231 views

Reducing the complexity of over-designed code

I have just started working at a company where I have inherited a C# codebase from a previous developer. I know programming well, have an engineering degree + an (unfinished, several year long) PhD ...
0
votes
0answers
72 views

Is there any necessity to pass a variable parameter to a method while the variable declared global? [duplicate]

I am writing a class in java of Monte-Carlo algorithm. Here is the written code - public class MonteCarlo { int[][] matrix; public void monteCarlo(List<Node> nodeList) { matrix ...
2
votes
2answers
105 views

Typedefs to convey relations between classes

I'm wondering if the following use of typedefs is any good practice, or if there are any downsides to it. Basically I have alot of "data"-structs, which are intended to be used in (globally unique) ...
1
vote
2answers
692 views

How should I compare two database tables - with SQL or using Java? [closed]

I have two tables with different structure. I should compare ID from 1st table with ID of the intermediate table and then comapre TXT field of the intermediate table with TXT field of the 2nd table. ...
13
votes
2answers
1k views

Are there well-known PowerShell coding conventions?

Are there any well-defined conventions when programming in PowerShell? For example, in scripts which are to be maintained long-term, do we need to: Use the real cmdlet name or alias? Specify the ...
0
votes
1answer
131 views

Where does the Liskov Substitution Principle generally lie in different constructor parameter lists?

There are two other questions I've posted that dealt with specific cases of this: Where does the Liskov Substitution Principle lie in a subclass passing extra arguments to similar, tightly-related ...
3
votes
4answers
558 views

Are `switch` statements generally used wrong? [closed]

I see most developers using switch statements with breaks in each and every case. Is this usage of switch statements inappropriate since a simple set of if-else statements would suffice? Is it OK for ...
18
votes
6answers
14k views

Naming classes, methods, functions and variables [duplicate]

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 ...
12
votes
5answers
806 views

Evolution in coding standards, how do you deal with them?

How do you deal with evolution in the coding standards / style guide in a project for the existing code base? Let's say someone on your team discovered a better way of object instantiation in the ...
0
votes
2answers
50 views

Capitalizing custom methods in a SDK based project [closed]

In projects which need heavy SDK usage, like Android and iOS development, I want the methods/functions I write to be obvious and since the whole framework is written with lower case method names I ...