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