JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Especially in these early assignments I usually prefer print as you go because of the simplicity. If you are going to concat a bunch of Strings and just print them to the console at the end, it's simpler.
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Originally posted by Scott Rumrill:
Will we be learning more optimization techniques during the rest of the Cattle Drive?
My question is this: How do I know which is more/less optimized?:
- doing 100 string concatenations, OR
- printing output 100 times
Every time you concat two strings, you create about 4 objects. Object creation is expensive.
If you think of it on a larger scale, like the overall development and maintenance process, then improving readability just might help performance where it costs the most: when the next programmer, maybe someone with less experience than you, has to maintain your code - if it's not readable, then
Check out my kickstarter CLICK HERE
My book, my movies, my videos, my podcasts, my events ... the big collection of paul wheaton stuff!
In this case, which is faster may be debatable. But one thing is for certain, using String for 100 string concatenations (most people try 200 on their first try) is a bad habit to get into.
As a contractor, I get the stinky jobs that nobody else wants to do. A year ago I was in San Diego and inherited such a beast. Nobody wanted to mess with it. In the end I eliminated 99% of the known bugs, reduced the code size by a factor of four and doubled the functionality. Of course, any of these people could read the code. It was just a mess and would take more time. All I did was clean it up. Make it do the same thing, but in a more readable way. My focus was on readability.
Check out my kickstarter CLICK HERE
My book, my movies, my videos, my podcasts, my events ... the big collection of paul wheaton stuff!
Originally posted by Joyce Lee:
On the other hand, though choice B has two additional lines, it doesn't forgo the readability
Check out my kickstarter CLICK HERE
My book, my movies, my videos, my podcasts, my events ... the big collection of paul wheaton stuff!
Check out my kickstarter CLICK HERE
My book, my movies, my videos, my podcasts, my events ... the big collection of paul wheaton stuff!