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
3
votes
2 answers

Convert notices into exceptions in symfony 3.4

I would like all errors (notices, etc) to be treated as exceptions in Symfony 3.4 and to halt the application. This is the same for PHP as "use strict" in JavaScript. Edit: When using debug true when creating an AppKernel it enables strict…
jgmjgm
  • 4,240
  • 1
  • 25
  • 18
3
votes
1 answer

How to create my custom tslint rule set?

I want to introduce a typescript coding guideline that can be shared accross multiple projects. I don't want to copy paste a tslint.json over multiple times, it has happened currently and we have diverged version of it going around. I want to base…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
3
votes
1 answer

Fixing code style: change double quote strings to single quote in PHP when there are no variables in them

I am wondering if there is a tool, that will parse a PHP project and fix a bad code style. That is a double quoted string that has no variables should be changed to single quote. $var1="change enclosing to single quote"."here too"; $var2="change…
Pentium10
  • 204,586
  • 122
  • 423
  • 502
3
votes
2 answers

What are the advantages of function calls without mixed variables?

I know PHP is a very error tolerant language and I guess that is why you can have mixed variables for function calls like: /** * @param mixed $bar **/ function foo($bar) { // Do something with $bar, but check it's type! } Is there a…
Jurik
  • 3,244
  • 1
  • 31
  • 52
3
votes
3 answers

.Net Full qualified name for variable type

Where I work, I often see code like that : public void Test(Models.User.UserInfo userInfo, Models.User.UserParameter param) { ... } Personally, I prefer to see something like that : public void Test(UserInfo userInfo, UserParameter param) { ...…
Melursus
  • 10,328
  • 19
  • 69
  • 103
3
votes
1 answer

Law of Demeter violation search tool?

Does anybody know of a tool that I could use with a C# application to find possible Law of Demeter violations? I know that it would give a lot of false positives, but I think it could still be useful. Especially during the early design process.
Jerod Houghtelling
  • 4,783
  • 1
  • 22
  • 30
3
votes
3 answers

Document Empty Constructor In java by PMD

I am using PMD plugin in my Java Project. When I run the PMD it shows the warning as "Document Empty Constructor ". My code is as follows... public class ExceptionHandlerImpl implements ExceptionHandler { private static final Logger log =…
sam
  • 71
  • 1
  • 9
3
votes
2 answers

PHPMD says violating Single Responsibility Principle for argument having boolean default value

These two PHP class methods violates Single Responsibility Principle (SRP) according to the phpmd rule booleanargumentflag. How should they be written to avoid this? If the solution is to remove the default value "= true", then how is this improving…
Mikael Roos
  • 285
  • 3
  • 15
3
votes
1 answer

Suppress checkstyle errors on PRIVATE member variables in a suppressions.xml?

On a project I am working on, checkstyle is failing with "Missing a Javadoc comment" due to a missing Javadoc comment on a private member variable. This seems like unnecessarily strict behaviour to me and I would like to suppress the error for…
0xbe5077ed
  • 4,565
  • 6
  • 35
  • 77
3
votes
1 answer

Finding all strings that have single quotes with resharper 8

We have some coding standards that state we must use double quotes instead of single quotes for string literals in JavaScript. As I am in the habit of always typing single quotes I was wondering if there was a way, using resharper 8, that I could…
mbx-mbx
  • 1,765
  • 11
  • 23
3
votes
1 answer

How to check node.js code to code standards

Does anybody know how to check nodejs code to code standards automatically? I'm looking for some features like codesniffer but for node.js (express framework).
Andrii Tarykin
  • 628
  • 3
  • 9
  • 26
3
votes
2 answers

Which PHP SPL Exception should you throw if a class doesn't exist

Which PHP SPL Exception should you throw if a class doesn't exists? within the context of ZF2 coding standards for exceptions. In the standards it say exceptions should extend from one of PHP's SPL Exceptions. My first guess would be that it's some…
gawpertron
  • 1,867
  • 3
  • 21
  • 37
2
votes
0 answers

Is it Pythonic to import an external symbol imported into another module?

Please guide me on the pythonic way for a minor code-standards question. Searching SO re imports gets me many discussions comparing import foo vs from foo import bar which is not my concern here. Still I apologize if I am creating a dupe Q. My team…
chrisinmtown
  • 3,571
  • 3
  • 34
  • 43
2
votes
1 answer

Coding standards: Should one always write 'return' at the end of every method or function?

I believe that the question is not a duplicate as the other question does not respond to the question of readability. In the contributing guidelines of the library scikit-learn, they refer to a document for coding standards, see here, in which you…
Robin Vogel
  • 159
  • 9
2
votes
1 answer

Kotlin predefined code style synchronisation with oficial guide

I found excellent guide how to apply predefined code style from official site. But I can't found any information about how to automatically keep this setting up to date. For note, coding convention page was updated 16 times in 2018 year. May be I…