4 ms·
Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have
by brabel 5y ago
Their code is full of things like:
type fileOps []any // []T where T is (string | int64)
Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them.
Reminds of Java 4 (15 years ago or something) where code was full of this crap:
List /* <String> */ values;
Map /* <String, Object> */ map;
Some devs spent a whole week doing nothing other than removing those commented out generic type declarations once Java finally got generics!
- mseepgood 5y agoYou're lucky: Go 1.18 Beta 1 was released today, which has generics.
- mikojan 5y agoCraazzyyyyy - ty!
- Thaxll 5y agoGo has generics in that commit.
- qaq 5y ago1.18 Beta is out today with Generics
- gameswithgo 5y agoYou could have sum types, and not generics to cover many of these cases I guess? And then Go could have the error type it kind of wants to have.
- amelius 5y ago> Some devs spent a whole week doing nothing other than removing those commented out generic type declarations once Java finally got generics! Fast-forwarding to today, could Co-pilot have saved them the trouble?
- tjalfi 5y agoI'm not sure about Copilot but IntelliJ IDEA's structural search and replace[0] is well suited to this task. [0] https://www.jetbrains.com/help/idea/structural-search-and-replace.html https://www.jetbrains.com/help/idea/structural-search-and-re...
- vlang1dot0 5y agoI'm pretty sure sed could have saved them the trouble.
- comeonseriously 5y ago> I feel sorry for them. Oh good grief. There are 32,768 programming languages. People are free to pick the ones they want to use and nobody wants your pity.
- jwandborg 5y agoAre we wasting that bit to spite us?
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- mappu 5y agoGo has had generic List<> and Map<> since before Go 1.0, though. It's really interesting you used those as your examples because that need was fully met in a type-safe way already, and other examples are actually much rarer to come by.
- erik_seaberg 5y agoThe behavior of builtin maps can’t be customized at all. Now at least it’s possible to define a sorted or threadsafe or immutable map with a typesafe API, though it takes replacing all reads and writes with method calls.
- xyzzy_plugh 5y agoNot being able to customize built-in containers is a huge win in terms of readability though. Principle of least surprise and all. If I see a map or slice I know exactly how it behaves, how much memory it consumes, what the runtime behavior is. If you make those generics instead then I have literally no fucking clue what's going on.
- brabel 5y agoIt's even more interesting you chose to actually comment on the particular example I gave rather than general generics for user-defined types, which is clearly what I was talking about. Trying to counter argue against an example by using the actual example, rather than the point the example is trying to convey, is a common, but quite dishonest debate strategy.