Questions for best practices for writing high quality code.

learn more… | top users | synonyms

12
votes
7answers
1k 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?
12
votes
7answers
605 views

Where do you draw the line between quantity and quality? [duplicate]

My manager has talked with me and says that the quality of my work is excellent, but I need to step up the quantity of how much I crank out. I've only been working for a couple of years, so I still ...
12
votes
5answers
595 views

Do high standards necessarily lead to frustration, and how to deal with it?

I consider myself a programming language enthusiast. When I find bad code, especially my own, it is hard to understand, hard to change, and hard to test. My coworkers don't know better, or don't care....
12
votes
3answers
3k 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 ...
12
votes
4answers
5k views

Good use of try catch-blocks?

I always find myself wrestling with this... trying to find the right balance between try/catching and the code not becoming this obscene mess of tabs, brackets, and exceptions being thrown back up ...
11
votes
10answers
1k views

Does code generation increase the code quality?

Arguing for code generation, I am looking for some examples of ways in which it increases code quality. To clarify what I mean by code generation, I can talk only about a project of mine: We use XML ...
11
votes
9answers
1k views

Should a programmer take writing lessons to enhance code expressiveness?

Given that programmers are authors and write code to express abstract thoughts and concepts, and good code should be read by other programmers without difficulties and misunderstandings, should a ...
11
votes
7answers
4k 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 ...
11
votes
3answers
254 views

Do I need to deal with the situation where private methods are called through reflection?

When creating a library, must I ensure that the private methods must work as expected when called not by other methods of the same class, but by another library through reflection? For example, if a ...
11
votes
3answers
2k 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 ...
11
votes
3answers
2k views

How to write manageable code with functional programming?

I just started with functional programming (with JavaScript and Node.js) and from the look of things it looks as if the code I am writing would grow to be one hell of a code base to manage, when ...
10
votes
15answers
1k views

Are software developers who ignore quality/standards better for the company? [closed]

Do software developers who choose not to put code optimization, standards and best practices as top priority, create more useful code than those developers who choose to worry about optimization, ...
10
votes
7answers
3k views

Is it beneficial to read old Java programming books? [closed]

Many of my Java books are 5 - 10 years old. Does it still help to read them, or should I use something within 2 years.
10
votes
6answers
1k views

Which is more maintainable — boolean assignment via if/else or boolean expression?

Which would be considered more maintainable? if (a == b) c = true; else c = false; or c = (a == b); I've tried looking in Code Complete, but can't find an answer. I think the first is more ...
10
votes
5answers
555 views

Methods for testing a very large application

