|
|
|
|
|
by burke
3382 days ago
|
|
While I understand the argument for simplicity and agree with the premise in most cases, I find it pretty hard to argue for this code: ys := []byte{}
for _, x in xs {
ys = append(ys, f(x))
}
over something like this code, which is more obvious, less error-prone, and, though it relies on an additional concept, it's an extremely broadly-known concept: ys := collections.map(xs, f)
I don't think a proper collections library would require very invasive runtime changes -- though, once you start down this path, you and up at "but what if `f` returns `(myType, error)`, and then you're wishing for Option/Maybe types (which is another feature that I believe Go should have implemented, but is more obviously outside of the apparent mandate).EDIT: It would make static analysis significantly more complex too. |
|
If they build a collections API like this now, without generics, and they then add generic types later, they will be in the same position Java found itself in - lots of painful API migrations.
While the generics debate is legendary in go, it does still seem very much like the intention is to eventually include it. Given that, I think it makes perfect sense to wait to introduce more special cases (like `append`).
In the meantime:
:)