aspose file tools*
The moose likes Cattle Drive and the fly likes Cattle Drive Assignments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Cattle Drive Assignments " Watch "Cattle Drive Assignments " New topic
Author

Cattle Drive Assignments

Deepali Kohli
Greenhorn

Joined: Jun 06, 2011
Posts: 13
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.

Thanks and Regards!



Richard Broersma
Ranch Hand

Joined: Apr 28, 2009
Posts: 63

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.
Deepali Kohli
Greenhorn

Joined: Jun 06, 2011
Posts: 13
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.
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
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
Deepali Kohli
Greenhorn

Joined: Jun 06, 2011
Posts: 13
Appreciate it Katrina! Thank you for the much valued suggestions you have made through the quotes!

Thanks once again.
 
 
subject: Cattle Drive Assignments