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)

-2
votes
0answers
20 views

Name for “1:1” sourcefile - testfile convention

A classic convention for organizing test files is to maintain a 1:1 mapping between source files and test files. One common scheme is to simply append "-test" or "-spec" to the source filename and ...
0
votes
0answers
20 views

Convention for writing the software details over the command line

What are the standard or more elegant ways of writing information about the software package? I have developed a package for one of machine learning methods in C++. I wish to provide information ...
0
votes
1answer
50 views

Should I always use prefix private methods with an underscore in Python?

Prefixing methods and members with an underscore indicates internal use. For simple classes, I sometimes find the easier reading and typing of self.foo outweighing the indent of self._foo. Especially ...
12
votes
4answers
9k 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 ...
127
votes
15answers
42k 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
2answers
88 views

What is good practice when dealing with data integrated in the source code?

I've been tasked with overhauling a fairly large web-system that requires much user input. In an attempt to instruct the users when making input, the original creators has made extensive use of ...
3
votes
4answers
276 views

Easy way to make old javascript files conform to new quoting standard?

We've just started putting linting in place at my workplace, and a lot of the devs didn't realize our standards called for double-quotes everywhere. About 50% of the codebase uses single-quotes, so it'...
1
vote
1answer
54 views

Coding guidlines for Controller and Dao?

