Question

When fixing defects in new code what are the best strategies to use? cause as I figured out defect-fixing improves my coding standards and my understanding about that language and technology. I want to optimize thing gaining.

Was it helpful?

Solution

TDD says that first you should implement test(s) that reproduce the problem. Then fix the bug and run tests again. If all tests pass you are done. Otherwise continue fixing.

OTHER TIPS

The question is too general, and the only thing I can state is that before fixing something you should make sure you have tests.

I think when you are starting out its important to learn to keep small segments of your code as independent as possible. Then you can easily test that each function and each object behaves like it should finding the flaws as you go. Commenting out problem sections to isolate where the issue is; is important to learn. Then start learning about unit testing. Which is a fancy way of commenting out problem code = )

After having unit tests with good code converage, I would suggest you look at running a static code analysis and run a decent portion of your code in a profiler to see if it is busy in the areas of cod eyou expect (and creates the sort of objects you expect)

Be proactive in setting things up so that the detection and fixing of defects is made easier. As with most things in life, if you apply discipline before you encounter issues you find dealing with those issues much easier.

  1. Write your unit test first: Some people find this bewildering but it really works. This is very useful in identifying corner cases, non-obvious issues BEFORE you implement the code. Obviously you'll have to have some sort of skeleton for your code but I find that I have that at least in my head before starting.
  2. Write the code: use the unit test to verify the code stepwise.

With this in place you can run the unit test with the appropriate data to reproduce the bug and then you fix the bug using the unit test to decide when the bug is fixed.

Update your unit test to cover this defect.

I use below steps to fix a bug:

Step 1. Identify the bug.

Ask for screenshots from reporter of the bug. Try to reproduce the bug in given scenario.

Step 2. Analyze the error

Capture the logs and try to analyse it carefully.

Step 3. Discuss your findings with the team

Look for the expected behavior and discuss this with the tester and verify your potential solution.

Step 4. Cover lateral damage.

Try to look if your potential fix will cause some other bug in the system.

Step 5. Fix the error.

Fix the error!

Step 7. Validate the solution.

Run all the test scripts and check that they all pass. If they fail correct them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top