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
21 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
52 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 ...
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 ...
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 ...
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 ...
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 ...
-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 ...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
4
votes
3answers
404 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 ...
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 ...
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): ...
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 ...
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 $...
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 ...
1
vote
2answers
378 views

How to deal with Classes having the same name (different packages)

My R&D team have Java packages containing classes with the same name. For instance: com.myapp.model Device ... com.myapp.data Device ... We had a discussion, the names conflict when both ...
1
vote
3answers
221 views

The best practice for passing formatted string to methods

Though it might be trivial for someone, I find it a little inconvenient when someone formats the string while passing it as a parameter to a method. For e.g. AddMessage( string.Format("{0} (" + ...
1
vote
0answers
241 views

Can this be used to implement Post Redirect Get pattern?

I am trying to implement proper a Post Redirect Get on a PHP site (question is language agnostic in nature however). I thought about it, and realized that running this code on every request seems to ...
21
votes
8answers
4k views

At what point is it taboo to have loops within loops?

Just curious. The most I have ever had was a for loop within a for loop, because after reading this from Linus Torvalds: Tabs are 8 characters, and thus indentations are also 8 characters. There ...
0
votes
3answers
190 views

Best practices in exposing interface

Let's assume I have a class that downloads data from API, cleans it and saves to database. What methods should I expose? class ApiConnector1 { public string GetDataFromApi() { // ... ...
1
vote
1answer
136 views

Sorting Array before looping : best practice

I was going through JBAKE code at https://github.com/jbake-org/jbake/blob/master/src/main/java/org/jbake/app/Asset.java : 58 PFB the code. Why are we sorting the array here? if (assets != ...
37
votes
9answers
3k views

Using compound statements (“{” … “}” blocks) to enforce variable locality [duplicate]

Introduction Many "C-like" programming languages use compound statements (code blocks specified with "{" and "}") to define a variables scope. Here is a simple example. for (int i = 0; i < 100; +...
0
votes
1answer
77 views

Should http requests be in the constructor or in a static function? [closed]

Which is conventional? For example, this is in the constructor: public class Foo { ... public Foo(...) { // http requests } ... } and this is in the static method: public class Foo ...
64
votes
6answers
8k views

Why is the minus sign, '-', generally not overloaded in the same way as the plus sign?

The plus sign + is used for addition and for string concatenation, but its companion: the minus sign, -, is generally not seen for trimming of strings or some other case other than subtraction. What ...
0
votes
4answers
254 views

Where to put try-catch statements [closed]

I have the following code statement that calls a separate class. if (newOrEdit.Equals("New")) { try { BusinessLayer.InsertOperator(operatorDetails); } catch (Exception) { ...
59
votes
5answers
6k views

Why would you not use the 'using' directive in C#?

The existing coding standards on a large C# project includes a rule that all type names be fully qualified, forbidding employment of the 'using' directive. So, rather than the familiar: using System....
3
votes
0answers
152 views

Is it okay to write C code that must be compiled with -fno-strict-aliasing? [closed]

Some major C projects violate the strict aliasing rules in the C standard and must be compiled with -fno-strict-aliasing. These include Python, OCaml and the Linux kernel. Obviously this is not ...
2
votes
2answers
335 views

Using a private auto-implemented property vs. a private field

If I have a need for simple, private fields, is there any reason I shouldn't just make it a convention to use private, auto-implemented properties instead? For instance, I could do this: private ...
5
votes
3answers
514 views

non-optional pointers vs. non-const references in C++

In Other C++ Features, Reference Arguments of the Google C++ Style Guide, I read that non-const references must not be used. All parameters passed by reference must be labeled const. It is clear ...
1
vote
2answers
166 views

Performance concern in object oriented languages [duplicate]

I recently moved into web development using ASP.NET MVC. The language I use is C#. Having considerable experience in C makes me look for optimized coding standards (memory, efficient data structures ...
2
votes
0answers
70 views

Standard for order of tags in PHP DocBlocks?

Based on the tags listed from this "standard", is there an order of the tags that people typically follow? Even if it's not something that has been entirely accepted, but something proposed? I am ...
17
votes
6answers
1k views

Writing comments for some small code with rather large background [duplicate]

So I had to write some code related to splitting Bezier curves into parts. I read through several references and particularly referred this rather detailed one. The final code outcome is however ...
1
vote
1answer
67 views

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

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 ...
-1
votes
0answers
65 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
154 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 ...
-2
votes
2answers
151 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 ...
1
vote
1answer
305 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 ...
8
votes
2answers
251 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 ...
6
votes
3answers
1k 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 Vertex(...
-3
votes
2answers
266 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?