views:

379

answers:

6

I have just started to write code in C, C++, Java, ASP.NET, C#, Objective-C, I-Phone, etc.

But I don't understand why i have to spend 20% of my time for fixing bugs.

I just learned those programming languages as they are. Do most programmers face this type of problem?

+4  A: 

Bugs will always crop up and should always be tackled as soon as possible, that way the code is fresh in your mind.

Paul Creasey
+9  A: 

No, most programmers have it worse than 20%.

If you want to get ahead of the game, you'll start writing tests to go along with your code. Google for:

  • test first programming
  • test driven design
  • behavior driven design
Wayne Conrad
+1 but can I suggest dropping the initial "design" from your last point?
j_random_hacker
... and adding it back to the second line where it belongs. Thanks for the catch.
Wayne Conrad
+1 for the sad truth :)
Yar
+16  A: 

You don't necessarily have to spend 20% of your time fixing bugs litteraly, but - yes - most programmers have to face the problem of bug fixing. Hopefully you'll be able to spend less than 20% on your time bug fixing, if you're not careful it might even take more of your time.

No matter how good a programmer you are it is highly likely that you'll introduce a few bugs at some time. If you're diciplined with unit testing you can hopefully avoid bugs best possible. I highly recommend you to look into Test Driven Development (TDD) if you want to do your best for avoiding bugs.

There are several questions about unit testing and TDD on StackOverflow if you need help getting started. Here are a few of them:

stiank81
+1 Couldn't agree more. In fact after we started unit testing and then TDD, I would say we spend about 5% of our time on bugs. No lie.
Walter
Very nice, but I don't like the 'most programmers' and 'highly likely' talk. **Every** programmer spends time bug-fixing. You **will** introduce bugs.
abyx
@abyx: You're absolutely right! But if I said that every programmer will introduce bugs I'm sure someone would claim that they don't - even though they certainly do..
stiank81
@stiank81, and you need to cater to them? It's a safe and provably true generalization by virtue of the fact that people learn through trial and error regardless of what they say, it just takes a different form than what they envision "trial and error" to mean.
Geoff
+4  A: 

For example you are able to write, but in your post there are some "bugs": no space after comma, space before comma, no space after dot, "Programmers" is not a name of someone, so it's better "programmers". Now you can use 20% of your time to fix them.

wiso
You are really right....
Hiren Gujarati
A: 

Fixing bugs is a part of programming, whether you like it or not, it'll always be there.

It's been there for as long as programming has been around and it'll be there until we program no more.

It's so common you can find it in many of the the common programming jokes.

And like Wayne, most people spend a lot more than 20% of their time on debugging.

Personally, I think debugging is what makes programming fun, not because it's fun per se, but because it takes you so long to fix and once you've fixed it you get this overwhelming feeling so "WOOHOO! I did it!"

Again, I agree with Wayne on trying those techniques for programming, however, they take all the fun away from programming.

One thing I found useful when debugging is to take a break and then come back to your code after a few minutes, preferably after a short conversation with a friend or a phone call, you'll be amazed at how fast you can spot bugs, the hardest part is getting the will to stop programming and taking a break.

Leo Jweda
@Laith, if by "fun" you mean "getting woken up at 2am by the shift supervisor because a bug has popped up in production," then yeah, it eliminates some (not all) of that enjoyable activity. There are still plenty of puzzles to solve, though. You just solve them while you're writing the code the first time instead of at 3am. Usually.
Wayne Conrad
@Wayne: Aren't you up programing at 2 AM? For shame! ;)
Leo Jweda
@Laith, Shhhh. I don't want them to take away my "programmer" title just because I'm getting some shut-eye.
Wayne Conrad
@Wayne: Yeah, let's just keep this our dirty little secret.
Leo Jweda
A: 

It's kind of an odd question. If I may take the liberty to rephrase it...

Why am I spending so much time fixing my own mistakes?

Focus your energy on not making them in the first place. There are many things you can do to minimize mistakes:

  • Be clear ahead of time what the inputs, outputs, and side effects of your methods are.
  • Break down your problem into small, easy-to-write functions and methods.
  • Write lots of tests.
  • Write testable methods.
  • Proofread your code before you hit that compile/run button.
  • Have someone else proofread.

As you gain experience, you'll find that the easy mistakes become less frequent and the hard ones (usually resulting from poor design or unknown behaviors in libraries) start consuming more of your time.

Barry Brown