4 ms·
I find Go is quite similar to C, and C also lacks all of these features. It's rare to see C code using some library for generic containers. Most developers roll
by xyzzy_plugh 9y ago
I find Go is quite similar to C, and C also lacks all of these features. It's rare to see C code using some library for generic containers. Most developers roll their own, as needed.
In practice, bugs and safety aside, this tends to work swimmingly. Look at Redis, or git, or postgresql, or the many other projects getting by just fine without generics.
While I agree, and believe generics offer unparalleled power, they often aren't remotely necessary. If anything, their presence creates a tendency to over-use them, resulting in even greater complexity.
- pjmlp 9y agoI was able to write software since 1980's until 1994, without a single line of generics in whatever language I had to use, until I got the first Borland C++ compiler with support for the early templates draft. It is still possible to travel by horse, yet people have moved on to better solutions.
- microtherion 9y agoHaving lived through that time as well, maybe the most painful period of that was toward the end, when we I was trying to use macro-based generic containers from the Rogue Wave Tools.h++ library. Frankly, early templates based C++ code was not all that great either. It was the introduction of the STL that made a huge difference in the usefulness of templates.
- pjmlp 9y agoThat is what go generate reminds me, the macros that Borland had on Borland C++ 2.0 for MS-DOS, on their collection classes (BIDS), before they added templates support with 3.0.
- pcwalton 9y agoNo, it doesn't work swimmingly. All of those projects have ended up either using void∗ or macros, or both, in order to roll their own generic data structures. > Look at Redis, https://github.com/antirez/redis/blob/unstable/src/adlist.h https://github.com/antirez/redis/blob/unstable/src/adlist.h — generic doubly-linked list with void∗ https://github.com/antirez/redis/blob/unstable/src/dict.h https://github.com/antirez/redis/blob/unstable/src/dict.h — generic hash table with void∗ > or git https://github.com/git/git/blob/master/hashmap.h https://github.com/git/git/blob/master/hashmap.h — generic hash table with void∗ https://github.com/git/git/blob/master/list.h https://github.com/git/git/blob/master/list.h — generic doubly linked list implemented with macros > or postgresql https://github.com/postgres/postgres/blob/master/src/include/lib/ilist.h https://github.com/postgres/postgres/blob/master/src/include... — generic doubly linked list implemented with macros https://github.com/postgres/postgres/blob/master/src/include/lib/rbtree.h https://github.com/postgres/postgres/blob/master/src/include... — generic red-black tree with void∗
- KirinDave 9y agoI agree strongly. "It works" is an encoding of, "I can write tests which perform correctly" and not "My code is stable in the face of aggressive input." Go definitely follows along with C in this tradition. It's better than C, because you have slightly more safety interpreting memory as executable and in bounds checking. However, it does very little to stop destructive bugs or let programmers escape copy-paste code hell where regressions keep resurfacing because it's most expedient to copy-paste code.
- SomeStupidPoint 9y ago> bugs and safety aside Can you really set aside one of the core arguments for generics while discussing how it works? How many exploits have been caused by the fact that C code tends to have its own data structures (including bounds checking errors)? I don't describe that as working "swimmingly", at least when discussing how things work in practice.
- deleted 9y ago[deleted]