Questions for best practices for writing high quality code.

learn more… | top users | synonyms

0
votes
1answer
53 views

Multiple if in comparison function vs chain of || or &&

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
79 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 = ...
11
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 ...
28
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
164 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 ...
2
votes
1answer
87 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
45 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
67 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
141 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
65 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
75 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
176 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
127 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
122 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
150 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
171 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
57 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
37 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
284 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
318 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
434 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 ...
53
votes
9answers
9k 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
23 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
58 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
183 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
123 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
92 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
220 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
141 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
412 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
157 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
184 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 ...
219
votes
7answers
17k 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
344 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
211 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
334 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
66 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
6k 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 ...
1
vote
3answers
137 views

Use of for loop conditional statement unrelated to iterating variable

Is it considered decent form to write code like this: int done = 0; for (x = 0; !done; x++) { ... something involving 'x', that might end early ... if (!(x < max)) done = 1; } ...
1
vote
2answers
118 views

What is meant by “redundant, but not duplicative” in the Steelman language requirements?

The Steelman language requirements have this: The language shall require some redundant, but not duplicative, specifications in programs. I think I can see the underlying idea (that re-stating ...
1
vote
2answers
197 views

How do I tell my boss that their custom cms is terribly inefficient? [closed]

I started a new job about 2 months ago now with the job title of 'Programmer'. The web dev company I work for had made their own custom CMS and use it for all their sites. Conceptually, the idea is ...
4
votes
2answers
180 views

Separate code coverage reports for unit and integration tests, or one report for both?

Should there be a separate code coverage report for unit and integration tests, or one code coverage report for both? The thinking behind this is that code coverage allows us to make sure that our ...
0
votes
2answers
80 views

PHP conditional test func call against two values

I was wondering if there's a one liner for PHP that would allow me test multiple values against a function call. As example, say I want to test if foo() returns either 1 or 2, (in pseudo code) if( ...
0
votes
2answers
221 views

if a c# interface contain only getter and setter definition, is it a code smell?

A project that I am working on has the following code for interface example: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { public ...
0
votes
1answer
215 views

What are the key areas to evaluate software (codebase) on? [closed]

I have been asked to do a code review of about 50 applications over a period of 6 weeks. (Management has changed and the new CTO asked for an full internal software audit) I am wondering, what are ...
3
votes
1answer
229 views

The most effective arguments in favor of improving code quality, for a manager [closed]

My employer's legacy system started off (in 1997) as very structured procedural code (with a smidgeon of OO), and it was luckily one of the 10% of software projects that was successful. It may look a ...
3
votes
6answers
471 views

Explicitly define enum values, even if the default value is the same?

There are times when an enum's values are important: it is not necessary for them to be unique, they also need to have specific values. In such cases, should the values be explicitly defined, even if ...
0
votes
0answers
59 views

How to define dependent function in node js?

I have a nodejs project in which a sample.js include two function function A depends on function B's callback . // smaple.js Both function are included in the same file function B ( ...
1
vote
1answer
97 views

How to keep class parameters visible while using generic argument passing

After writing some classes where class initialization requires multiple options, instead of writing several parameters into constructors or setters, I started passing an associative array of ...