52 ms·
I really like Go, but it just doesn't quite reach the point where I want to use it for everything I do - mainly because it lacks generics. The philosophy of Go
by djhworld 14y ago
I really like Go, but it just doesn't quite reach the point where I want to use it for everything I do - mainly because it lacks generics.
The philosophy of Go is to keep things simple I know, and generics would inevitably add some degree of complexity to the language, but I feel that addition of complexity would be worth it.
Without generics it just feels like you're writing in Java <= 1.4 again
- mseepgood 14y agoGo has some selected generic data types: array, slice (think of ArrayList<T>), map, channel, func. I found these to be sufficient for 90% of my problems. In 9% of the cases I craft non-generic data structures based on interfaces, which are specific to my problem domain. For the rest I can live with interface{}.
- CJefferson 14y agoI really dislike languages which decide to bless some special data-structures, but then won't let me add my own generic data structures. Of course, I really love data structures, so I can understand other people who just want to get on with things, and are happy to slightly abuse some built-in data structures to get most of the way there.
- luriel 14y agoGo doesn't stop you from building datastructures, actually is really nice for building datastructures. It simply doesn't provide a simple way to build some kinds of generic datastructures, but when the ones provided by the language are not enough it usually means your problem is specialized enough that a custom datastructure is best anyway, and Go makes that pleasant and easy. And then there are interfaces, which are a kind of "generics" of their own.
- fauigerzigerk 14y agoI don't like the special treatment for builtin data structures either. But if the alternatives are ending up in a mental institution (C++ templates) or in a Potemkin village (Java), I'd rather live with this inconsistency for a while. Maybe (hopefully!) these are not the only alternatives.
- djhworld 14y agoI'm currently going through an algorithms textbook and find that algorithms and generics go hand in hand in writing generic, type safe reusable algorithms in your code. Having to rewrite the same code over and over again to support one algorithm is a real pain in the butt. ...and the interface{} thing is just a workaround that defers type errors until runtime. Which in turn defeats the point of enjoying a type safe language
- deleted 14y ago[deleted]
- luriel 14y agoJava <= 1.4 had nothing like Go's maps, slices, channels (quite useful to build queues and FIFOs), or interfaces. So no, its not like Java <= 1.4 at all, and that is without going into all the other fundamental language, library and philosophy differences.
- danieldk 14y agoIndeed, Go goes much further than Java before 1.5, since it does allow you to specify types for maps, lists, and channels. Still, it would be nice if you wrote, say a matrix package, that you could simply specialize data structures for double or single precision. You see such shortcomings in the standard library as well, for instance for the ParseFloat string conversion functions in strconv, you have to specify the number of bits of the data type. It would be much better if the return type was some generic type for fractional numbers. Now, if you want to have a single precision double, you have to specify that you want to have a 32-bit float and then cast it to a float32. That said, I believe that Go needs generics, but I'd rather see them implement them properly than to rush.
- pjmlp 14y agointerfaces are part of Java since 1.0 maps in Java 1.3 (older documentation is not available online): http://docs.oracle.com/javase/1.3/docs/api/java/util/HashMap.html http://docs.oracle.com/javase/1.3/docs/api/java/util/HashMap... channels for queues and FIFOS: http://docs.oracle.com/javase/1.3/docs/api/java/util/LinkedList.html http://docs.oracle.com/javase/1.3/docs/api/java/util/LinkedL... better yet after 1.5: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concu... Many of the array slices algorithms can be made via the Arrays class http://docs.oracle.com/javase/1.3/docs/api/java/util/Arrays.html http://docs.oracle.com/javase/1.3/docs/api/java/util/Arrays....
- luriel 14y agoNone of those things are like in Go, which was precisely my point.