On the other hand, if there ' s one complaint I ' ve heard consistently from my fellow developers over the years, it's that th EY can ' t understand my code until they also understand the set of abstractions I ' ve introduced in order to make the logic of it easier to express. Once They do understand them, they ' re usually comfortable (Once or twice I ' ve had-roll something back out because Nobod Y else could see the point of it; They were usually right, in retrospect).Je ne regrette rien. But you do has to work to get people over the initial hurdle; And that means thattheyHas to work, too. This was practicable in a small, close-knit team where can just wander over to someone ' s desk and talk them through SOM Ething unfamiliar, but it presents a challenge when your codebase would be is read and potentially worked on by hundreds or th Ousands of people, situated in different timezones, across a period of decades. That's Google's reality, and Go is optimised for that scenario.
Here ' s a concrete example. Suppose we wanted to append an exclamation mark to each of the strings in a collection, creating a new collection with the Modified strings. In Kotlin, which would be Val plain = listof ("foo", "Bar", "Baz") val exclaimed = strings.map {it + "!"}
In Go, you could write func mapstringtostring (Input []string, mapper func (String) string) []string {output := make ([]string, len ( Input)) For index, item := range input {output[index] = mapper (item)} Return output} func main () {plain := []string{"foo", "bar", "Baz"} Exclaimed := mapstringtostring (Plain, func (s string) string { return s + "!" }) fmt. Println (exclaimed)}
But it ' s terribly clunky. Go ' s lack of generics means so you had to write as mapStringToString a mapper between collections of both fixed types–you can ' t WR Ite a generic from an map array T R of-an array of, as-can in almost any other strongly-typed modern Lang Uage. The lack of lambda functions means so you had to write out the function signature in full just to pass the string modif Ying function into the mapper. It hardly seems worth it; You might as well just write: Func Main () {plain: = []string{"foo", "Bar", "baz"}exclaimed: = Make ([]string], Len (plain)) for index, item: = Range Plain { Exclaimed[index] = Item + "!"} Fmt. Println (exclaimed)}
|