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
1
vote
1 answer

Not operator or Strict comparison on false?

What's the best practice for writing if-statement on boolean value? function foo(boolean $bar) { if ($bar === false) // ... // or if (!$bar) // ... } With a Not operator it's more compact, but you may not notice this operator while…
NameX
  • 49
  • 4
1
vote
1 answer

Exceptions to control execution flow in managed .NET code - a good practice or not?

Here is a very simple functionality example, to make the discussion easy. Suppose, I am logging some abstract objects' content in a flat log. If an object's json representation contains property called EntityID with a GUID, I'd like to record it as…
Yuri Makassiouk
  • 425
  • 3
  • 16
1
vote
1 answer

Code Standard - is it better to have a getter/setter even though they are never used?

The IDE has suggested to add a getter/setter to a private field. It is never used, and reaching the field is only from within the class. what is the preferred coding style? keeping the never used methods? Im asking specifically about java/kotlin but…
RAN
  • 15
  • 4
1
vote
0 answers

Git Hook to detect invalid code formatting/standards

I'm trying to design a pre-push git hook for some kind of static code analysis. I've read about the topic and seems that some people go down the route of executing a maven/gradle goal and then checking the exit code but haven't found one that's a…
AdamekOwns
  • 33
  • 4
1
vote
1 answer

Newline before closing tag PhpStorm

I am trying to use the code beautifier within PhpStorm, trying to configure it for HTML. I have one issue that I can't seem to solve. I would like to add a whitespace (enter) before a closing tag.
Kaasstengel
  • 427
  • 1
  • 4
  • 17
1
vote
2 answers

How to start with a JavaScript coding style?

How can I learn or start learning the right coding style in JavaScript? What are my possibilities and what practical resources can I use to get used to the coding style? Thanks! var getRequestUserList = function getRequestUserList(req,res,id) { …
V.Aleksanyan
  • 577
  • 1
  • 4
  • 7
1
vote
1 answer

Configuring phpcs to disallow spaces after closing bracket and before closing bracket

Most of our projects are WordPress, and while we agree with the most of coding standards it sets, there are some which we disagree on and do not want to use in our own private projects. Somehow pieces of those disagreements still end up in the…
Christian
  • 927
  • 2
  • 13
  • 22
1
vote
2 answers

any reason to not use a dictionary

I was having a discussion with a co-worker over whether it is better to use a Dictionary and repopulate it whenever a result set changes or to just use linq loop over all elements in the list each time. We're trying to map a parent / child…
Seph
  • 8,472
  • 10
  • 63
  • 94
1
vote
1 answer

Sonarqube not honoring git commit date while calculating new bugs/vulnerabilities/leaks

I had recently integrated sonarqube in our release process. I have set the leak period as the date of integration, and mandated it in quality gate definition that there should be zero new issues since the start of leak period. The problem is…
azi
  • 929
  • 1
  • 11
  • 31
1
vote
3 answers

standard / readable array declaration and using

what in your opinion more standard / readable / efficient code of array declaration : one way : $days = array(1=>'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); then use : $days[$value] or the second way : $days = array('Sun', 'Mon', 'Tue',…
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
1
vote
1 answer

Is there any code standards for PHP using multiple calls and arguments?

I am using Doctrine and have this line in PHP: $result = $entityManager->getRepository('Example\Entity\Users')->findOneBy(array( 'address' => $address->getId(), 'email' => $email->getEmail(), 'type' => $type->getId(), …
Rafael
  • 1,495
  • 1
  • 14
  • 25
1
vote
1 answer

Lots of small CSS files or one big one with sections - from a code-quality standpoint

I'm asking this question purely from an ease-of-development standpoint. Performance is not a consideration, because we will have a build process that combines and compresses all our CSS files into a single file for release and then compresses…
Jonathan
  • 32,202
  • 38
  • 137
  • 208
1
vote
2 answers

Parenthesis placing after function

Which is the common best practice for where to place parenthesis after a function? I see at times function () and I see function(). With parameters I see function (param) and then I see function(param. Is this just a matter of preference or is there…
pertrai1
  • 4,146
  • 11
  • 46
  • 71
1
vote
2 answers

BDD Story style

We using Behaviour Driven Development to develop a SOA system using Scrum and have come across two approaches to producing the stories. Approach 1 Given Specific Message Type is available And Specific State exists When the Message is…
1
vote
1 answer

PHP mess detector optional parameters

I have interface X interface X { public function foo($x, $y = 0); } then I have class class xx implements X { public function foo($x, $y = 0) { // use $x, but not $y } } This is perfectly normal, because I do not want to…
Mantas
  • 4,259
  • 2
  • 27
  • 32