• Post Reply Bookmark Topic Watch Topic
  • New Topic

5 days of frustration and errors? How to troubleshoot any java project?  RSS feed

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am somewhat past the beginner stage. But, I have always faced this problem of "mysterious error messages" which often make me waste 2 hours to 5 days. Besides killing productivity, it is a major blow to the ego when it lasts for a week.
Can someone suggest any books or ways to make myself capable of -

1- looking at any java error (core java, framework, google api, anything...) and tracing the sequence of events that lead to the errors.
2- getting rid of such errors quickly

 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john carmack wrote:I am somewhat past the beginner stage. But, I have always faced this problem of "mysterious error messages" which often make me waste 2 hours to 5 days. Besides killing productivity, it is a major blow to the ego when it lasts for a week.
Can someone suggest any books or ways to make myself capable of -
1- looking at any java error (core java, framework, google api, anything...) and tracing the sequence of events that lead to the errors.
2- getting rid of such errors quickly

#2 is easy:
Get a good book on defensive programming techniques and learn it. Prevention is far better than cure.
Although it's not specifically on that subject, Effective Java is as good as any book I know for helping you avoid "error message hell". It also describes some good techniques for aiding the debugging process (such as 'fail fast', and 'provide good messages').

#1 - I doubt whether there is a catch-all answer, particularly when 3rd-party frameworks such as Struts or Hibernate are concerned, because very often you won't have the source code to backtrack the stacktrace with. Unfortunately, a lot of the time, it comes down to familiarity with the product.

Winston
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john carmack wrote:any books or ways to make myself capable of -

1- looking at any java error (core java, framework, google api, anything...) and tracing the sequence of events that lead to the errors.
2- getting rid of such errors quickly


There is a way...

Your mission, should you choose to accept it, is to find the book "Growing Object-Oriented Software, Guided by Tests" and learn how to do Test-Driven Development.

3-Minute Primer on TDD
Test-Driven Development follows this cycle (more or less):
1. Write a small unit test
2. Run your test to see it fail; a compilation error is a failure
3. Write only enough production code to make your test pass
4. Run your test(s) again to verify that it passes
5. Clean up the code (by eliminating duplication, bad names, unclear sections, etc.)
6. Run your test(s) again to make sure you didn't break anything
7. Repeat the process until you can't think of any more tests

Each cycle (steps 1-6) must be completed within the span of no more than a few minutes. Ok, if you're a beginner, try to get it done in 5 to 10 minutes per cycle. Word going around in certain circles is that masters of TDD can complete each cycle in 30 seconds or less, on average.

The shorter the cycle time, the less chances are of writing code that has errors. If you do get an error, then you know it's something that you wrote in the last [Beginner: 5 to 10 minutes; Master: 30 seconds] since you last saw all your tests pass. Debugging becomes repeatedly pressing the "Undo Typing" control sequence in your text editor (usually, CTRL-Z) until you can get your tests to pass again.

Think about it: Just how much buggy code can you write, without running tests to check if you have any errors, in 5 to 10 minutes? In 1 minute? In 30 seconds? Now, how much buggy code can you write, without running tests to check if you have any errors, in an hour? In a day? In five days? See the trend now? Which way will give you a better chance of finding mistakes you made? Which way will help you minimize the number of mistakes you have piled on to one another?

Important Note: Your unit tests MUST be automated and in each cycle, you must run all the tests you have written so far. Unit testing frameworks like JUnit are recommended for Java developers.

3 Rules/Laws of TDD
(Source: http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd)
1. You are not allowed to write any production code unless it is to make a failing unit test pass.
2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.

Yes, it may seem like a totally ridiculous way to program but it's how some of the best of the best developers do it. I don't see how it can't be good enough for the rest of us.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!