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 regarding Assignment 4b

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just received my nitpick for assignment 4b. One of the things that was mentioned was that I should consider printing the number as I go along... rather than what I had been doing, which was saving the number in a String variable.

But I did this for 2 reasons:
1. I thought that just working with a variable, and printing the number once, would be much more efficient than sending several print statements thoughout the processing. Am I wrong?
2. By using a variable, I could determine when/where I should place a comma separating some of the words (i.e. if there's already text in the variable, and I want to add more text, add a comma first).

So, can somebody tell me why it makes more sense to print the number as you go along?

Scott
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Scott, I'm going to be lazy and give you a link to a couple conversations that we had on this a while ago. Fun discussions... to concatenate or not to concatenate
 
Scott Rumrill
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pauline. That was an extremely informative discussion.

That addresses reason number 1 above, but not reason number 2. Is there a recommeded way to deal with determining if you've already printed something (for the purposes of printing the comma)? or do you not care about commas in Assignment 4b?

I guess I could create another variable (probably boolean) which would indicate if anything has been printed. Is that the way to do it?

Scott
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The short and easy-way-out answer: strictly speaking, commas aren't really required. But you can work them in if you want to.

When I did the search for the concat discussion I came across a couple other old chats about the comma too. I've only got a minute now, so I can't go get them, but maybe you can come up with them. A search using "comma" and "say" should do the trick.

Enjoy And let us know what you come up with.

ciao,
Pauline
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic