This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Firstly, I have not registered for nitpicking yet and just trying the assignments on my own as m new to Java. Just finished with Head First book. I have a small but may be a silly question regarding Assignment 5. I get the output as desired with 2 individual loops and 1 nested loop and is 40 lines long. But I see the Instructor's solution is only 28 lines long. Does that mean I am doing something wrong?In the other assignments(1-4) my solutions are smaller than the instructors'. Does that make any difference.
You'll find that the instructor's solutions are geared to accomplish a task with the least effort for the computer processor - at least this was my take on the nitpicking that I received. So you'll find that your tightly compact elegant solutions need to have a bit more code to make life a little easier for the processor. And at other times when you have way too much code, you'll find that there is a better way of solving the problem all together.
So - in my case - the nitpicking didn't explicit state preferred practices. However, the nitpickers' nudging of my code seemed to imply that there were cases where I wasn't following "good coding" practices.
Joined: Jun 06, 2011
Thanks Richard! I think I agree with you..instructor's solution might be more compact and fast in assignments where i have more lines of code.
I would say that the instructor's solution is geared towards readability, but that in some cases this coincides with code that is more efficient.
To quote Martin Fowler: "Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
We encourage readability first, and when you have reached a solution that is clear and easy to understand, then (and only then) would you optimize for performance, and then only if necessary.
To quote Donald Knuth: "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
There are times when obvious optimizations would be silly to ignore. We tend to point those out
Joined: Jun 06, 2011
Appreciate it Katrina! Thank you for the much valued suggestions you have made through the quotes!