I have a PHP app which is very large. There are usually 2-3 developers working on it full time and we are getting to the point where we are making changes and creating bugs (cough features!). The ...
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 and I am creating a installer for the application, there are Three main parts. PostgreSQL installation/uninstallation myapplication ( setup of myapplication is ...
10
votes
5answers
1k views

How to handle flag in multiple if-else's

I seem to see this often enough in my code and others. There's nothing about it that seems horribly wrong, but it annoys me as it looks like it can be done better. I suppose a case statement, might ...
10
votes
5answers
798 views

Is adhering to one assert per test foolish consistency in this case?

I have a class that I'm testing. The class has a function: apply(List<IRule> rules, List<ITarget> targets); In one test I want to ensure that each target has been passed to one rule, a la:...
10
votes
5answers
9k views

Why have a method that returns a bool/int and has the actual object as an output parameter?

I see the following code pattern all over the place in my company's codebase (.NET 3.5 application): bool Foo(int barID, out Baz bazObject) { try { // do stuff bazObject ...
10
votes
7answers
555 views

How do I go from being able to write code to being a good developer?

I'm frustrated by the lack of concrete explanations on how to go from being able to script (bash, awk) and write simple applications (c, php, python) to designing and developing larger, more ...
10
votes
9answers
310 views

What mistakes in managing software products must be avoided to keep people from hating the vendor?

A previous question about why people hate Microsoft was closed. This is an attempt at a somewhat more constructive question along the same general line. This one is both broader and narrower though. ...
10
votes
2answers
723 views

How to deal with too much pragmatism in the project? [duplicate]

My team and I took over a medium sized codebase over a year ago when the previous tech lead left the company. Originating from the lack of man power I fear we favored pragmatic solutions over best ...
10
votes
5answers
4k views

How strictly do you follow the “No Dependency Cycle” rule (NDepend)

A bit of background: As a team lead I use NDepend about once a week to check for the quality of our code. Especially the test-coverage, lines of code and cyclomatic complexity metrics are invaluable ...
10
votes
4answers
3k views

How should I test my TEST code?

One of the few things that most software developers agree on is that you shouldn't rely on code to work correctly unless you test it. If you don't test it, it may have hidden bugs that are only ...
10
votes
4answers
341 views

Should I insist that we perform code reviews before merging back to trunk?

Requested re-post from StackOverflow: I'm working in a small development time with very limited time for development. We develop a tool that is important for the result of our work, but not used ...
9
votes
14answers
1k views

How do I (tactfully) tell my project manager or lead developer that the project's codebase needs serious work?

I just joined a (relatively) small development team that's been working on a project for several months, if not a year. As with most developer joining a project, I spent my first couple of days ...
9
votes
7answers
4k views

What is beautiful code in C++, and why do most programmers care that much?

As most projects use a C++ API, they deal with constraints of the API and constraints of the project itself. I'm a beginner at programming, I don't like to use OOP at all because nobody clearly ...
9
votes
8answers
2k views

Copy-and-Pasted Test Code: How Bad is This?

My current job is mostly writing GUI test code for various applications that we work on. However, I find that I tend to copy and paste a lot of code within tests. The reason for this is that the areas ...
9
votes
5answers
2k 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 ...
9
votes
7answers
987 views

Entry level engineer question regarding memory management

It has been a few months since I started my position as an entry level software developer. Now that I am past some learning curves (e.g. the language, jargon, syntax of VB and C#) I'm starting to ...
9
votes
5answers
1k 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 ...
9
votes
5answers
1k views

Is code duplication a necessary evil in C?

I'm rather new to C, and I'm wondering if code duplication is a necessary evil when it comes to writing common data structures and C in general? I could try to write a generic implementation for a ...
9
votes
7answers
8k 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 ...
9
votes
2answers
2k views

What does Uncle Bob mean by 'noun phrase names'?

I am reading Clean Code by Uncle Bob. Because I am not a native-English speaker, I couldn't understand following statement: Classes and objects should have noun or noun phrase names like ...
9
votes
8answers
793 views

How to balance code quality vs strong developer personalities

On code reviews at work I have been seeing code & patterns that I consider "clever" though not necessarily adding to the overall quality or maintainability of the code base. I point this out on my ...
9
votes
6answers
900 views

If you learned formal methods for software, how useful have you found it?

If you have been trained in the use of formal methods (FM) for programming: How useful have you found it? What did your FM training involve (e.g. a course, a book)? What FM tools do you use? ...
9
votes
4answers
3k views

In MVC is it considered good practice to have private, non-action, functions in a controller class?

Sometimes action functions in the controller class can become huge and nasty, with many-many lines of code to simply control the flow of data from the Model to the View. At some point these huge ...
9
votes
1answer
3k 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 ...
9
votes
5answers
435 views

When developing on an old code base, should I use Best Practices or go for Consistency [duplicate]

Possible Duplicate: Code maintenance: keeping a bad pattern when extending new code for being consistent, or not ? As my experience in programming increases with each project, I look back at ...
9
votes
2answers
3k views

How is technical debt best measured? What metric(s) are most useful? [duplicate]

Possible Duplicate: How can I quantify the amount of technical debt that exists in a project? If I wanted to help a customer understand the degree of technical debt in his application, what ...
9
votes
1answer
414 views

Are there any empirical studies about the effects of commenting source code on software quality, maintainability and developer productivity? [closed]

I am an advocate of commenting on source code and documenting software products. It is my personal experience and observation that working on source code that is rigorously commented has helped me in ...
9
votes
2answers
905 views

Unit Testing: “It's a code smell if you're refactoring and there are no collaborators”?

I'm reading The Art of Unit Testing by Roy Osherove. I'm at section 7.2 Writing maintainable tests where the author has this note about code smell: NOTE: When you refactor internal state to be ...
8
votes
6answers
2k views

How to implement a property on class A which refers to a property of a child object of class A

We have this code which, when simplified, looks like this: public class Room { public Client Client { get; set; } public long ClientId { get { return Client ==...
8
votes
6answers
1k views

Are there any benefits to checking in commented out code into version control? [duplicate]

I've found, what I personally believe to be a bad habit that a lot of developers seem to have adopted. Code in various places in the applications I have seen are commented out (lots of it) and checked ...
8
votes
6answers
8k views

What's the benefit of having a private repository for personal projects?

So I just created my first GitHub repository and started to wonder if there would be any reason why somebody shouldn't post their code. I don't mean the obvious, such as code that is IP of somebody ...
8
votes
6answers
2k views

Warranty or guarantee clause for code breaking

Should I guarantee or add a warranty clause to my contract in the event code breaks or an anomaly occurs outside the client's hand or act of God? If so, what should that language say?
8
votes
3answers
1k 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 ...
8
votes
6answers
1k 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 ...
8
votes
6answers
2k views

How to evaluate code quality when you're not familiar with the language? [closed]

As a hypothetical, if I were to interview someone for a new PHP developer position when my experience is in .NET, how can I determine if the code sample they've provided me is efficient and of good ...
8
votes
6answers
727 views

How to write good code with new stuff? [closed]

I always try to write easily readable code that is well structured. I face a particular problem when I am messing around with something new. I keep changing the code, structure and so many other ...