Questions for best practices for writing high quality code.
4
votes
2answers
94 views
The concept of “quality gates” in software testing
We are using SonarQube for code quality testing. It tests the quality of code, and not the function of code. It has the concept of quality gates, so you can set for instance a 90% quality gate, ...
2
votes
1answer
148 views
How to respond to bizarre requests in code reviews? [closed]
I think that code reviews are great and very helpful for everyone. With that being said, from time to time I've received feedback on a pull request (leading to the PR being delayed for at least as ...
1
vote
1answer
184 views
Is defining only one method against S in S.O.L.I.D
The first version of pseudo code I consider a code smell because of (I think) the Command Query Separation principle and/or the S in S.O.L.I.D. What I like to see is in the 2nd version.
Should I keep ...
3
votes
1answer
294 views
Bad c++ code design? [closed]
This is bothering me a long time. I feel like I am doing mistakes on the code design relative to the performance. I never had any teacher to indicate my mistakes so its hard to me to make it right in ...
6
votes
3answers
976 views
Is break a code smell?
I'm asking in terms of a loop, obviously break is important in switch statements. Whether or not switch statements themselves are code smells is a separate issue.
So consider the following use cases ...
1
vote
2answers
108 views
Does an interface including several methods that return instances of Object make sense?
I am in the process of writing my first true API. In the process, I am defining an interface for mapping complex data structures onto other complex data structures.
At the moment, the interface ...
28
votes
8answers
6k views
Is it acceptable to copy and paste long but straightforward code instead of wrapping them into a class or function?
Suppose I have a segment of code to connect to internet and show connection results like it:
HttpRequest* httpRequest=new HttpRequest();
httpRequest->setUrl("(some domain .com)");
...
96
votes
13answers
15k views
Should we avoid language features that C++ has but Java doesn't to increase maintainability?
Suppose I am limited to use C++ by the environment in the project. Is it good to prevent the use of some language features that C++ has but Java doesn't have (e.g.: multiple inheritance, operator ...
1
vote
0answers
119 views
Can this be used to implement Post Redirect Get pattern?
I am trying to implement proper a Post Redirect Get on a PHP site (question is language agnostic in nature however). I thought about it, and realized that running this code on every request seems to ...
0
votes
3answers
176 views
Best practices in exposing interface
Let's assume I have a class that downloads data from API, cleans it and saves to database. What methods should I expose?
class ApiConnector1
{
public string GetDataFromApi()
{
// ...
...
1
vote
0answers
43 views
WMC Calculation in CK Metrics Suite
I have two classes C1 and C2. C1 has 2 methods and C2 has 3 methods each of complexity value 1. C2 inherits from C1. So, I know C2 has 2+3=5 methods in all. The question is, should I take C2 to have 5 ...
3
votes
1answer
116 views
What percentage of failed requests is “normal” [closed]
So I just launched my first "real" site that actually has a decent amount of interactions and whatnot. It's an ASP.net site with a SQL backend.
We've served 130k requests in the last 12 hours but ...
1
vote
1answer
80 views
flatMap with if else vs combine with filter
When using reactive frameworks I have seen both solutions below to make a mutually exclusive selection of which stream will be forwarded (rxjava in this case)
Observable.merge(
...
-3
votes
2answers
166 views
Why ever use exception throw (in C#) except for Class Library development? [duplicate]
Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change).
To be more specific, ...
2
votes
2answers
168 views
Passing fields (instance variables) by arguments (parameters) inside an object - does it make sense? [duplicate]
I believe this is language agnostic question - if it's not then please correct me.
Let's say I have a class (code snippet is a kind of 'pseudo code')
class Car:
private steering_wheel
private ...
0
votes
0answers
65 views
Is there a school of thought where while(1) or while (true) is a code smell? [duplicate]
My employer requires code reviews for all devs, and new employees are required to to have their code reviewed by a senior dev. Initially, trainees get to pick a small project they are working on and ...
1
vote
2answers
224 views
Code quality : what's the worth of the looking at the ifs?
We've all seen discussions on the ideal length of a method. My favourite litmus test for code quality is to look at the "if" statements, to see whether the values being tested belong to the current ...
-2
votes
1answer
201 views
Searching for 2 numbers that equal 10 [closed]
During an interview today I was asked to write a function that accepted an array of integers and return the positions of two values in the array that the sum was 10.
My code was
C#
public string ...
1
vote
5answers
543 views
Is this taking DRY too far? [duplicate]
A colleague and I are working together on a Meteor app.
One of us thinks that the following code in two places should be wrapped in a function to avoid duplication -- the other thinks that it leads ...
4
votes
2answers
144 views
Who is the Owner of Information? Memento vs. Originator
Imagine for a second that I'm implementing the Memento Pattern, using the following classes.
Classes
An Originator class that has public and private, properties and fields respectively
A Memento ...
2
votes
1answer
107 views
How to properly manage “business” constants with AngularJS?
I'm working with AngularJS on a browser game and I have a bunch of "business" constants.
These constants will be often updated during game testing (game balancing) and are used by different ...
2
votes
2answers
99 views
How to reduce redundancy in a service implemented using multilayer architecture while maintaining consistency across the system?
Currently our service is implemented using a multilayer architecture dividing the whole service into three:
API
Business
Persistence
However this introduces a lot of redundancy within our system. ...
8
votes
6answers
2k views
How to implement a property on class A which refers to a property of a child object of class A
We have this code which, when simplified, looks like this:
public class Room
{
public Client Client { get; set; }
public long ClientId
{
get
{
return Client ...
4
votes
1answer
140 views
Should a web service return an error message if it receives unknown parameters?
I have a web service which allows to retrieve users: http://example.com/users. It returns a list of users.
That service accepts a number of parameters (age, gender) to select which users to retrieve. ...
2
votes
3answers
69 views
Order of terms in a conditional expression [duplicate]
Consider the following loop (in Swift - but my question is language independent):
var index = standardizedTimeSpans.count - 1
while index >= 0 && timeSpan < ...
2
votes
0answers
71 views
Is a long XSLT file a code smell? [closed]
Is a long XSLT file a code smell?
In imperative programming languages it's generally acknowledged that very large classes and/or sub-routines are an indication of possible problems, e.g. a class ...
0
votes
2answers
355 views
Is cyclomatic complexity density a good software quality metric? [duplicate]
Where I define Cyclomatic complexity density as:
Cyclomatic complexity density = Cyclomatic complexity / Lines of code
I was reading previous discussions about cyclomatic complexity and there seems ...
8
votes
2answers
231 views
Do we need to validate entire module usage or just arguments of public methods?
I've heard that it is recommended to validate arguments of public methods:
Should one check for null if he does not expect null?
Should a method validate its parameters?
MSDN - CA1062: Validate ...
0
votes
2answers
100 views
Built-in the separate thread execution inside of the method or wrap the method by the thread
Let assume, I have some resource and time-consuming code, which I want to arrange as a separate method. In order to optimize the performance, this code should be executed in the separate thread.
Now ...
1
vote
1answer
161 views
Right-aligning code [closed]
I recently was looking for a CSS solution to vertically-align elements, and I found one here.
One thing that I thought was nice was the right-justified code; example:
.vertical-center {
// ... ...
47
votes
7answers
5k views
What is the actual value of a consistent code style
I am part of a consultant team implementing a new solution for a customer. I am
responsible for the majority of code reviews on the client-side codebase (React and javascript).
I have noticed that ...
0
votes
1answer
51 views
Dealing with data containing integer overflow, rollover
I am writing a small matlab function to analyze data from a laser probe.
The data to be analyzed is basically:
x-data: Position.
y-data: Laser (light) intensity.
...
0
votes
1answer
85 views
Is a number used only once and directly bound to a function parameter a magic number? [duplicate]
I want to avoid numbers used directly in expressions without obvious meaning. However, if a number is used only once, as an argument passed into a function, and that number can be easily changed ...
34
votes
6answers
4k views
How can I write unit tests that simplify feature implementation? [duplicate]
I'm a newbie to working in software development and I read a lot about how cool unit tests are. Now, I've made my first steps into a project where I'm working with a number of equally unexperienced ...
8
votes
3answers
596 views
Cleanest way to write logically procedural software in an OO language
I'm an electrical engineer and I don't know what the hell I'm doing. Please save the future maintainers of my code.
Recently I've been working on a number of smaller programs (in C#) whose ...
2
votes
2answers
71 views
SDK/DB isDeleted vs Integration Testing
((Using "users" as an example to represent one of many record types))
An application with user tracking typically has a User table. Many, if not all, companies mandate that a User record should ...
6
votes
6answers
756 views
What are the most used pattern to manage a lot of interconnected parameters?
I recently start to work on an application that drive different measurement device.
Before the user start a measure, she sets the parameters of it.
Actually, considering all measurements type there ...
0
votes
0answers
36 views
Defensive Programming - “Return” placement [duplicate]
Sometimes I see myself writing code in the following way:
if(value == null) return null;
//... I will have here as many defensive conditions (and returns) as I need
//... Continue to execute method ...
3
votes
2answers
1k views
Class becoming God Object what pattern to use
I am developing Android app and my MainActivity is becoming God Object.
By the way native Activity class implementation is some sort of God Object already.
The problem is that my activity class is ...
0
votes
1answer
90 views
Multiple if in comparison function vs chain of || or && [duplicate]
I'm writing a function (or operator==() in C++), comparing two objects. The code looks like this:
bool operator==(const Obj& copy1, const Obj& copy2)
{
if(copy1.a!=copy2.a)
return ...
0
votes
1answer
134 views
Passing same argument to multiple small functions versus doing everything in one big function?
I have inherited a class method from another developer, which looks like below:
(Note: Class:X means X is a member of Class in the OOP paradigm.)
Class:BigFunction()
{
ImportantValue = ...
13
votes
2answers
1k views
Is an NPath complexity of over sixteen octillion realistic? Or have I broken the tool?
I have just measured a large chunk of PHP code (1153 lines) using PHPMD (http://phpmd.org/) and it tells me the code has an NPath complexity of 16244818757303403077832757824.
That looks like a ...
30
votes
11answers
3k views
What factors should influence how I determine when to abandon a small project with a friend? [closed]
I've found myself in a tough spot as of late. Been working on a game with a programming buddy for nearly 8 months now. We both started off as newcomers to programming around August of last year, he is ...
2
votes
2answers
230 views
Is there a software industry for converting old, outdated code to new standards? [duplicate]
There still are developers building and extending applications using languages like COBOL, since banks and other such organizations rely on ancient systems to power their day to day businesses. Some ...
3
votes
1answer
315 views
Including standard library headers only once across multiple program headers
I am writing a program with multiple headers and code files, as so:
message.h
message.cpp
option.h
option.cpp
main.cpp
message.h includes option.h as message.cpp requires the definition of the ...
0
votes
0answers
109 views
GMP Core Dump while using mpz_clear in C
I'm working on a prime factorization program written in C using the GMP library through cygwin. The algorithm that I have now works fine, but has memory leaks from not using the mpz_clear function on ...
2
votes
1answer
176 views
How much trouble can the use of Singleton class as Model cause?
In my latest WPF applications I've been using a Singleton class, that I call Model, to contain all my application's logic, such as file reading, information handling, etc..
In the WPF Views or ...
2
votes
1answer
1k views
When to use def in Groovy?
I have been developing in Groovy for a little while now and I'm wondering how often I should be using the dynamic casting def? A co-worker of mine believes we should use it always as it helps Groovy ...
1
vote
1answer
128 views
When should one create a new py-function rather than tweaking another one?
Me and a co-developer are arguing when it's wise to cast a new function rather than tweaking another one. By tweaking I mean an option or a hidden check in an existing function. The question could be ...
1
vote
3answers
361 views
Avoid opt(options) in javascript [closed]
A lot of frameworks, most like jQuery plugins uses the "optional" parameter. Basically a dictionary (or key/value structure) with a bunch of additional parameters instead of send in the parameter's ...