• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cattle Drive Assignments

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!



 
Ranch Hand
Posts: 63
Firefox Browser Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Appreciate it Katrina! Thank you for the much valued suggestions you have made through the quotes!

Thanks once again.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic