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
0 answers
47 views

Are type, constant/static/global, and pointer prefixes still necessary in C coding standards, considering the capabilities of modern IDEs? [duplicate]

Our coding standards for C include various prefixes for data types, constants, static/global variables, and pointers. These prefixes were originally introduced for code review purposes, but with the ...
Cem Polat's user avatar
  • 127
1 vote
5 answers
312 views

Is storing computed values always bad?

Edit: I'm copying the question but changing the example code. Apparently, I used a bad example earlier that contained an imprue getter. I'm keeping the old example code at the bottom so the first ...
sharbel okzan's user avatar
0 votes
1 answer
69 views

Practical Advice for rapidly changing code maintainability [closed]

This question may get closed quickly, but I'll appreciate any advice I can get and all the resources I can find online about this topic aren't quite relevant to my case. I am a Math PhD student doing ...
msm's user avatar
  • 109
4 votes
6 answers
321 views

Naming a method that does the same thing faster but only approximates the result?

Presume I have a function that does some precise calculation on a large amount of data, call it calculateResult(data). This function gets very slow with increasing size of input. Luckily, I only need ...
csstudent1418's user avatar
-1 votes
1 answer
123 views

What is point of having certain microservices making another API call in the same service

I was going through an old, largely untouched part in my company’s codebase and found one API. It does the following things. A POST API with path host/entities/trigger which fetches a list of entity ...
elliot's user avatar
  • 11
4 votes
1 answer
303 views

How to label backwards incompatible changes which change the API but don't add a feature?

I have a project in which I'm the sole contributor, there isn't a stable API yet and I'm constantly refactoring code, but I still try to denote breaking changes whenever they do happen. Recently ...
Clara's user avatar
  • 53
8 votes
4 answers
609 views

Are there advantages to using an interface, rather than a class, for a Java application?

Java is often (rightly IMHO criticized) for overusing the class keyword, as it can denote: a factory to instantiate objects (traditional classes) a collection of global methods (when all methods are ...
Ray Toal's user avatar
  • 1,305
0 votes
2 answers
370 views

Can a UUID be called a constant?

From my understanding, a constant is a value which is assigned only once and cannot change at runtime, whereas variables have mutable values which are unpredictable by nature. My question is, to what ...
Clara's user avatar
  • 53
1 vote
0 answers
221 views

Is non-contiguous protobuf field numbering an anti-pattern?

Is it an anti-pattern to have gaps in field numbers to aid readability? The need being address by this idea is that metadata fields, which are "aspect" fields, can be placed in the proto ...
Bohemian's user avatar
  • 1,986
4 votes
5 answers
645 views

Why are vertical and horizontal spacing heavily used in coding styles?

Why would so many repositories use additional — apparently unnecessary — vertical and horizontal space in coding styles? I almost unanimously see this: public function getName() { ...
Nobody-Knows-I-am-a-Dog's user avatar
1 vote
4 answers
500 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 ...
Equescript's user avatar
8 votes
5 answers
3k 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 ...
DaveFar's user avatar
  • 1,416
55 votes
7 answers
11k 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:...
Šime's user avatar
  • 669
3 votes
1 answer
2k 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 ...
explorer's user avatar
  • 149
12 votes
6 answers
5k 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 ...
Adilson Cabral's user avatar
0 votes
5 answers
140 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 (...
alirezaarzehgar's user avatar
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 ...
Onorio Catenacci's user avatar
0 votes
1 answer
223 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"> ...
Renato Junior's user avatar
0 votes
1 answer
207 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 ...
kaay's user avatar
  • 109
-3 votes
2 answers
163 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, ...
tgkprog's user avatar
  • 603
-2 votes
1 answer
288 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 ...
SpiritBob's user avatar
  • 105
0 votes
2 answers
150 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 ...
Pulkit Gupta's user avatar
0 votes
1 answer
65 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() ......
demiculus's user avatar
  • 109
3 votes
5 answers
2k 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 ...
JensB's user avatar
  • 237
-3 votes
1 answer
146 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 ...
AlainD's user avatar
  • 150
4 votes
3 answers
803 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: ...
max's user avatar
  • 63
2 votes
3 answers
1k 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 = ...
DT1's user avatar
  • 211
4 votes
1 answer
84 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 ...
Eduardo's user avatar
  • 151
4 votes
5 answers
362 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 ...
Literal Line's user avatar
0 votes
2 answers
429 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 ...
Takesi Tokugawa YD's user avatar
-3 votes
1 answer
71 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: > .... .... ...
Siddharth Gupta's user avatar
0 votes
2 answers
234 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" -> "...
Takesi Tokugawa YD's user avatar
1 vote
1 answer
192 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 ...
Guish's user avatar
  • 23
-3 votes
4 answers
583 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 ...
Shaun H.'s user avatar
1 vote
1 answer
377 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 =...
janardhan reddy's user avatar
-5 votes
2 answers
352 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 ...
Dan's user avatar
  • 615
3 votes
1 answer
3k 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 ...
Truffle's user avatar
  • 39
0 votes
1 answer
253 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 ...
rohanagarwal's user avatar
1 vote
4 answers
520 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 ...
Hisham Mohammed's user avatar
12 votes
4 answers
3k 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 ...
klutt's user avatar
  • 1,428
-2 votes
4 answers
180 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 ...
Primordial_Hamster's user avatar
1 vote
6 answers
3k 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 ...
Kamil Bęben's user avatar
2 votes
3 answers
502 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 ...
Hawkeye's user avatar
  • 147
2 votes
2 answers
541 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 ...
Fa773N M0nK's user avatar
0 votes
3 answers
304 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 ...
pepijno's user avatar
  • 129
2 votes
1 answer
1k 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-...
gnash117's user avatar
  • 149
0 votes
2 answers
923 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 ...
dextoruz's user avatar
4 votes
4 answers
338 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 ...
Ankur22's user avatar
  • 85
1 vote
3 answers
328 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 ...
kai's user avatar
  • 245
3 votes
2 answers
209 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()....
Julian Durchholz's user avatar

1
2 3 4 5
11