Questions for best practices for writing high quality code.

learn more… | top users | synonyms

4
votes
1answer
540 views

In Java, why use bit hacks when non-bitwise technique it is more readable?

Is there any legitimate use for bit manipulation hacks in higher-level languages such as Java? I can see them being useful in speed-sensitive low-level and computation-intensive programs, e.g. ...
12
votes
5answers
4k views

Is it considered Pythonic to have multiple classes defined in the same file?

In working with python for the first time, I've found that I end up writing multiple classes in the same file, which is opposed to other languages like Java, which uses one file per class. Usually, ...
28
votes
13answers
2k views

Fix bugs, or wait for the customer to find them?

Do other people fix bugs when they see them, or do they wait until there's crashes/data loss/people die before fixing it? Example 1 Customer customer = null; ... customer.Save(); The code is ...
0
votes
2answers
214 views

Working with Javascript classes the right way

Comparable questions have surely been asked before but I'd like to hear some words about my specific way of implementing Javascript classes. Let me first start with a Javascript example taken from a ...
1
vote
2answers
109 views

Apply filter only if not null

My function takes an optional parameter, type, which is used to filter through a collection. However, the filter should only apply if the parameter is passed in (in other words, non-null). If the ...
1
vote
3answers
251 views

Software architecture for two similar classes which require different input parameters for the same method

I am writing Java code to simulate a supply chain. The supply chain can be simulated in either an intermediate stocking or a cross-docking configuration. So, I wrote two simulator objects ...
1
vote
0answers
118 views

Diagram to show code responsibility

Does anyone know how to visually diagram the ways in which the flow of control in code passes between code produced by different groups and how that affects the amount of code that needs to be ...
8
votes
6answers
2k views

Prefer class members or passing arguments between internal methods?

Suppose within the private portion of a class there is a value which is utilized by multiple private methods. Do people prefer having this defined as a member variable for the class or passing it as ...
1
vote
1answer
143 views

Is it good practice to analyse who introduced each bug? [duplicate]

I used to analyse performance of programmers in my team by looking at the issues they have closed. Many of the issues are of course bugs. And here another important performance aspect comes - who ...
1
vote
3answers
79 views

Modelling highly specific business requirements

How can one go about modelling highly specific business requirements, which have no precedent in the system? Take for example the following requirement: When a purchase order contains N lines, is ...
2
votes
4answers
252 views

Is it normal needing time to understand code I wrote recently [closed]

By recently I mean some weeks ago. I am trying to continue a project I left 2 weeks ago and I need time to understand some functions I wrote (not copied from somewhere) and it takes me time. Normally ...
76
votes
11answers
5k views

Why should main() be short?

I've been programming for over 9 years, and according to the advice of my first programming teacher, I always keep my main() function extremely short. At first I had no idea why. I just obeyed ...
2
votes
2answers
141 views

Checking program robustness using static code analysis

(Building on this question) If you have a static code analyser such as Checkstyle, is it possible to to relate any of the stuff that it checks for to actual robustness? Some of the things that ...
39
votes
12answers
5k views

I am making 4-5x more story points than average, but producing bugs at half the rate. Graphs say it's 2x more bugs, how to deal with that?

So it is generally accepted that top tier programmers can produce an order of magnitude more/better code than their more average peers. It's also generally accepted that the rate of errors made in ...
16
votes
11answers
2k views

How to address the concerns of the software architect but still maintain collective code ownership? [duplicate]

The quality of the code in our software is indeed lacking. When you change a line of code in one component it usually breaks code in other components. Our software architect blames this on collective ...
-1
votes
1answer
182 views

How to code efficiently? [duplicate]

I often compare my code to others and I find their solution more efficient and shorter than mine. Although both solutions work, I can't help it but wonder if mine is not adequate enough. As a result, ...
1
vote
4answers
1k views

Legitimate reasons for circular references in C++

I have project written in C++ that I am working on which has a parent-child relationship where each child has only one parent. I had previously decided after looking at this post that I would make the ...
7
votes
4answers
487 views

