• 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

Assignment 1a - Mixed signals

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first post so go easy on me. I'm mainly a COBOL programmer, but I have done some OOP in SQLWindows yuk. I want/need to learn Java because the University I work for is moving slowly, very slowly, in that direction and I want to get a head start. I have taken beginning and advanced C++ classes, but I have no real-life experience with it. I have also done some VB 6 coding, but not for hire. That said, I am a little confused about the nick picking I got over the first assignment.
In my code I used:
System.out.print( args[0] + " ") ;
and was nitpicked becuase I was dereferencing the array and concatenating the space 100 times. Though I will admit I didn't think about the derefernecing and cacatenation issue, I was under the impression to make the code as simple as possible. No biggy, just seems like I got nitpicked for the sake of nitpicking.
Also, before I signed onto the ranch for the abuse I perused the site and I remmeber a link to a post with a reply from Paul Wheaton concerning the Style Guide. In the post the person had given his opinion on several issue regarding the Style Guide and Paul had given an indepth reponse to each issue rased. Could someone tell me where I can find that link/post. I thought it was in the common mistake link on Assignment 1, but I didn't see it there.
One last thing, before a person attempts getting Java certified how much of the Cattle Drive should they complete?
richard.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"I was under the impression to make the code as simple as possible."
Simplicity and readability are the key. You don't need to lose them by moving the array dereferences and string concatenations outside of the loop.

"a link to a post with a reply from Paul Wheaton concerning the Style Guide."

Actually there are quite a few of these. There is a search facility somewhat inconspicuously located at the top of each forum page. Type in "style" and see how many links come up.

 
Richard Boren
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marilyn,
I agree that simplicity and readability are not given up by moving the dereferencing and concatenation out side the loop, it just seems more like a performance issue to me. I know, I know performance is important too.
Thanks for the search idea.
richard.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, firstly, they don't call it nitpicking for nothing. I did something similar to you for the first assignment, and was nitpicked for doing 100 concatenations.
I really thought that the way I did it was clearer and more/better object oriented than the accepted solution. (Sorry for the vagueness. If you've done the assignment, you know what I'm talking about.)
The path that I have decided to take with the Cattle Drive is to assume that I'm doing a large program/project and not these little programs.
 
Richard Boren
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the assignments as a major projects sounds like solid advice, though I suspect it'll take me a few assignment to get the hange of it. Thanks Bruce.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I first started doing these projects, I also looked at them as large programs and tried to make them more OO. But for the first group of assignments I don't think that is the case now. The first group of assignments are there so you can see some of the basic constructs and get the style guide down. Most of them can be down entirely within the main method and I think you are supposed to treat them as separate assignments and not part of a package.
Some of the goals are to make the code as simple and readable as possible and still have them highly optimized. That is why doing a string concatentation inside of a for loop is not as good as the instructor's solution. Doing it outside of the for loop doesn't lose any readability, and it does make it more efficient.
Bill
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an old post that perhaps merits repeating occasionally:
IMHO, writing optimized code is a good state of mind to be in all the time. You don't always know when you are writing a specific section whether it will later prove to be processing-intensive or not. Why would you want to write less-optimized code on the assumption that it won't matter, when it only takes a few more keystrokes to write better code?
In my early days as a greenhorn doing the Cattle Drive assignments, I felt myself resisting the advice that came with nitpicking. I thought my own years of programming experience should count for something. I finally came to realize that it was all meant to help me be a better Java programmer, and that if I spent my energies in employing the suggested styles and techniques instead of trying to prove why my way was just as good, I came out way ahead.
 
Richard Boren
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>>IMHO, writing optimized code is a good state of mind to be in all the time.
This is true; however, it is hard to know/understand what is optimazed code when you are just beginning to learn a language. Just keep nugging. I'll try not to whinny too much.
The reason I made this post "mixed signals" was; it appears alot of effort was made in the "About the Cattle Drive" explaining that the first few assignments are for getting your feet wet. To me that meant lets learn how the Java Ranch works and do a simple program first, not optimize Hello World. I felt like the nitpicking needed to be more inline with the "About the Cattle Drive". I guess I learned how the Java Ranch works plus some.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard, I don't think you need to feel you are whinning, I think you bring up good points.
Let me offer my reasoning however why I think it should be optimized from the beginning. I feel that learning to optimize your code from day one helps you learn the language even more and it also gets you in the pattern of trying to have the best solution the first time around. These are very important when you are writing code.
For example, lets say you had to write a Hello World program. If someone wrote this:

This would work, but it is way to complicated and verbose for what is needed. Wouldn't you suggest to the person to optimize there code and just print "Hello World"? I know that this is a pretty contrived example, but you see where I am going.
Instilling into a new programmer to write clean and optimized code is a big help IMHO. Many programmer write overly complicated, verbose and spaghetti code, which they probably learned when they were just beginning. At least for me, I know my code looks much better than it did when someone wasn't there saying "What are you doing, why not just do this?"
Just my opinion,
Bill
 
Richard Boren
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
Okay. Okay. I have to agree with you. Code is often written more complicated and encrypted than need be and not as efficent as could be. Probably because the programmer wasn't taught correctly to begin with.
This is a really well thought out site. I have paid $$$ for programming classes that gave little to no direction, let alone any real constructive feedback. Those classes create sluggers not boxers. Anybody can slug, you have to be trained to box. It looks like this site aims to train not please.

P.S. After rereading my reply prior to this one, I feel my comments may have come across more hard nosed than I intended
 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a great service. Its not often you find something SO helpful and so easy to access. I would have thought something like this could only have been reserved for a private Java class of some sort. I could get nit-picked to death and ill never complain, as its for my own good.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I may have an advantage as I've no previous programming experience. Instead of complaining about optimization I think you should be thankful someone is taking the time to nitpick. It will make you a better coder and make it easier to modify and read when someone shows up a year from now. It should instill a very good habit and I definately appreciate it. I got the same nitpick on my code and if you do it right every time here you always will elsewhere.
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying to learn java since August. Along with learning the syntax of Java I have learned a very important point. Knowing the syntax of a programming language does not make someone a programmer. The cattle drive seems to be a great tool for turning an ability to write code into an ability to program. I turned in my first assignment Friday night and can't wait to see the nitpicking, because I know that learning from that will help me be a truly professional programmer.
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic