DEV Community

Discussion on: Learn Go by writing tests: Structs, methods, interfaces & table driven tests

Collapse
 
hrishin profile image
Hrishikesh Shinde • Edited

Thank you so much for this tutorial.

Just wondering type system of go (would like to understand more). For example, passing integer value to float type just works. What is the intent of such kind of flexibility?

Collapse
 
quii profile image
Chris James

Glad it's helpful!

I hope this will help: play.golang.org/p/gTXh3vhOj-z

Basically when you pass a value into a function that takes a float, if the type hasn't been explicitly resolved, it will coerce it into a float (if it can, it wouldnt do it on a string).

So when you say "why can you pass integers", well you're not really. It's just 2 is being turned into a float.

Does that make sense?

Collapse
 
hrishin profile image
Hrishikesh Shinde

Thanks Chris. Yes that makes sense.