Questions for best practices for writing high quality code.
3
votes
1answer
47 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 ...
1
vote
0answers
18 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
58 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. ...
4
votes
1answer
58 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
62 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
62 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
144 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 ...
7
votes
1answer
164 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
53 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
150 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
41 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
64 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
522 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 ...
1
vote
1answer
37 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
704 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
34 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 ...
-1
votes
2answers
96 views
Personalization of code: Personalized debugging message, personalized strings and project tags [closed]
I was given a code review today by a coworker.
1) I'm told not to use personalized tags to aid in searching for important portions of the code. For example:
Personalized Strings, for example ...
1
vote
2answers
437 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
83 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
111 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 ...
29
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
195 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
129 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
68 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
160 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
235 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
89 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
225 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 ...
1
vote
4answers
143 views
What practical steps do you take to ensure you are thorough? [duplicate]
Bit of Context
I'm not sure if this is fitting to the programmers.stackexchange area, but I'm not going to post it in SO. Any problem with ambiguity and I'll happily remove it.
If I had to talk ...
0
votes
1answer
138 views
Changing repetitive code to improve good programming design
In Java Swing if you want to add a listener to a component, it would look something like this...
JButton j = new JButton();
int counter = 0;
j.addAncestorListener(new AncestorListener() {
...
3
votes
3answers
183 views
Development Time: sql in UI code vs domain model with datamapper
First, sorry for my English guys.
Currently this is my first programming job. I am labeled as the most incompetent programmer in my company that's because they measure the performance and ...
0
votes
4answers
71 views
What's the best way to handle slightly different exceptions?
My code right now looks something like this:
void throw_illegal_part_of_input_exception(char c) {}
void throw_invalid_input_length_exception(int position, int length) {}
void ...
1
vote
2answers
158 views
What about source code homogeneity?
As time passes I think that one valuable aspect of maintenable and escalable software is to be homogeneous. The same problem should be solved in the same way everywhere in the application. If there is ...
1
vote
1answer
191 views
how to introduce a culture of quality into the work environment? [duplicate]
Currently we're not doing any code reviews and we have effectively zero unit tests (we have some but they are never run by anyone else other than myself) and there's no coding standards for style and ...
0
votes
1answer
67 views
Cyclomatic complexity for 2 IFs - why not just FF or TT?
I know that cyclomatic complexity defines the number of independent paths in the code. Using the simple way, it can be calculated as number of IF +1. In that case, for a simple code with two IFs, CC ...
1
vote
1answer
40 views
How to handle type conversion of a constant?
Consider the following (imaginary) code extract:
class X {
private static String IS_PAYLOAD_REQUIRED = "4001";
[....]
checkPayloadRequired(String input) {
if ...
3
votes
8answers
296 views
Creating one-line method for the single purpose of self-documenting code [duplicate]
Given the following two snippets:
Snippet 1:
public void foo(Data data, AbstractNode node)
{
int originalId = data.getCurrentId;
node.execute(data);
//If node changed currentId reset it ...
5
votes
5answers
336 views
Should the method describe its side effects? [duplicate]
I was reading Clean Code by Bob Martin and there's one particular code smell, related to naming, that looks interesting to me:
N7: Names Should Describe Side-Effects
Names should describe ...
6
votes
1answer
715 views
What is the purpose of Code analysis and when do I need to use it?
I heard about Visual Studio's Code analysis but never used one. I've read MSDN, but still don't understand the real use of Code analysis.
Isn't it the same as StyleCop?
Somewhere, FxCop was also ...
54
votes
9answers
10k views
Bad sign if nobody can comprehend one's code? [duplicate]
If a coder writes code that nobody other than he can understand, and code reviews always end with the reviewer scratching his head or holding their head in their hands, is this a clear sign that the ...
1
vote
0answers
47 views
Managing interdependent project reference in solution file
Context for question
I am working on a legacy product, that has multiple projects - Class libraries, websites, windows services, web services etc.. I have a single solution file that contains all ...
0
votes
3answers
61 views
Returning reference type passed to method
I'm asking this from .NET (C#) point-of-view, however, I'd preferire language agnostic answer.
Is it better to return the reference type when some value is changed in method or not? I'm mostly ...
1
vote
1answer
274 views
Is circular Dependency Injection a good practice?
I'm trying the Dependency Injection pattern in some new classes, more specifically in a Transaction System and stumbled into a dilemma. I have a Person class with a create_new_transaction method, and ...
2
votes
2answers
136 views
Is it acceptable to refactor a collaborator's code?
When working with other people in a project, is it acceptable to refactor some of their code?
I'm working with another developer and I notice a lot of duplicate code. To make things easier for ...
0
votes
2answers
97 views
Empty except block vs. huge except block
Which of these is easier to read?
An empty except block:
try:
foo = do_foo()
except FooError:
pass # see below
else:
return do_bar(foo)
# Recover from the FooError (long, complicated)
...
0
votes
1answer
304 views
WCF Project Structure & Maintainability
We are working on a medium scale WCF project configured to use per call instancing and wondering weather it's a good practice to create classes per service method to hold the business logic since each ...
0
votes
1answer
150 views
Is brevity in writing code beneficial when it requires using language constructs in a strange way [duplicate]
In C#, with extension methods, you can replace this line of code:
TimeSpan interval = TimeSpan.FromMinutes(4);
with this one:
TimeSpan interval = 4.Minutes();
Extension method being:
public ...