Questions for best practices for writing high quality code.

learn more… | top users | synonyms

4
votes
3answers
170 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
25 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
59 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 ...
-1
votes
0answers
69 views

When should mixed PHP/JS snippets be refactored into a separate JS file? [duplicate]

This code snippet is from a teammate of mine, his title is "Full Stack Developer". He mostly write PHP code. I found this code at the end of a .php file and asked him to move it to a separate JS file ...
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
486 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
21 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
689 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
31 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
88 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
382 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
82 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
103 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
176 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
107 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
56 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 ...
1
vote
1answer
74 views

Java private method signature clarity and better practice [closed]

I received the code review comment for below code snippet - public void doWork(String a, Integer b) { .. .. SomeService service = getService(); for (Integer i : numbers) { ...
1
vote
1answer
153 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
107 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
81 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
190 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
131 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
132 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
165 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
67 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
1answer
182 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
61 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
38 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
295 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
326 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
507 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
26 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
60 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
230 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
130 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
94 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
249 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
143 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 ...
2
votes
6answers
441 views

Why sacrificing good software engineering practices is typically the first choice for software development projects assuming “good enough” quality [duplicate]

I have observed a correlation between a customer ordering software of "good enough" quality and the same customer not willing to pay for good engineering practices (unit testing, code reviews and the ...
3
votes
1answer
166 views

Unit testing a template class after refactoring

I am cleaning up my code by way of removing duplicates, and found two classes that were almost identical, out of 55 lines, only a single predicate in an if statement differed between them. Both ...
3
votes
2answers
187 views

How to deal with historic exception specifications in maintained C++ code

Today, I discovered a few exception specifications in legacy code I've to maintain, when Cppcheck 1.68 ([Inconclusive] but correctly) pointed out that the specified exceptions are not handled in ...
221
votes
7answers
18k views

Does using == in JavaScript ever make sense?

In JavaScript, the Good Parts, Douglas Crockford wrote: JavaScript has two sets of equality operators: === and !==, and their evil twins == and !=. The good ones work the way you would expect. ...
3
votes
3answers
361 views

Where should I place a typedef when used in method signatures in C++?

I'm using an Optional class quite similar to that of boost. For semantic reasons, I switched an attribute of the same (structured) type in some class definitions (and therefore also in method ...
0
votes
1answer
250 views

Suggestions on refactoring a poorly written ASP.Net MVC web application [closed]

I have recently "inherited" a project written in ASP.Net MVC which has quite a few issues and I'm looking for suggestions on how to go about refactoring the code. The technical issues found so far ...
2
votes
2answers
342 views

Should we refactor our existing codebase to use functional programming, especially streams? [closed]

We have a large project written in PHP. It almost exclusively uses imperative operations, as in example 1. Should we refactor our existing code to use functional operations? Do you think that the code ...
1
vote
0answers
67 views

Reject pull request or accept incorrect code? [duplicate]

Very often I have to review pull requests of fellow programmers and I face the problem - what should I do when the code is not as good as I would expect? Should I reject the pull request or ...
65
votes
6answers
7k views

Are all magic numbers created the same?

On a recent project, I needed to convert from bytes to kilobytes kibibyte. The code was straightforward enough: var kBval = byteVal / 1024; After writing that, I got the rest of the function ...