AndyJu76 / go-tour

Automatically exported from code.google.com/p/go-tour
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Slide 15 of Tour (Type conversions) correction #170

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
http://tour.golang.org/#15 encourages the learner to remove the "float64" 
conversion from line 10:

    var f float64 = math.Sqrt(float64(3*3 + 4*4))

Removing it does nothing (it still compiles), as the constants are untyped. The 
concept of untyped constants is introduced after this in #17, and line 9 
declares x and y as 3 and 4, so I think we should have:

    var f float64 = math.Sqrt(float64(x*x + y*y))

Then removing the conversion has the right effect; people will see that Go 
requires you to be explicit when converting:

prog.go:10: cannot use x * x + y * y (type int) as type float64 in function 
argument

Original issue reported on code.google.com by p...@google.com on 9 Mar 2014 at 9:18