My Controller code: ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); ObjectReader objectReader = objectMapper.reader(...
0
votes
1answer
110 views

What scientific support does some coding standards have?

Let's consider the rule in python PEP8, coding standard for the linux kernel etc saying that a line of code are not allowed to be longer than N characters. To this rule there is normally a few ...
7
votes
7answers
1k views

Why would an employer ask for a 'long' code sample? [closed]

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?
22
votes
11answers
3k views

Should coding best practices always be used [closed]

When coding software, should the architecture always be best practices or practical practices in regards to the application being built? If I am building a two page web application that might live 5 ...
0
votes
2answers
81 views

Using Super.someMethod for added clarity?

Is Super.someMethod() a good practice to add clarity to the code by explicitly stating that someMethod is not a method included in the current class but in the parent class? For instance, would this ...
-3
votes
1answer
95 views

According to GNOME guidelines, should git messages end with a full stop, or not? [closed]

According to GNOME guidelines, how sentences should be written in Git messages? Should sentence in git commit message start with upper-case letter and end with a full stop, or lower-case without a ...
8
votes
6answers
564 views

Is it considered bad practice to run different JavaScript for IE

Is it considered bad practice (and how bad) to run different JavaScript for IE? Currently im writing some JavaScript and the simplist way to work arround IE quirks seems to be to check for browser ...
8
votes
3answers
1k 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 ...
5
votes
3answers
325 views

Is nesting try-catch statements still a code smell if nested within a loop?

I have heard that nesting try-catch statements can often be a code smell, so I'm wondering whether this situation is an exception. If not, what would be some good ways to refactor? My code looks like ...
138
votes
14answers
22k views

Why does Uncle Bob suggest that coding standards shouldn't be written down if you can avoid it?

While I was reading this question, the top voted answer quoted Uncle Bob on coding standards, but I was confused by this tip: Don't write them down if you can avoid it. Rather, let the code be ...
5
votes
5answers
311 views

Do you generally send objects or their member variables into functions?

Which is generally accepted practice between these two cases: function insertIntoDatabase(Account account, Otherthing thing) { database.insertMethod(account.getId(), thing.getId(), thing....
26
votes
10answers
5k views

Does your company have a coding standard? [closed]

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 ...
21
votes
7answers
24k 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 ...
4
votes
2answers
96 views

Common loop variable names for indexes in 4D and above

I am curious if there are common loop index variables (of single character or not) for dealing with 4 dimensions and above? I was helping another student working through CS50x who was just learning ...
3
votes
2answers
163 views

Correct way for storing data for runtime use in stand-alone applications?

I am working on a project that involves a "team builder" type application, if you will using C#. For the sake of simplicity, let us say it involves the user creating a "Team." There are three teams ...
101
votes
4answers
10k views

Does a `long` ban make sense?

In today's cross-platform C++ (or C) world we have: Data model | short | int | long | long long | pointers/size_t | Sample operating systems ... LLP64/IL32P64 16 32 32 64 ...
3
votes
1answer
83 views

Term for the current iteration of a recursive function call

Is there a standard or widely accepted term for referring to a variable within the current call of a recursive function where the last value of the same variable is passed as an argument? I am trying ...
36
votes
6answers
31k 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 ...
2
votes
1answer
91 views

What is MISRA 8-0-1 rule on init-declarator-list and member-declarator-list about?

I am reading company's coding guidelines, and I encountered the MISRA 8-0-1 rule, which states: An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or ...
0
votes
1answer
211 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 ...
0
votes
1answer
97 views

Matching the superclass's constructor's parameter list, is treating a null default value as a non-null value within a constructor a violation of LSP? [duplicate]

I kind of ran into this when messing around with FlashPunk, and I'm going to use it as an example. Essentially the main sprite class is pretty much class Entity. Entity's constructor has four ...
35
votes
8answers
27k views

Is it necessary to add the default case while using switch cases?

During a recent code review I was asked to put default cases in all the files wherever switch block is used, even if there is nothing to do in default. That means I have to put the default case and ...
4
votes
3answers
440 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 ...
41
votes
9answers
30k views

What does XXX mean in a comment? [closed]

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

invoking methods within a conditional expression

In an oft-cited (if dated) reference for C# coding standards (pdf; from Lance Hunt), the statement is made, 33. Avoid invoking methods within a conditional expression. I've not seen this ...
0
votes
2answers
83 views

What is the accepted practice for handling numeric conversions under OOP?

I am making a weather app that involves temperatures. You can change between Kelvin, Celsius, and Fahrenheit just for fun. However, temperature figures get used all over the place in different ways. ...
9
votes
3answers
1k views

When comparing a string variable to a string literal with .equals(), is there a standard practice for the order of items? [closed]

There are benefits to each and I understand the differences, but what is considered best / standard practice? And why? For example : "myString".equals(myStringVar) Avoids a potential NPE and does ...
14
votes
5answers
618 views

Is scientific code a different enough realm to ignore common coding standards?

Lately I've been trying to wrap my mind about the following fact. On one hand, there is a host of coding guidelines and standards for what is considered to be "healthy", "clean", "well-written" and ...
2
votes
7answers
3k 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, ...
4
votes
3answers
403 views

Are for loops allowed in the “Clean Code” set of rules?

Given the set of rules explained in "Clean Code", can one really use for loops? My confusion stems form the fact that a for loop is a low-level construct per se, thus it can only be used at the very ...
8
votes
9answers
1k views

How can I promote clean coding at my workplace?

I work with a lot of legacy Java and RPG code on an internal company application. As you might expect, a lot of the code is written in many different styles, and often is difficult to read because of ...
1
vote
1answer
174 views

In C, are large 'pointer chains' bad for performance or code cleanliness?

The following for example: i = readString(&packet->data.play_server.updatesign.line1, pbuf, ps); It has a large amount of nested structs/unions. Is this generally frowned upon in code ...
17
votes
16answers
2k views

Do else blocks increase code complexity? [closed]

Here is a very simplified example. This isn't necessarily a language-specific question, and I ask that you ignore the many other ways the function can be written, and changes that can be made to it.. ...
44
votes
7answers
12k 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 ...
1
vote
3answers
222 views

Is it considered good practice to always have methods return a value?

Sorry for the terrible title but hopefully these snippets will give you the gist. Method 1: class Person: def __init__(self, name): self.name = name def set_name(self, new_name): ...
8
votes
5answers
13k views

Creating a coding standards document

I work in a control systems company, where the primary work is SCADA and PLC, along with other control systems stuff. Software development is not really something the company does, apart from little ...
3
votes
3answers
185 views

Would dependency injecting into entites be considered against SRP?

I asking a question on Stackoverflow earlier and someone pointed me to a previous post of his, He states that injecting a dependency into an entity violates the Single Responsibility Principle. To ...
731
votes
7answers
99k views

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

I often talk to 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 ...
15
votes
10answers
2k views

How important is a good coding style for the decision to hire a programmer? [closed]

Even as a student I am asked to review the code of programmers who have (not) passed a test (create a list of Fibonacci numbers on android). While I am very strict on coding style I just read about ...
5
votes
3answers
615 views

Are there standard style guides for PHP? [closed]

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 broadly-...
0
votes
1answer
123 views

Is it worth it to follow code conventions of Netbeans? [closed]

I am always not able to follow Netbeans default coding conventions like the following Function should be N lines only Method Length is N Lines (M allowed) Warning: Do not Access Superglobal $...
56
votes
7answers
29k 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 ...
41
votes
8answers
4k views

When is it appropriate to make a separate function when there will only ever be a single call to said function? [duplicate]

We are designing coding standards, and are having disagreements as to if it is ever appropriate to break code out into separate functions within a class, when those functions will only ever be called ...