Questions tagged [code-standards]

*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.

Coding standards, or coding conventions, are, in essence, sets of rules or guidelines designed to govern the process of code production in a software project, based on industry best practices, and, as such, they have been around for almost as long as programming itself. They are often applicable to a specific programming language, library, framework or environment, but they can also be language-independent, focusing mostly on style.

While coding standards can be somewhat informal, defined by a small team or corporation for internal use, most adopted standards aim to provide a formal definition of their rules, the reasoning behind each rule, and whether (and how) compliance with those rules may be verified. The main advantage of adopting coding standards, regardless of the formality and reasoning of a standard, is to have consistency across a code base.

In practice, to a programmer, complying with coding standards means restricting oneself to a subset of the programming language's features or syntax rules, in virtue of consistency, robustness and code readability. This tends to result in increased team productivity and reduced maintenance and production costs.

118 questions
178
votes
11 answers

How to use @Nullable and @Nonnull annotations more effectively?

I can see that @Nullable and @Nonnull annotations could be helpful in preventing NullPointerExceptions but they do not propagate very far. The effectiveness of these annotations drop off completely after one level of indirection, so if you only add…
Rylander
  • 19,449
  • 25
  • 93
  • 144
134
votes
4 answers

Eclipse: Can you format code on save?

In Eclipse, under Windows -> Preference -> Java -> Code Style, you can define code templates for comments and code, and you can setup a code formatter. I'm wondering if it is possible in Eclipse to have these setting take affect every time I save a…
Fostah
  • 11,398
  • 10
  • 46
  • 55
61
votes
4 answers

jQuery Standards and Best Practice

I’m currently responsible for rolling out the use of jQuery to the community of Web Developers within our company. Part of this involves presenting a course, however another part involves communicating standards and best practice. If you Google…
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
38
votes
9 answers

jQuery best practices in case of $('document').ready

I was researching on jQuery best practices and found this article by Greg Franko Normally, I do: $("document").ready(function() { // The DOM is ready! // The rest of the code goes here }); But the article recommends to use: // IIFE -…
Red
  • 6,230
  • 12
  • 65
  • 112
27
votes
5 answers

How do I modify Eclipse code formatting?

When I reformat code with Eclipse, it turns method headers like this: public void myMethod(String param) { into method headers like this: public void myMethod( String param) { When I was brought on here I'd never used Eclipse…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
24
votes
3 answers

How to customize Eclipse's text editor code formatting

How can I set my Eclipse's code formatter to allow code rows longer than 80 characters. I know that very long lines is hard to read but in my opinion 80 characters per line is very small value for wide screen monitors.
Eugeniu Torica
  • 7,484
  • 12
  • 47
  • 62
21
votes
4 answers

Jquery Bad practices

What are the JQuery bad/worst practices you have seen, written or thing should be avoided?
piyer
  • 746
  • 4
  • 11
19
votes
2 answers

Visual Studio 2017 Code Style "Errors" do not prevent build?

I've set various C# Code Style rules to generate errors, and while violations show up as errors in the IDE (both in the error list and the text editor), actual builds still succeed. Can anyone confirm this? I've tested on VisualStudio/15.0.0+26228.9…
Xorcist
  • 3,129
  • 3
  • 21
  • 47
19
votes
5 answers

Rails: how to add a header to every page

What is the standard way to add a header and footer to every view in a Rails app?
Drew Johnson
  • 18,973
  • 9
  • 32
  • 35
15
votes
1 answer

How do I configure autoformatting in Eclipse?

I dislike how auto format messes up empty cycle body, like: Before for (int i = 0; isTest(i); i++); After for (int i = 0; isTest(i); i++) ; How to configure eclipse not to do this?
Margus
  • 19,694
  • 14
  • 55
  • 103
12
votes
3 answers

How to sort imports alphabetically for TypeScript files automatically in WebStorm / PhpStorm?

I use tslint with default config tslint:recommended and I want to adapt as less rules as possible. Certain rules enforce that imports should be alphabetized: src/core/task/TaskMockDecorator.ts[2, 1]: Import sources within a group must be…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
12
votes
1 answer

Modern MATLAB codestyle: what is missing?

I seek to adopt a coding standard for MATLAB, but I am not sure if I picked the right one. To my best knowledge there is not that much available on topic of programming guidelines for MATLAB, other than this document. The document is well written…
Yauhen Yakimovich
  • 13,635
  • 8
  • 60
  • 67
10
votes
6 answers

Best practice for returning in PHP function/method

I am refactoring an extensive codebase overtime. In the long run we are going to develop the whole system in classes but in the mean time I am using the opportunity to refine my PHP skills and improve some of the legacy code we use across several…
JohnDevelops
  • 582
  • 3
  • 14
9
votes
1 answer

Best practice: returning multiple values

What would be recommended from a pure coding best practices perspective to adopt as a standard for medium-large developer teams? Return a sequential array: function get_results($filter) { $query = "SELECT SQL_CALC_FOUND_ROWS, * FROM ..."; …
Emanuel Lainas
  • 152
  • 2
  • 11
8
votes
2 answers

Is docstring max line-length different to normal PEP8 standard?

So im looking at some code and bringing it up to PEP 8 standard with the help of pylint and i noticed that if i was using triple quotes for a print statement where the text went past 120 chars (we are allowing 120 instead of 79) pylint didn't…
Jacxel
  • 1,634
  • 8
  • 22
  • 33
1
2 3 4 5 6 7 8