Does “write quality code” advice apply to companies of any scale? [duplicate]

I carefully followed the "always write quality code, unless you're writing a prototype" advice during my career as freelancer and software developer. I was convinced pretty early that avoiding to do ...
2
votes
3answers
155 views

When to use python function nesting?

I am writing a program that creates backup of directories. Which of the following approach is better for code organization? Create separate class for Backup and Zip logic - class BackupUtil: ...
3
votes
2answers
147 views

Reflecting on finished project with no other technical criticisms?

I'm a coop (in college but I work 3 months, then do classes for 3 months, work again for 3 months, etc until I graduate) at a company in their IT department. My job usually has to do with writing ...
27
votes
10answers
4k views

Getting coders to do code review [duplicate]

I am running a project where I pay developers to contribute to my semi open source project. My problem is that it is easy to hire developers, but it is very difficult to get anyone to do code ...
29
votes
10answers
4k views

Are flag variables an absolute evil?

Are flag variables evil? Are the following kind of variables profoundly immoral and is it wicked to use them? "boolean or integer variables that you assign a value in certain places then down ...
0
votes
1answer
171 views

Is it a good practice to decouple the membership system?

Currently I'm developing a project that basically is built with ASP.NET Web API. The membership system I'm using is ASP.NET Identity. The only problem I'm seeing with this is that the membership ...
11
votes
7answers
945 views

Is test coverage an adequate measure of code quality?

If I have some code that has 80% test coverage (all tests pass), is it fair to say that it's of higher quality than code with no test coverage? Or is it fair to say it's more maintainable?
0
votes
0answers
85 views

Creating New Wrapper Objects and Extension Classes and Keeping it Organized

Here's my situation: I'm programming an embedded device with a very simple, but customizable LED array display. It's 10 RGB LEDs linearly setup. The LEDs will be used to display many different ...
1
vote
4answers
301 views

What's the point of Continuous Integration services like Travis CI?

As far as I can tell, services like Travis CI and CircleCI take your project and run its test suite whenever you push a new change to your repository. Assuming that it's also possible to either ...
2
votes
3answers
3k views

General checklist before releasing software [closed]

I'm currently building a tool that my company intends to sell. I'm the sole developer on the project and it is being developed outside our normal code base and to a certain extent outside our normal ...
4
votes
1answer
271 views

If TDD is design, how do you know your TDD is well designed? [duplicate]

Given a large group (50+) of programmers: All given the same problem, All using Test-Driven Development (TDD), All pair programming, All doing group-based code review, I have personally seen the ...
1
vote
1answer
163 views

Java code quality in methods calling methods

