5 ms·
What do you mean by nicer? I would imagine that something that is application specific would not require generics. Interfaces do not throw away type safety if
by ilovecaching 8y ago
What do you mean by nicer? I would imagine that something that is application specific would not require generics.
Interfaces do not throw away type safety if they are used correctly. They are also better suited for the consumer of the type rather than the definer. One of your problems might be that you are prematurely abstracting your interfaces for your callers.
- deleted 8y ago[deleted]
- singingboyo 8y agointerface {} definitely does throw away type safety, however, and is reasonably necessary for some library use cases. Is it possible that you're coming at this from an angle of building applications for specific purposes, while oppositelock is building more libraries? My experience (admittedly limited) is that application writing in Go is nice, but as soon as I try to build a library for use in several similar (but not quite identical) cases, maintaining type safety can quickly become a hassle.
- oppositelock 8y agoLet's say that I have an interface called Sortable, so I design my data structure to accept and return Sortables. I can insert any Sortable into it. When I get the Sortable in a future lookup, I don't know its type. I have to use reflection to error check. With generics, I could create a generic data structure which is strongly typed - what goes in is what comes out. Right now, the way to ensure that is to wrap your data structure in something that converts those Sortables into specific classes, say PatientRecords. Interfaces are wonderful, I like working in Go more than any other language so far, but they have their limitations.