|
|
|
|
|
by retrodaredevil
524 days ago
|
|
I like simple languages without bells and whistles but for me, Go has some flaws that I cannot look past. Specifically the map type. Unlike some Map implementations in Java, maps in Go are not ordered and there is no way to order them unless you want to keep a slice representing the order of the keys. Keys in these maps must be comparable, which means that unlike Java, you can't just implement equals() and hashCode() to make your type comparable. Maps and slices are not comparable, so if you use either in a struct, that struct is no longer comparable. Since map keys must be comparable, you'll have to convert your struct to a comparable type like a string if you want to use it as a key to a map. You can always look for a third party library for more data structures, but the last time I looked those libraries didn't support generics yet. Sometimes you'll find a standard library function that takes an interface{} and might panic if you give it a value it doesn't like. This is especially the case for library functions that want to operate on slices. Slices can be generic, but you'll still find many functions that accept interface{}, so you're left with library functions and third party libraries that take any as the type of an argument and expect you to read the documentation so that you don't accidentally pass the wrong type. interface{}s are comparable sometimes, and if you compare two types that aren't actually comparable, you'll get a panic. |
|