Questions tagged [coding-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. They include naming conventions, style, prohibited features, and more.

Filter by
Sorted by
Tagged with
0 votes
1 answer
39 views

Is the combination of state machine and pure function a programming style?

As a university student who just have been learning programming for a year. After I learned about the concept of state machine and the pure function in functional programming, I suddenly got an idea ...
5 votes
5 answers
390 views

Should an optional boolean function argument rather default to true or false?

In many cases I can formulate some boolean parameter equally well positively as negatively, e.g. isOn or isOff. Which one should I pick then, in case I want the argument to have a default value? Is ...
  • 1,386
53 votes
7 answers
9k views

Why do so many standards for JSON API response formats contain a "success" property in the response body instead of just using HTTP status codes?

I was researching about best practices for standardised JSON response formats for APIs, according to various sources available online general consensus looks something like this: //Successful request:...
  • 649
2 votes
1 answer
310 views

Naming convention for the classes holding REST APIs [closed]

Our new team suffixes class names with API to indicate that they encapsulate RESTful methods. Eg: "PaymentTemplateAPI", "FeeTemplateAPI" classes. I find it odd since API is a ...
  • 139
12 votes
6 answers
4k views

Is it bad practice create "alias" variables to not use globals or arguments with long names in a method?

Is it OK to create a variable which only purpose is to increase readability? Example: public class Example { private final HowLongCanARepositoryNameReallyBeRepository ...
0 votes
5 answers
84 views

best practice for error handling between PAM_SUCCESS and PAM_AUTH_ERR macros

We have two exit code code PAM_SUCCESS(0), PAM_AUTH_ERR(7). If we wanna return 0 or 7 when we compared password with our password in following code which code is better that this code ? if (strcmp (...
18 votes
4 answers
4k views

Adding Units To Magic Numbers

Considering this question and the most upvoted answer, and his specific example of public static final int THREE = 3; might it make sense to allow this sort of usage if we added units to the ...
0 votes
1 answer
140 views

Is a good practice using form tag's atributes in HTML?

Checkout this HTML using the attribute action, method and target from <form></form> tag: <form action="/action_page.php" method="get" target="_blank"> ...
0 votes
1 answer
112 views

ASPICE assessment: detail of test logs

The "VDA Automotive SPICE Guidelines" (excerpts: https://vda-qmc.de/fileadmin/redakteur/Software/Automotive_SPICE/Veroeffentlichungen/VDA_Guideline_Rules_and_Recommendations_2017.xlsx) tells ...
  • 109
-3 votes
2 answers
138 views

Java Coding standards via common and open source tools?

I'm working on a project with 3 other backend developers and 3 front end devs. Also playing the role of architect for 3 other projects. One issue I see is that most developers are not formatting code, ...
  • 557
-3 votes
1 answer
124 views

Assumptions versus no assumptions - where do you draw the line? [closed]

In our line of work as software engineers, we can write code that assumes various things outside its scope or architectural boundary, in order to save performance, time, and on defensive coding ...
0 votes
2 answers
79 views

Should we put behaviors (method) in constant class in Java?

Should we put behaviors (method) in constant class in Java? If not then why? Which clean code practice/principle I am breaking while doing that? public class TagConstants { public static final ...
0 votes
1 answer
45 views

Pros and Cons of placing a method as static in the class or as private function outside of class when it doesn't utilize this?

I use typescript. When I write the below code ESlint throws this error: https://eslint.org/docs/rules/class-methods-use-this export class { constructor() { const result = doCalculations() ......
  • 109
2 votes
5 answers
1k views

Why would you ever want WET code?

We have all heard of Don't Repeat Yourself and Write Everything Twice, but I've never understood why anyone would prefer the latter of those. Obviously you can go overkill with DRY, with the code ...
  • 217
-4 votes
1 answer
122 views

General term to describe the anti-pattern where the same concept is described in different ways?

Our codebase is old and very large. Over the years, many developers have worked on the code and frequently refered to the same concept inconsistently. For example, we have a "number that uniquely ...
  • 140
4 votes
3 answers
316 views

Passing object or using the field

I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class? Using the field: ...
  • 63
2 votes
3 answers
588 views

Error handling. Is it always necessary?

So, today I was reading a piece of code I found this function: Public Function FolderExists(sPath As String) As Boolean Dim FSO As New FileSystemObject On Error GoTo errHandler sPath = ...
  • 211
4 votes
1 answer
83 views

Download and apply or apply as they download, is there a best practice?

I am writing a function that will download an HTML post. Having downloaded the string I will: strip off the html tags remove special encoding characters like \n remove trailing white spaces My ...
  • 151
4 votes
5 answers
340 views

Two different styles of functions: does either have an advantage?

In the past few months that I've been learning Javascript, I've wondered which is the better usage of functions: Functions that perform actions based on their arguments with no return value: const ...
0 votes
2 answers
247 views

Should default settings be considered as business rules from the viewpoint of "Clean Architecture"?

The examples of default settings: Default port for server applications Default resources directory for Java Applications Default Webpack config file ("webpack.config.js") My particular ...
-3 votes
1 answer
67 views

What could be a better naming convention for the variable 'completeConfig'?

I have a feature in which the user can directly provide the entire nginx config inside the completeConfig variable in the config yaml. Like this: nginxConfig: completeConfig: > .... .... ...
0 votes
2 answers
155 views

Which approaches are exists for using of possessive case in variables/classes/methods naming?

In variables/classes/methods naming, sometimes "of" preposition is omitted and word order changing, for example: "Absolute path of source file of entry point" -> "...
1 vote
1 answer
180 views

counting identifiers and operators as code size metric

I'm looking for a code metric for monitor and track over time the size of several projects and their components. Also, I would like to use it for: evaluate size reduction after refactoring compare ...
  • 23
-3 votes
4 answers
243 views

Negative Naming in Forms

The Main Question Is it ever acceptable to use a negative name for a boolean variable? For example, I have a few user forms that have a checkbox for "N/A" or "Not Assessed". These ...
1 vote
1 answer
248 views

Cyclomatic complexity vs repeated code

we've a python function that can be achieved in 2 ways 1st method def complexity_1(x, y): if 2 == x and 3 == y: a=3 b=4 c = a + b elif 2 == x and not 3 == y: a =...
-5 votes
2 answers
121 views

Current industry standard with regards to C macros [closed]

I have read from several authors that macros in C should be avoided whenever possible, and use inline functions instead. It's true that inline only 'requests' the compiler to replace the function call ...
  • 605
3 votes
1 answer
2k views

Is this enum/trait a good way to implement polymorphic design in Rust?

this is my first post on here, and I'm wondering about a good rust implementation with traits on enum types. I want to know if using an enum w/ a trait as a generator of different code is viable like ...
  • 39
0 votes
1 answer
143 views

Microservices Conditional API Call Design

I always think about this scenario where we need to perform a task conditionally and the task requires calling another microservice. What I am not able to understand is which microservice's ...
1 vote
4 answers
448 views

What is the disadvantage of learning to code by doing?

It seems like the consensus is to learn by doing when it comes to programming, well that seems like the advice given to most beginners. How will beginners learn to write efficient code when they dive ...
12 votes
4 answers
2k views

Why would you ever use `malloc(0)`?

While reading an answer here, I saw this code: char ** v = malloc(0); while ((r = strtok(s, " ")) != NULL) { char ** vv = realloc(v, (n+1)*sizeof(*vv)); The thing that bugged me was the ...
  • 1,418
-2 votes
4 answers
170 views

Are there any guidelines about making SQL queries easier to comprehend?

As I'm spending more time working with SQL, I'm starting to feel like this language promotes logic obfuscation. Here are some examples: An INNER JOIN in a query can act as an implicit filter that ...
0 votes
6 answers
1k views

Naming boolean fields in classes

I have had hard times naming boolean fields. On the one hand, i've read that it is good to name them as affirmative statements, like hasAge, or canDance. It's not a problem when naming local ...
2 votes
3 answers
189 views

Changing control name property during runtime -- Why doesn't anything break and why shouldn't I do it?

To make a long story short, I needed a property of a button to act as a "secondary text property" and retain the original .Text value of a button, and the only String property that wasn't ...
  • 147
2 votes
2 answers
482 views

Does it make sense to use meaningless named constants?

For example, does it make sense to refactor the following code: a = a * 2; as: const int INT_TWO = 2; // ... a = a * INT_TWO; My question hinges on the fact that the new constant conveys no ...
0 votes
3 answers
272 views

Is relying on an IDE for code readability acceptable

During my years developing software I have most of the times tried to improve the readability of my code. As one example, I often try not to use boolean flag parameters of methods and I try to ...
  • 129
2 votes
1 answer
985 views

Any standard expansions to RFC 4122 for generating a name based UUID using SHA256

I am doing some code review for a project and they have generated a name based UUID using SHA256 as the hashing algorithm. I found a some Java code that created a Name-based (hashing) UUIDs using SHA-...
  • 149
0 votes
2 answers
436 views

Model View Controller: Can the Model access the view directly?

According to my understanding, in the MVC design the Model can only receive the functions calls from the Controller and not from the View directly. Is it true that the Model can change or access the ...
4 votes
4 answers
331 views

Measuring the success of coding dojos

I'm interested in starting coding dojos at the company I work at (during or after working hours). I think it will help to spread knowledge on how to write clean, concise and consistent code. I've been ...
  • 85
1 vote
3 answers
312 views

Is `print statements` a defensive programming technique?

We had an exam and the question paper asked which of the following is not a defensive programming technique. I've answered it as print statement, that a print statement is not a defensive programming ...
  • 245
3 votes
2 answers
147 views

Explicit type and final in stream lambdas

This argument has been going on for weeks: Bot.getGuild().getMembers().stream() .filter((final Member m) -> m.getRoles().size() == 0) .filter((final Member m) -> !m.getUser()....
12 votes
5 answers
1k views

How to introduce new language features in a legacy source code?

I have a coding style related question. In my example it is java, but I think this can be a generic question regarding languages that are changing rapidly. I'm working on a java code base which was ...
  • 243
21 votes
6 answers
3k views

How to quantify Code Quality [closed]

My Business unit has huge number of developers (About 100). Due to various reasons, the developers are nearly solely focused on delivery rather than quality. The bad quality code has already started ...
3 votes
1 answer
626 views

Avoiding Arrow Anti-Pattern in MISRA-C

For a safety-critical domain, with a code standard including the MISRA C 2004 guidelines, a "simple" piece of code becomes obtuse, chiefly because of the requirements both that all if() statements ...
  • 179
1 vote
3 answers
744 views

How should I name output variables that are the same as the function?

What are some conventions for naming a variable in cases where the name of the variable ought to be identical to the name of the function? I'm using VB.Net. I often have this problem when writing ...
1 vote
2 answers
488 views

Calling methods on objects VS. passing objects as parameters

Which is considered a generally accepted practice? class Image { public void decode(); }; //main Image image; image.decode(); vs class ImageDecoder { public Image run(Image image); }; //main Image ...
1 vote
3 answers
253 views

Which option is best, when you have an attribute that is a list?

I have a class containing a list, for example: class User{ .... List<String> cards ... } What's the best way to provide access to this member? List<String> getCards() or ...
  • 387
1 vote
1 answer
103 views

named fields vs compactness [closed]

Are their any objective guiding priciples to choose between named fields over compactness? const replacements = [ { from: 'apple', to: 'manzana' }, { from: 'banana', to: 'plátano' }, ]; ...
  • 532
2 votes
2 answers
278 views

Introduce code standard into old code

Our main product is written in C++ MFC and follows the same code standard as MFC. Now we will start to develop new components, and think about whether we should continue to use the same outdated ...
  • 201
5 votes
3 answers
2k views

How to deal with long URLs in comments that exceed the 80 characters limit?

I generally try to adhere to the 80 character limit for each line of code to satisfy my colleagues, to satisfy the linting tools, and to maintain an image of professionalism when random people look at ...
  • 161
4 votes
7 answers
1k views

How do you know where you stopped in your codes after a 2-week break? [closed]

I just had a more than 2-week long vacation/business trip and I couldn't remember actually what was I working in my coding and where I stopped. Could someone recommend a best practice to solve this?
  • 175

1
2 3 4 5
11