Questions for best practices for writing high quality code.

learn more… | top users | synonyms

16
votes
9answers
1k views

Are too many assertions code smell?

I've really fallen in love with unit testing and TDD - I am test infected. However, unit testing is normally used for public methods. Sometimes though I do have to test some assumptions-assertions ...
1
vote
6answers
2k views

Setters or constructor for many variables? [duplicate]

Possible Duplicate: Are there guidelines on how many parameters a function should accept? I have got class with 30 variables (it is application form), so I wonder what is the best practice ...
17
votes
10answers
2k views

Is 100% code coverage a pipe dream?

Is it feasible to expect 100% code coverage in heavy jquery/backbonejs web applications? Is it reasonable to fail a sprint due to 100% coverage not being met when actual code coverage hovers around ...
2
votes
5answers
1k views

Is automatically checking code quality via metrics possible?

For several years now I am a big fan of using static code analysis tools for checking the source code quality. We are mostly doing C# development so NDepend was the best way to go for me. Most of the ...
3
votes
4answers
291 views

Create new variable or make multiple chained calls?

What is the best way to get this attributes, thinking in performance and code quality? Using chained calls: name = this.product.getStock().getItems().get(index).getName(); id = ...
6
votes
9answers
906 views

Review quality of code [duplicate]

I have been asked to quality review two code bases. I've never done anything like that, and need advice on how to perform it and report it. Background There are two providers of code, one in VB and ...
9
votes
5answers
970 views

Is it bad coding practice to create something in a get if it does not exist?

So I have a webservice that has something like a getAccount where it would return an identifier to the account if it got it, else throw an exception. The client will always want to create an account ...
5
votes
6answers
527 views

How to deal with over-complication?

