Questions tagged [code-quality]

Questions for best practices for writing high quality code.

653 questions
278
votes
25 answers

How do you know you're writing good code?

I love programming. I've been messing around with code since I was a kid. I never went the professional route, but I have coded several in-house applications for various employers, including a project I got roped into where I built an internal…
Jim
  • 1,997
167
votes
28 answers

How to be a zero-bug programmer?

My boss has always told me that a good programmer should be able to ensure that the code he or she changes is reliable, correct, and thoroughly self-verified; that you should completely understand all the results and impacts your changes will cause.…
Elaine
  • 261
140
votes
10 answers

On developing deep programming knowledge

Occasionally I see questions about edge cases and other weirdness on Stack Overflow that are easily answered by the likes of Jon Skeet and Eric Lippert, demonstrating a deep knowledge of the language and its many intricacies, like this one: You…
Robert Harvey
  • 199,517
79
votes
6 answers

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 working & moved on. But later on, I started to wonder if…
user53019
69
votes
22 answers

How do you define elegant code?

Possible Duplicate: What does it mean to write “good code”? In a discussion on coding quality, and how you identify it, I came across a discussion on testing people's coding ability by getting them to show how they would swap two values using a…
temptar
  • 2,756
69
votes
4 answers

Most human-friendly way to order class method definitions?

In any given class definition, I've seen the method definitions ordered in various ways: alphabetical, chronological based on most common usage, alphabetical grouped by visibility, alphabetical with getters and setters grouped together, etc. When I…
Johntron
  • 1,008
59
votes
12 answers

Is it common to have to iterate on a design due to overlooking problems with it?

When I'm designing a system for a program, I often make misjudgements that will prevent the design from either working, being maintainable, easy to use or all the above. This means I will usually have to iterate several times, refactoring my code…
40
votes
13 answers

What does it mean to write "good code"?

In this question I asked whether being a bad writer hinders you from writing good code. Many of the answers started of with "it depends on what you mean by good code". It appears that the term "good code" and "bad code" are very subjective. Since I…
gablin
  • 17,407
25
votes
10 answers

Dealing with a developer continuously ignoring edge cases in his work

I have an interesting, fairly common I guess, issue with one of the developers in my team. The guy is a great developer, work fast and productive, produces fairly good quality code and all. Good engineer. But there is a problem with him - very often…
Alex N.
  • 569
14
votes
10 answers

Do ALL your variables need to be declared private?

Possible Duplicate: Why do we need private variables? I know that it's best practice to stay safe, and that we should always prevent others from directly accessing a class' properties. I hear this all the time from university professors, and I…
Sal Rahman
  • 1,544
13
votes
11 answers

What should I do when my code smells?

I'm a novice programmer and often when I'm working on my own projects, I always get the feeling that the design of my code is not the best it could be, and I hate this feeling. I end up spending time looking things up, but then I become overwhelmed…
Chris Bui
  • 241
13
votes
3 answers

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 can I define simplicity in code? What software…
Richard
  • 1,739
  • 15
  • 18
11
votes
5 answers

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 for me. But when it comes down to levelization and…
ollifant
  • 241
10
votes
5 answers

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 make a little more sense, but often variable is a…
TruthOf42
  • 762
8
votes
6 answers

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

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 into the mainline. Now, I don't have a problem…
Desolate Planet
  • 6,058
  • 3
  • 30
  • 38
1
2