3 ms·
It often amazes me that Go wasn't given some level of generics from the offset since it's a web-focused language and the web is untyped. If I'm honest though,
by laumars 12y ago
It often amazes me that Go wasn't given some level of generics from the offset since it's a web-focused language and the web is untyped.
If I'm honest though, most of the time I don't miss generics. However the moment I start using a database or parsing JSON documents (particularly ones you cannot make assumptions about the document structure), the lack of generics is a massive pain.
- jerf 12y agoIt actually was given "some level" of generics; arrays and maps are generic (or at least more generic than anything else), but they're programmed as special cases into the syntax and runtime rather than as an instance of generic generic (ahem) functionality. This is part of why the Go generic debate rages on, while Go itself is continuing to be used. If Go were lacking in any "generic" associative lookup structure it would get no traction in 201x. (If C were introduced today in a world that somehow lacked it, nobody would give it a second look. Which is as it should be... one would hope we've learned something in the past 40 years....)
- laumars 12y agoI don't really think it's fair to argue arrays as an example of generics since they've been around since the dawn imperative programming languages and have been a staple in the kinds of languages that people example as having a lack of generics. I'd also question whether maps are a good example either since a map[string]interface{} would be incompatible with a map[int]interface{} (which leads to many of the code duplication examples that developers demonstrate when discussing the need for generics in Go) Maybe I'm splitting hairs, but this would likely be the mindset that Pike et al have with regards to "generic" built in types. I do agree with you that there is "some level" of generics on Go though: interfaces{}. Sadly that feature was "uglified" by the constant need for casting (and that's putting it politely).
- jerf 12y ago"I'd also question whether maps are a good example either since a map[string]interface{} would be incompatible with a map[int]interface{}" The map is what is generic, not a specific map. List<Int> is not "compatible" with a List<Char> in any implementation of generics; how could it be? What would that even mean? There isn't a good way of taking a "map", just any "map", but that's a separate problem. Not all languages that have generics can do that, either, only some of them. (A recurring issue in these discussions about Go is that people end up bringing the union of all possible things that generics have ever done, anywhere, to the party, but in reality no language actually has all of those features at once. Real generic implementations, when not being discussed in the context of Go, are usually being discussed in how they are broken. This is what ultimately brought me peace in this argument... in the abstract, it's totally obvious that Go ought to have generics. In the concrete it's a great deal less obvious, and real implementations all do indeed have their serious problems once you get down to the nitty-gritty of what assembly instructions they would actually execute, and exactly how the compiler would produce them. It's all fun and games when you're just waving hands around.) interface{} isn't a "generic" in any sense.
- laumars 12y ago> The map is what is generic, not a specific map. List<Int> is not "compatible" with a List<Char> in any implementation of generics; how could it be? What would that even mean? Well, arguably there are languages where that's possible. PHP does some odd things with maps and arrays, and Perl hashes don't have any distinctions between strings, integers nor floats (or at least none that I've run into - please correct me if I'm wrong). Though I will grant you that I'm now comparing strongly typed languages to weakly typed ones. I think my problem here is although I cut my teeth on statically typed languages, my exposure to generics in those languages was rather limited (in fact does Pascal even support generics?). So I'm possibly misunderstanding the usage of generics in modern strongly typed languages.
- Nelson69 12y agoIt's web focused? In 2015, your new language needs to have some web stuff built into the standard library or at least some foundation libraries. I don't know that that makes it web focused though. Seems like there is a huge cultural gap or something, Go was initially built by real-deal C guys. There is a ton of overlap with them and like the plan-9 and suckless fans. If you're not doing hard-realtime or poking registers, it very very much looks like a language designed to fix the problems C has. Just about any of the standard UNIX tools could fairly easily be built in Go and probably be cleaner, maybe more bug free. When the go compiler and run-times are optimized up and the performance is there, it seems like you'd really need a compelling argument to not write those kinds of tools in Go instead of C. If you really dive in to the plan-9 and suckless stuff, how many of those programs legitimately have more than a couple data-structures? They are small, they do one thing, they try to do it well. There are a lot of "missing" things that they aren't urgent the replace because of that, like dynamic linking... What's really amazing is that it has been drawing the ruby, js and python guys in. And generics is a/"The Big" hangup? Why not just the fact that you actually have to compile it or that the compiled product has an OS and hardware requirement.
- laumars 12y ago>It's web focused? Web-focused is a poor choice of words on my part. But IIRC Google adopted the project as a means to speed up development and execution time for their web services back ends (if that's wrong then I'll happily welcome a correction). Either way, Go does have a presence in web development - not least of all by Google > What's really amazing is that it has been drawing the ruby, js and python guys in. And generics is a/"The Big" hangup? Why not just the fact that you actually have to compile it or that the compiled product has an OS and hardware requirement. Only the compiled binary is OS dependant, the code is just as portable as your exampled languages. And the only hardware requirement is the word size and architecture of the CPU - which for web development would nearly always be x86_64. Plus Go makes cross-compiling child's play - so there's no issues with compiling for another CPU architecture (if, for some reason, you're targeting ARM over x86) or for 32bit platforms, Windows, FreeBSD, OS X or Linux. I actually think the fact that Go needs compiling is a real strength of Go. Unit and regression testing of websites can be painful in JIT compiled, dynamic languages; where as go build catches a lot of developer "absent-mindedness" before the web application even reaches the testing phase. Obviously compiling isn't going to catch everything, but in my experience, it has massively streamlined the process of developing production ready code.