The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

roodhu001 (4) [Avatar] Offline
#1
Listing 1.1 could be expressed more concise and elegant like this:

base = 1
next = 1
10.times {
  print base + ' '
  next = next + base
  base = next - base
}
println ''
Mittie (397) [Avatar] Offline
#2
Re: Listing 1.1 could be improved
Hi,

well, I don't see this as an 'improvement'. It is just a different style, which is one line shorter but not necessarily easier to understand since the reader has to infer that the 'base' is set to the value that 'next' had when entering the closure. This is more obvious in the book version. One can regards this as the result of the refactoring"introduce explaining variable".

thanks for posting
Dierk
roodhu001 (4) [Avatar] Offline
#3
Re: Listing 1.1 could be improved
Hi,

Thanks for your answer. I understand what you say, and I agree.
Also thanks for this great book. I enjoy reading it.
Mittie (397) [Avatar] Offline
#4
Re: Listing 1.1 could be improved
thanks for your kind words!

keep groovin'
Dierk