I often catch myself doing code unnecessarily complicated (sad but true). Is there any set of rules, discipline, etc to help avoid that? (excluding the KISS principle, because I know it but often ...
1
vote
3answers
6k views

how to nicely use constant std::string in c++

In my current code project, there is an awful lot of constant strings I use to print out error messages. Hardcoding such strings is generally considered to be bad practice. Now I'm searching for a ...
10
votes
3answers
1k views

Experiments correlating code metrics to bug density

I'm wondering if someone has done some experiments correlating code metrics (SLOC, Cyclomatic Complexity, etc) with bug density in Object Oriented applications. I'm not looking for experiments that ...
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; ...
26
votes
5answers
2k views

Is use of finally clause for doing work after return bad style/dangerous?

As part of writing an Iterator, I found myself writing the following piece of code (stripping error handling) public T next() { try { return next; } finally { next = ...
9
votes
7answers
5k views

What is the difference between Static code analysis and code review?

I just wanted to know what the difference is between static code analysis and code review. How are each of these two done? More specifically, what are the tools available today for code review/static ...
133
votes
21answers
12k views

How would you know if you've written readable and easily maintainable code?

How would one know if the code he has created is easily maintainable and readable? Of course in your point of view (the one who actually wrote the code) your code is readable and maintainable, but we ...
8
votes
5answers
745 views

Is it OK to repeat code for unit tests?

I wrote some sorting algorithms for a class assignment and I also wrote a few tests to make sure the algorithms were implemented correctly. My tests are only like 10 lines long and there are 3 of ...
2
votes
2answers
1k views

Any Code Review tool with direct connection to CVS? [closed]

I've found many Code Review tools: Phabricator (by Facebook) - http://phabricator.org/ Rietveld (by Google) - http://code.google.com/appengine/articles/rietveld.html GitHub - https://github.com/ ...
12
votes
4answers
861 views

How should code “Goal Tending” be handled by a Development Manager?

First allow me to coin a term: code goal-tending: Checking out code in the morning, then silently reviewing all of the changes made by the other developers the previous day file by file, ...
16
votes
4answers
2k views

How large should a Python module be? [closed]

I was browsing a github project and found this module which has more than 10 thousand lines. Is it good practice to have that much code in a single module? Shouldn't this be split over multiple ...
2
votes
4answers
654 views

What code smell best describes this code?

Suppose you have this code in a class: private DataContext _context; public Customer[] GetCustomers() { GetContext(); return _context.Customers.ToArray(); } public Order[] GetOrders() { ...
5
votes
6answers
390 views

How to set up a one-man research in the difference between BDD and Waterfall?

Earlier, I asked a question about how to measure the quality of a project. The outcome of that question was that the quality of the project can be divided into two parts: Internal quality (code ...
5
votes
3answers
255 views

What quality level in the commit history can/should I expect/enforce?

I worked as a lone developer for a long time. During this time, I developed a way of formulating and ordering commit messages: Refactor first, describe exactly the reason for the commit in the ...
4
votes
3answers
1k views

Is it a bad practice to use inline styling with generated code?

If I'm using a technology like Grails. It's really easy to wind up with inline styling. Are there any downsides to auto-generating code with inline styling? Is this considered bad practice? Why?
10
votes
3answers
2k views

What is the pattern name for using method chaining to build an object?

I frequently use a pattern where I using method chaining to setup an object, similar to a Builder or Prototype pattern, but not creating new objects with each method call, instead modifying the ...
4
votes
3answers
1k views

Should a method do one thing and be good at it? [duplicate]

"Extract Till You Drop" is someting I've read in Uncle Bob's blog, meaning that a method should do one thing alone be good at it. What is that one thing? When should you stop extracting methods? ...
13
votes
14answers
2k views

how to find out if spelling mistakes in source code are a serious issue or not?

I find very troubling amount of spelling mistakes I see everyday in our codebase, from which I will reproduce a very short but representative example: ArgumnetCount Timeount Gor message from queue ...
6
votes
5answers
323 views

Splitting 1 large object into 2 tightly-coupled ones - good, bad?

I have a complex object (call it BusinessLogic) which provides an RPC interface to semi-trusted users. The functions in the RPC interface have to decide which procedure to call, check authorisation ...
3
votes
5answers
554 views

What is considered best practice for printing usage / help (--help)?

When writing tools for the CLI of UNIX, how should I make the program print out help and/or usage? I usually use fprintf(stderr, "help text here");, but there are several issues with that. First, ...
-3
votes
4answers
293 views

What are good strategies in C for dealing with pointer errors of this type?

In C, I often come across errors with code like this prio_queue->head[index] = newEntry; Yields a " "Cannot assign Entry** to Entry* " How do you prevent/debug errors of this type, in general? ...
3
votes
2answers
240 views

How to go about bring up the topic of bad programming practices with colleague [duplicate]

Possible Duplicate: How do I approach a coworker about his or her code quality? My development colleague is producing numerous blocks of code which I am a bit concerned doesn't really make ...
2
votes
2answers
197 views

How do you handle minor change in source code causing discontinuity in version tree?

For instance, I have a file with poor indentation (at least incoherant with the rest of the project). If I correct the indentation and commit, there will be a serious change in the file at a certain ...
37
votes
10answers
4k views

How can I quantify the amount of technical debt that exists in a project?

Does anyone know if there is some kind of tool to put a number on technical debt of a code base, as a kind of code metric? If not, is anyone aware of an algorithm or set of heuristics for it? If ...
55
votes
16answers
2k views

Do We Have a Responsiblity to Improve Old Code?

I was looking over some old code that I wrote. It works, but it's not great code. I know more now than I did at the time, so I could improve it. It's not a current project, but it's current, ...
10
votes
6answers
1k views

Need to make my code more readable to the other programers in my team

I am working a project in delphi 7 and I am creating a installer for the application, there are Three main parts. PostgreSQL installation/uninstallation myapplication ( setup of myapplication is ...
20
votes
9answers
2k views

Adding complexity to remove duplicate code

I have several classes that all inherit from a generic base class. The base class contains a collection of several objects of type T. Each child class needs to be able to calculate interpolated ...
1
vote
2answers
1k views

What are the things that you consider in reviewing an iOS source code? [closed]

We're going to do some peer reviews for our iOS projects. We're kind of inexperienced at reviewing each other's codes. The iOS developers attending the reviews will be from other projects, since ...
1
vote
1answer
243 views

How to quantify benefits from a programming training?

I'm conducting a programming training for 3 months. Details in this link - Programming Training Details. My question is "How do we quantify benefits from such training?". I think the two important ...
18
votes
5answers
766 views

Keep it simple now, or program with the future in mind?

I'm currently coding a new application for my company that is rather involved. To meet the deadline, the functionality has been toned down quite a bit so that we can have something ready to go for ...
7
votes
2answers
520 views

Are there any opensource APIs that help analyze code?

As an example, let's say that I need to check for a certain usage of C# code and warn the user that that is a bad pratice. There are multiple usages that I want to detect, such as: Resource not ...
1
vote
5answers
157 views

Automatic sorting of class/module members and its possible impact on productivity and code quality

Recently I saw some possibilities of some IDEs (via plugins) to sort members of their classes/modules based on some criteria, sou you could have everything sorted automaticaly no matter where you ...
37
votes
12answers
4k views

How do I approach a coworker about his or her code quality?

I work on a new venture at a large enterprise software company (3000+ programmers). In my group, we have a bunch of projects and people usually work on several projects over the course of a year. I ...
5
votes
5answers
1k views

Example bad code project to motivate refactoring / good design [closed]

This is sort of the opposite of Is there an open-source project that can be an example of well-written code?. I am teaching software engineering to undergraduates and I would like a blob of object ...
35
votes
11answers
4k views

What does a code review look like? [duplicate]

I'm writing a code review process document for our team; we've never had a formal process in place although we do do some code review. I've found lots of articles talking about how important code ...
7
votes
10answers
1k views

Overcome clumsiness in writing code

I believe this is a little related with this question: How to be a zero-bug programmer?. But I believe this is more regarding clumsiness in programming because I know it is impossible to become a zero ...
26
votes
4answers
18k views

Why is #include <iostream.h> bad?

I was reading another thread where a guy asked about C++ books for beginners, and one of the programmers answering wrote this: Some warnings: avoid all books that present an "hello world" stating ...
8
votes
4answers
183 views

Advice/Approach for distilling homogenous code and building common code for a team

I work for the State of California. Our programming team in my opinion is not really a 'team' in that we usually work solo on projects throughout the application/systems complete life-cycle. The end ...
9
votes
7answers
2k views

Keep my classes and methods as small as possible?

A few days ago, I was talking to a Software Engineering PhD candidate and at some point she said to me: Keep your classes and methods as small as possible And I wonder if this is always a good ...
2
votes
2answers
298 views

SONAR and DesignForExtensionCheck Rule

When enabling SONAR on an in-house Java project, there are a large number of violations being reported due to the rule DesignForExtensionCheck. Whilst I agree with the theory that all classes/methods ...
2
votes
3answers
285 views

in doubt of using code generators

I am now entering the world of java ee 6. And I am supposed to used different technologies like jsf, jpa, different kinds of beans and all that stuff. I am learning using the netbeans IDE, which is, ...
10
votes
3answers
2k views

How can I define and measure simplicity in code?

There are many answers in my previous question about simplicity relating to readability that helped me see my definition and understanding of simplicity in code was, quite possibly, incorrect. How ...
25
votes
15answers
2k views

Does simplicity always improve Readability?

Recently, I was developing a set of coding standards for our company. (We're a new team branching out into a new language for the company.) On my first draft, I set the purpose of our coding ...