Golang Conversions – Ints To Strings And Strong Typing
Go is a strongly typed language, which means at any point a developer should know exactly what type of value they are dealing with. For example, if we have a function that prints a string, we can’t just give it an integer and expect it to work. We have to cast it to a string explicitly: func main() { num := 5 numString string(num) printString(numString) } func printString(s string) { fmt.Println(s) } If we don’t cast the value, the go compiler won’t even let us compile the program. Dynamic Typing is Slow Developers coming from dynamically typed languages often get annoyed with Go’s strong typing. They think that the compiler should just know what they mean and do the type cast implicitly. Strongly typed languages won't guess for you. They make you make the decisions. Click To Tweet There is a reason for this. Type conversions take time and resources. If the Go runtime were to dynamically type every value then programs would run a lot ...