This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Question about 4a

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could someone explain how the second part of line 41 (ignoring comments) of the instructors solution works.
Thanks
 
hired gun
Posts: 250
MS IE Oracle Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove the second part and then try running the program with a negative number.
java say -4
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah I understand that it checks for that but I can't see how it works.. I mean I just checked an int but I am assuming that since this way is in the instructors version it is better?
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amy Phillips:
...but I am assuming that since this way is in the instructors version it is better?


Wow, that's a loaded question if I have ever heard one. I'd like to state that the following is my own opinion and does not reflect yada yada yada...
Personally, I wouldn't do it the way the instructor does, and I don't think I did it that way on my passing assigment. I'll try to state this without giving too much away, but the instructor approaches the handling of the input in the form it is received. I, on the other hand, like to deal with the input in the form that the input represents. Several other students do it this way, also.
So is one better? I don't think so, they're just different approaches. You're not gaining any remarkable processing improvement, and readability isn't necessarily improved by doing it the same way as the solution. Nor do you gain any real benefit from doing it the "other" way.
You aren't the first one to ask about it, and that isn't a reflection that the instructor's way is worse, either. It's just different than what some people would do, and it takes a look or two before realizing what is actually happening.
Just like in any task where you ask two programmers to solve the same problem, very rarely would the two solutions come out the same. As long as both are optimized for effeciency and readability, one can't be considered better than the other (unless you ask the programmers themselves, who are notorious for thinking their code is the best ).
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Jason (and my views don't represent yada yada, more likely nada nada. )

Piling on more opinion...
I think that once I got over trying to come up with something exactly like the instructor's solution (didn't take long!), seeing different approaches in the instructor's solutions was like a cool added bonus to finishing each assignment. Another advantage of the Cattle Drive approach - you get to come up with *a* right answer, and then see another approach or other smaller variations. More tricks added to your toolbox as it were.
[ June 03, 2003: Message edited by: Pauline McNamara ]
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah I think thats the best thing about the Cattle Drive its not just about getting something working I have quickly realised that there is lots more to it than that.
Still I have learn some very nice little tricks from the Instructors Versions but I just couldn't see it with this bit.
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My memory is *really* fuzzy on this assignment and the instructor's solutions, but one thing I *think* I remember (I apologize in advance if I'm leading anyone astray) is that the seeing the instructor's solution for 4a helped me decide whether to treat "0" (zero) as a special case when coding 4b.
(I'll have to check this memory out later when I get home.)
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah it was treated as special but again I couldn't really see why, I presume its because there is no point running all the other code if its just 0 but why is it different with 1, 2, 3 etc??
Hang on i think I might have got it - there must be some problem with not doing it like this in 4b?? Am I right?
[ June 03, 2003: Message edited by: Amy Phillips ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you look at that class's API and see what that method returns?
[ June 03, 2003: Message edited by: Marilyn de Queiroz ]
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh I see! I got confused with the -1 part but having re-read the documentation 3 times its come together
Thanks
 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you just love those moments when you see the light at the end of the tunnel and you know it
isn't an oncoming train?
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah its the best part! I am hoping to have one of those moments with 4b but so far its been slow in coming...
reply
    Bookmark Topic Watch Topic
  • New Topic