5 ms·
tl;dr: We're shipping generics in 1.18, it's a huge release so let's wait a little bit until they stabilise and they're used in production before changing our s
by sph 5y ago
tl;dr: We're shipping generics in 1.18, it's a huge release so let's wait a little bit until they stabilise and they're used in production before changing our stdlib.
Good call in my book, and I'm extremely excited to have generics finally. I thought they were going to ship with 2.0, but the sooner the better!
It's cool to hate on Go, it's taken over the system programming space for a reason, like it or not, and after working full time on Elixir it's hard not to think in map/reduce and other generic constructs, which were unreasonably verbose before in Go. Now the haters will have to focus on the "if err != nil" statement to pile on the language — though to be fair I'll expect some ergonomic improvement on that aspect as well, eventually.
With generics, Go will be my new Python, but with a decent dependency and deployment story, and I'll just need Zig for my low-level manual memory management needs. What's Rust?
EDIT: indeed being a bit cheeky with HN's favourite language isn't well received in this place.
- pjmlp 5y agoGo has taken over kuberbetes related stuff, that is all. Although I like it being used for systems programming stuff like TinyGo on embedded or F-Secure TamaGo unikernel, that is hardly taking over the domain where C and C++ still rule, and will keep to do so for decades to come, despite the increasing usage of Rust on the domain.
- EdwardDiego 5y agoAt least now we can write a generic set that supports all the things you want a set to do, instead of using map[T]interface{} and a lot of for loops.
- everybodyknows 5y ago>map[T]interface{} If the semantics desired are merely those of a simple set, why instantiate storage for the value side of the map? An interface{} consumes 16 bytes. Instantiating a struct{}, i.e. with no fields inside, consumes 0 bytes.
- Shish2k 5y agoBecause when a language doesn’t supply common features out of the box, users implement them for themselves, and inevitably a lot of them do a bad job of it :)
- EdwardDiego 5y agoAh yeah, that's right, it was map[T]struct{} - it's been a bit since I had to do it. I knew it was something with curly brackets instead of the map[T]bool I started using.
- vips7L 5y agoMore reasons to have a generic Set type in the standard library. That way you know the implementation is correct every time.
- paedubucher 5y agoBrad Fitzpatrick stated in one of his talks, that a version of Go coming with generics will be called 2.0 eventually. Maybe they do the version jump if there are backward-incompatible changes done to the library in 1.19.
- leaveyou 5y agoWhen was that ? IIRC that was the general feeling then but the impression has changed in the mean time ?
- cageface 5y agoLack of null safety is still a major shortcoming in my book compared to Rust/Swift/Typescript.
- everybodyknows 5y agonull safety: Can you provide us a reference to a working definition of the term?
- cageface 5y agoFor example in Typescript, you can specify whether a parameter is allowed to be null in the signature of a function. If you do the compiler will make sure that you don't accidentally pass a null value to that function. function foo(x: number) { return x + 1; } let y = null; foo(y); // compiler will flag this
- drvd 5y agoIn Go func foo(x int) { return x + 1 } var y *int = nil foo(y) // compiler will flag thi
- Gwypaas 5y agoNow add an error to foo and have x=0 as a valid return value, or even worse, having to deal differently with different errors.
- cy_hauser 5y agoThat wasn't the greatest example as Go doesn't really have any way to represent it. If it did it might be something like this. type MyStruct struct { Name string } var-not-nil myStruct = &MyStruct{"Hello"} // this is a "not-nil" pointer variable myStruct = nil // compiler would catch this The idea being to allow variables to hold and pass pointers to structs like now but ensure they are never nil.
- Macha 5y ago
- throw_m239339 5y ago> It's cool to hate on Go, criticism =/= hate Nobody "hates" on Go for the sake of it. If some people were not critical of that language, generics would have never been added at first place. I'm glad the Go team acknowledged the flaw instead of the gaslighting that has been going on for years in the go community from a few go users.
- 1_player 5y agoCalling it "gaslighting" is exactly what a hater would do. It's not very constructive. Generics were a pain point, but people have been crapping on Go on this forum while people out there are using it to build stuff. It's not a perfect language, but if you read any HN thread about it it's like it's impossible for people to go past the lack of generics or the existence of nil.
- sanderjd 5y agoIt is a good use of the word "gaslighting", which I think can be defined as "an effort to convince someone that they do not know a thing that they do know". In this case, a lot of people know from lots of experience that writing type safe generic code is extremely useful, but the go community spent a long time arguing that people could not have had that experience because writing generic code isn't actually useful. This isn't really my impression of what the go team was saying, which I interpreted as more like "parametric polymorphism is useful but we aren't sure it is a good fit with the simple language design we are seeking to maintain". That's totally reasonable, everything is trade offs, but that's not the prevailing pushback you would get from the go community, you'd instead hear a message more like "if you'd rather write generic code instead of copy pasting constantly, you're a bad programmer who doesn't get it", which is not helpful and yes, I think gaslighting is a reasonable description. The existence of nil is also a design flaw. But you're right that no language is perfect and neither of these flaws keeps people from building tons of useful stuff with the language. I think there is definitely gaslighting in the other direction too, which is what you're highlighting: lots of people know from experience that go is a super useful language, but then people come of as saying "your experience does not exist, it is not a useful language because of these big design flaws".
- the_duke 5y ago> it's taken over the system programming space for a reason I'm curious what you define as systems programming, because Go certainly isn't a systems programming language by the classic definition. Go has a complicated runtime and GC. It's really not in the same category as C/C++/Rust, but more like Java/C# , just without a JIT. The only domain where Go is a go-to language is the Kubernetes ecosystem. It's also decently popular for networking heavy applications / microservices / server applications, because the runtime is well suited for those domains.
- Zababa 5y agoGo is basically a systems programming language if you consider """the cloud""" a system, a big part of the ecosystem is built on it. It is basically between C/C++/Rust and Java/C#, which is "good enough".
- fsociety 5y agoIn that case JavaScript is a systems programming language if you consider the web a system. Golang having GC and a heavy runtime make it unsuitable for systems programming IMO.
- pjmlp 5y agoIt isn't unsuitable per se, but it definitly lacks the knobs of something better like D, C# or Nim. https://www.packtpub.com/product/creative-diy-microcontroller-projects-with-tinygo-and-webassembly/9781800560208 https://www.packtpub.com/product/creative-diy-microcontrolle... https://www.f-secure.com/en/consulting/foundry/usb-armory https://www.f-secure.com/en/consulting/foundry/usb-armory
- Zababa 5y agoNot exactly, the web runs on browsers and web engines that are written in C++, and servers that are mostly C and/or C++. On the other hand, "the could" runs (partially) on k8s and friends, which are written in Go (which runs on servers, written in C and/or C++).
- 5y ago
- stjohnswarts 5y agoThat's because you can put out there why you like a language and people will upvote you. Dump on other people's choice in a systems language and you will likely suffer some down votes. Cheeky has a price.
- another_Hans_M 5y agoNo need to disrespect Rust. I like both. And certainly they both have their proper use cases.