I am currently working with an "interesting" code-base and see the following type of thing alot in the code. public Object doSomething() { Object obj = new Object(); // Do some stuff to the ...
0
votes
0answers
50 views

Algorithm to Select Sequential Subarrays from an Array

I solved my problem by using simple nested loops and comparisons but I'm wondering if there is a well known Selection Algorithm to solve my problem. Let's say I have an array such as [1, 10, 250, 9, ...
0
votes
1answer
139 views

What should be the minimal quantity of code production per week? [duplicate]

I'll try to further explain what I mean. Imagine you are the boss of a company. You have to deal with the tradeoff between the quality of the code and the speed of producing it. Let's assume to ...
5
votes
4answers
820 views

Sprint pressure causes quality issues? [closed]

The burn down chart displays a clear deadline and the progress towards the deadline. When the progress is slow and the completion of the committed work is at risk, people start to get sloppy on design ...
0
votes
1answer
274 views

Lean Startup MVP: Quality Code or Quick and Dirty [duplicate]

Hello some programmers might know about the lean philosophy, building a minimal viable product Lean Startup MVP. I ask myself (when building Webapps): "Should I put effort into writing good ...
1
vote
0answers
33 views

Reducing Valgrind Findings (uninitialised value)?

I'm trying to run some code though Valgrind. The code depends on OpenSSL, and OpenSSL is making Valgrind useless due to uninitialised values. I know where the use lies in OpenSSL's PRNG, but I'm ...
21
votes
5answers
2k views

Is code ownership a code smell?

This is something I've been thinking about ever since I read this answer in the controversial programming opinions thread: Your job is to put yourself out of work. When you're writing ...
6
votes
6answers
502 views

Code ownership with multiple Scrum teams

If two Scrum teams use the same software component, who is responsible for providing a clear architectural vision of that component and maintain/develop this vision as the code base evolves? In Scrum ...
22
votes
14answers
920 views

How do you overcome your own coding biases when handed legacy code?

As programmers, we often take incredible pride in our skills and hold very strong opinions about what is 'good' code and 'bad' code. At any given point in our careers, we've probably had some legacy ...
2
votes
1answer
53 views

When should I pass setting-like value as class' variable and when as an assoc. array?

Following my other question, is there a general rule of thumb, when we should pass a setting-like value, that controls class' behavior (for example displayed texts) as as class' constant or variable, ...
1
vote
1answer
97 views

When should I pass value as class variable and when as a method argument?

Is there a general rule of thumb, when we should pass a value as as class variable and when as a method argument? Or is it just a choice of the developer? For example -- are there any reasons, why ...
3
votes
3answers
132 views

Can removing unnecessary file from a repo be considered part of refactoring?

We're using Git as our DVCS and we're about to start to do a clean up (never done before in this team) of files that are not necessary (not part of the sources) from our products. This is done in two ...
3
votes
5answers
2k views

Declaring functions in order to avoid explicit nested loops

My programming professor has told me that it is a good programming practice (at least in C/C++) to declare a function with the inner loop when nesting loops (not for loops, since when, i.e. looping ...
45
votes
19answers
3k views

Forcing people to read and understand code instead of using comments, function summaries and debuggers? [duplicate]

I am a young programmer (finished computer science university but still under a year of working in the industry) and I recently got a job working on some C code for a decent size web service. Looking ...
6
votes
6answers
557 views

When to write Abstract code and when to be more specific?

I'm working on a small tool as a toy project to show the difference between two directories, showing which files/directories were added, removed, modified, etc. I was trying to represent these ...
2
votes
1answer
196 views

How to avoid too much html in JQuery?

I'm not liking how my JQuery is after making some dynamic buttons, or other dynamic things. For example, when I have checkboxes marked, I add a button that is called "Download Selected" and "Remove ...
8
votes
2answers
688 views

Are there any good use-cases for variable variables?

Today I encountered this little PHP gem called variable variables. $literal = "Hello"; $vv = "literal"; echo $$vv; // => prints "Hello" Are there actually any real use-cases for this language ...
13
votes
10answers
3k views

Passing member variable as a method parameter

In a project, I've found a code like this: class SomeClass { private SomeType _someField; public SomeType SomeField { get { return _someField; } set { _someField = value; ...
2
votes
1answer
581 views

equals and hashcode methods autogenerated, is it always a good practice?

Preamble: Let's say I aim to cover all my classes with test coverage. Despite the common opinion (expecially in Java community) to "not pay too much attention to Cyclomatic Complexity (CC) and code ...
1
vote
2answers
129 views

Should a method in a class be aware that the class has “loaded” a variable?

So I have the following code, which connects and then binds to an LDAP server. The question is in the first method. public function getUsers() // This is the method in question { if( ...
0
votes
1answer
91 views

should this code be structured into an event capture and a method or put the functionality in the event capturing

I have adopted some jQuery code that has like 20 event-captures that look like this // used on menu#edit $('.show-headers-only-toggle').on('click',function(){ ...
6
votes
5answers
505 views

How do you get developers to want to write good code they can be proud of? [closed]

In a team of developers, how do you get the developers to feel pride in their code and write good code (I realize this is subjective and everyone is different, but there is a point when I write code ...