3 ms·
C may not have generic types, but much of the standard library does use generics, just through the unsafe mechanism of `void*`. Likewise, go already includes so
by opnitro 6y ago
C may not have generic types, but much of the standard library does use generics, just through the unsafe mechanism of `void*`. Likewise, go already includes some generic code (the array type), it's just treated specially.
- zwieback 6y agoFor me the desire to use generics shows up once I've invested some time in making fancy types. When I work in C that point is never reached since problems are solved "the C way". Personally I'm a huge fan of generics but I can understand how the keepers of Go might be reluctant to go down the path of C++, Java and C#.
- wahern 6y agoThe equivalent to a void pointer in Go is interface{}. But very little of the C standard library uses void pointers--basically only those interfaces dealing with untyped blocks of memory, such as malloc and free. IME, you see interface{} far more often in Go code than you see void pointers in C code. And C actually has bone fide generics capabilities with _Generic, it's just very simple and manual.
- wing-_-nuts 6y agogo's empty interfaces reminded me too much of the bad old days when everyone passed around Objects to java methods. I hated it.
- Cyph0n 6y agovoid * is very useful as an opaque pointer type. For example, it's used all over the place in collection implementations and user-defined arguments (e.g., callbacks, pthread_create). It might not be used much in the stdlib (which is relatively small!), but libraries and applications rely on void * heavily in my experience.