Questions tagged [code-quality]
Questions for best practices for writing high quality code.
656 questions
4
votes
1
answer
1k
views
CA-1822: Mark members as static Roslyn recommendation will not unnecessarily increase memory consumption?
My job uses SonarQube as part of the CI/CD quality gate. One of the "Maintainability" issues (severity: medium) raised is the CA-1822: Mark members as static.
The link explains the added ...
4
votes
1
answer
432
views
Best way to "verify" programs
As we know, determining the semantic properties of programs is an undecidable problem (e.g. Halting, commonly attributed to Turing). But tools such as static analysis (notably that of Clang/LLVM) are ...
5
votes
1
answer
576
views
Confused on how abstraction and encapsulation is helpful
Using assimp I've created a function to load 3D models and it does everything I need and I don't plan to use another library or write something custom, however, I am curious how techniques such as ...
0
votes
1
answer
228
views
Our php codes base has 6 different ways to do INSERT … ON DUPLICATE KEY UPDATE, how do I fix it?
Our php codes base has 6 different ways to do INSERT … ON DUPLICATE KEY UPDATE. It happened over years because the php framework is evolving and my team members come and go, although I won't say we ...
2
votes
3
answers
345
views
Displaying a list of similar but different objects without resorting to type checking
I'm creating the UI for a "Point of Sale" type page. You can add orders, grouped orders, and custom items to your transaction, and it should display these in a list so you can see what you ...
0
votes
1
answer
278
views
How to deal with very complex codebase? [duplicate]
I recently changed my job to a big MNC and the code I am exposed to is highly complicated, difficult to read and understand. Although it is divided in microservices and runs on local I have to keep ...
17
votes
8
answers
7k
views
How to be (more) critical during Code Reviews? [closed]
I'm a Software Engineer who sometimes need to review the code of my fellow team members. I often look at the source code and think; this looks fine. I'm having a hard time to think critical about it. ...
21
votes
4
answers
10k
views
In C, if I am passing a file descriptor to a function, should I close it in the function or in the place where I called the function?
I have a situation like the following:
int fds[2];
pipe(fds);
// Write lots of stuff into fds[1]
close(fds[1]);
do_stuff(fds[0]);
// Should I close fds[0] here or at the end of do_stuff?
Which one ...
19
votes
9
answers
7k
views
Why should we reuse code as binary modules instead of copy/pasting?
So this is a basic question that was asked by a junior developer (not in these exact words). He had worked on a feature which was used in multiple projects. The main feature can be easily isolated and ...
18
votes
6
answers
5k
views
Is setRGBColor(32,128,192) a valid use of magic number?
According to When is a number a magic number?, I know magic number should not exists, so I know the following code about creating a Label from some UI framework and set the color RGB needs to be ...
40
votes
11
answers
14k
views
Should developers fix bugs in their own code? [closed]
This is more of a philosophical question.
I have recently started working on a new team and I see here a pressure on developers to fix bugs in their own code. Whenever a bug is found in a feature, the ...
1
vote
1
answer
307
views
Is module scoped initialisation considered a bad practice?
A module app.js includes another module service.js. The service.js module/file contains some functions but also does some module scoped initialisations(registry variable).
// service.js
const ...
0
votes
2
answers
179
views
Is usage of "with" prefix acceptable for filter methods that are specific(not generic) [closed]
I am not a native english speaker so I have the following question related to naming I have a class that has generic filter method of type:
filter(Predicate predicate)
In the same class I have some ...
1
vote
1
answer
292
views
Working with a poorly written piece of software as an entry-level developer with no support or documentation [duplicate]
I'm and entry-level developer straight out of college. I am the only developer at this company.
I feel the challenges I face are different to most people working with sub optimal or very poorly ...
2
votes
5
answers
577
views
Is it a code smell for a factory to have many methods?
I have a testing project, in Katalon Studio, that uses data classes, called models. This is a conscious design decision.
Also a conscious design decision, is the decision to separate the concern of ...
10
votes
8
answers
2k
views
When are try/exceptions not an anti-pattern?
I just finished a discussion with colleagues regarding the use of exceptions in code. Here is the code (pseudocode) that they had written:
resp = fetch(URL)
if resp.status_code != 200:
return ...
3
votes
5
answers
736
views
How do I find indicators to show that code review is improving quality of a code base?
I was asked to review and handle merge request for a code base, which has been contributed by dozens of programmer with basically no regulation (or perhaps there was but nobody follows), so I set up ...
-1
votes
1
answer
217
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 ...
2
votes
3
answers
407
views
What would be a good metric of quality of a single bug fix?
If you solve a bug in a poor way, it might result in even more bugs in the future, so I need a way to validate if the fix was actually good. Time between the bug assignment and issue closed doesn't ...
1
vote
2
answers
837
views
Best practice for updating object fields (with values calculated in methods)
What's the cleanest and most coherent way to assign a new value to an object field when the calculation of that value is outsourced to another method?
The most obvious way would just be to update the ...
42
votes
10
answers
7k
views
What is the most efficient way to continue developing a piece of software in the long-term?
For my job, I work on multiple different scientific software projects, as well as general administrative tasks that go hand-in-hand with any 'office' job. Thus, any given working week could involve ...
2
votes
2
answers
262
views
Should I abstract function calls with duplicate arguments?
I have an intuition, that I'd like to read what others have talked about. To me, it seems fairly intuitive that when you have a function which is called multiple times with the same arguments, it ...
-2
votes
2
answers
189
views
best practice to recover or handle requests that is half completed or partially failed [closed]
Assume I have a request:
app.post('/order', ()=>{
// task 1
// task 2
// task 3
})
and task1 and task2 is completed but task3 failed.
for example a user paid order successfully but saving order ...
27
votes
5
answers
8k
views
Dry running a function
I have a function with a sensitive operation:
function doSomeThingSensitive() {
customers = getAllCustomers()
for each customer in customers
if customer is from Europe
Give ...
-1
votes
3
answers
272
views
How to improve coding while/though working? [closed]
How could I improve my coding skills aka skills in coding while being in a job? My job is mainly coding and so, my coding should be better and better over time. But the struggle is: There are always ...
0
votes
1
answer
349
views
Is there a reason why you shouldn't use 'integration variables'?
I tend to create a variable whenever I need an uncircumstantially same value as to that of an earlier value more than once (the values are not happening to be the same by chance rather they actually ...
2
votes
2
answers
393
views
Is "pass through" boilerplate code the trade off for improved encapsulation and composition?
Is it a sign that something is wrong with the code design if you end up with a layer of functions that just forward request to a component? Exposing the component would avoid this but hurts ...
1
vote
1
answer
155
views
What is the best approach to use a common variable in multiple method in a request in laravel [closed]
I have a $c variable that is calculated at the beginning of the request. After calculating this several nested methods use it as a part of their job. Is it better that I pass down the $c variable to ...
-2
votes
1
answer
563
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
1
answer
280
views
Python code template for scripts to be run in batch
I will be writing a number of Python scripts which will be run in batch daily on a Windows server.
I am trying to develop a template for writing the scripts. My intention is to use a configuration ...
3
votes
2
answers
1k
views
GetOrCreate method for a database operation
I have read this thread: Is it bad coding practice to create something in a get if it does not exist?
But, my question involve a method which gets a record from a database or creates it if it doesn't ...
4
votes
3
answers
10k
views
Should try-catch blocks be used when calling functions that already have them?
In JavaScript, if I have try catch blocks in a function that is meant to be called from another function, should I also put them in the calling function or just let the called functions handle them.
...
3
votes
4
answers
384
views
how to perform code review among different types of developer?
My develper team includes Android, iOS, PHP, Web Front, .Net developers, but every type of developer only 1 person, and they don't know other's programming languages very well.
We have setup Jenkins ...
2
votes
3
answers
704
views
How to track temporary fixes
Whenever I do temporary fix I want it to really be temporary.
However, there is no way to come back to it later, as the fix might be a part of a bigger issue.
Let's imagine that we have for some ...
1
vote
3
answers
347
views
Which code to copy-paste and which to centralize?
In a fairly complex system with a dozen or more git repositories, most of them are done in a cookie-cutter fashion.
What is or would be your best approach to deal with duplication?
In my opinion the ...
0
votes
1
answer
184
views
quality management on SQL stored procedures
I've always developed my own applications and use certain criteria to evaluate if the code is acceptable from a quality perspective. Now I've switched jobs and have to among other things maintain ...
1
vote
1
answer
608
views
Is bytes as request parameters as rest endpoint a security risk?
I am working on an application where user can send in an absolute path of an image or URL as string in API endpoint. My code is able to handle that.
Now I have been asked to add the code which can ...
0
votes
0
answers
661
views
Best way to trigger javascript error to go to catch block
I have a couple of doubts regarding the quality of my code. I'm working on a helper function (for KoaJS) where I'm validating a Firebase ID token. If it is valid, I return the decoded token; otherwise ...
1
vote
3
answers
1k
views
Strategies for introducing or enforcing new linting or other code quality tooling rules
I'm in a situation where there is a code base that has TypeScript and ESlint but:
There are a lot of type errors (code compiles despite errors using Babel)
There are a lot of lint warnings.
We may ...
1
vote
2
answers
179
views
How to organize logic for table-like feature set? Looking for architecture pattern advice
I have a table-like feature set in a game. What it means is I have 10 types of battle, and 10 types of features related to battles, like hints, start/end logic, rewarding/spending resources, statistic ...
5
votes
8
answers
1k
views
How to scale code reviews
My boss say we should find a way to scale code reviews at our company. As it is right now, we have about 16 software developers spread across 4 different teams/squads, but soon the company will close ...
-4
votes
1
answer
301
views
Python: Help with replacing list comprehension with generators [closed]
I have written the following code which takes a coord_list of points in a 2D coordinate system, a center and a radius and returns a list of all points from the list having distance at most radius from ...
2
votes
1
answer
1k
views
How do pull requests fit into a development process?
In my software engineering career I have never worked with pull requests. Probably because I only ever worked in relatively small teams (5-16 people) and only on projects that were structured well ...
-4
votes
3
answers
200
views
Methods that receive buffer objects AND return another Object - is that bad design?
The Argument
Some say that if you write a method that receives a buffer, iT MUST RETURN VOID -> the buffer is your exit point.
Do not abuse the methods by receiving buffers AND returning a another ...
0
votes
1
answer
395
views
Code review patterns for multiple teams working on a single product
We're scaling out development on a single product from a single team to multiple teams. What are the patterns to ensure coding style, patterns and technology is used consistently?
Is there one person ...
69
votes
8
answers
17k
views
In code review, should I ask to do a refactor outside of the scope in a pull request?
I have been studying the best practices for a code review, and I was wondering what to do in the following scenario:
During a code review, I see potential improvements, but decide that they are ...
1
vote
3
answers
211
views
Why are code readability and debugging arguments often expressed as a counter-argument for the use of generated LR parsers?
When it comes to using an LR parser generated by a tool, such as Bison, a disadvantage that often comes up as counterarguments is that the resulting parser will be unreadable and complicated to debug, ...
0
votes
3
answers
944
views
How to arrange expected result model for test in a cleaner,readable way when the model contains many properties
In one of my projects I saw wrapping the expected results as a static variable in non static class. The reason for doing so is to make the code more readable, so that the massive expected result model ...
2
votes
1
answer
543
views
Converter implementation in Python: class versus module?
I've written a little library that uses the builtin ast library to convert between functions, docstrings, argparse .add_argument, classes, and [soon] more.
Stubs look something like this, with ir ...
-2
votes
1
answer
109
views
Code Base Analysis
Does anyone know of a methodology that can be used on a project file tree to identify dead files, dead code, unused libraries, etc. I have been thinking about this for some time as I seem to inherit ...