Live data from Hacker News

Go generics are not bad

lemire.me

241–250 of 305 posts

Re: Go generics are not bad

#241
post #235

Earlier quoted context omitted.

That's an interesting point. From a strictly theoretical perspective you're right. I think it's that generics are more abstract and have a higher blast radius. Eg, you add an argument to a method, you need to update usage of that method. You add a generic to a class, you need to update everywhere that class is used. The fact that arguments are less abstract also I believe tends to prevent them from bubbling all the w…

> you add an argument to a method, you need to update usage of that method. You add a generic to a class, you need to update everywhere that class is used. You're talking about two different things here, though. What if you add a generic parameter to a function? It'll often be inferred at existing call sites, but worst case, same as any other change to a function's signature.

The reason I'm relating them is that they're both changes to a class, that have different blast radii and different levels of abstraction.

In the worst case, adding a nongeneric parameter to a function could have the same impact. I've never heard of that happening though. I'm trying to express how I've observed things working in practice, not the theoretical boundaries of what could happen here.

So lets say you add a concrete parameter to a method. You update the usages. Somewhere the output gets stored in an existing class. So you add a new field to this class of the correct type. You're done.

Let's say you do the same with a generic. Now when you add that field to that class, it also has to be generic over that type. Now you need to update all the places where that class was used.

If your code is overly generic throughout, the likelihood of this having secondary or tertiary effects and having a runaway refactor becomes pretty darn high.

Being too abstract will always get you in trouble, and it'll probably look pretty similar. I'm just saying it's very easy to do with generics and harder to do with less abstract techniques.

Re: Go generics are not bad

#242

Earlier quoted context omitted.

> my guess is that the great languages Academia cook-up scale poorly on code bases which receive tens of updates per day Why would they? Many are designed meticulously to address the issues industry has. I've worked on a multi-million line Haskell code base in a financial institution and it scaled better than e.g. C++ or Python. In 30 years time, I'm sure the industry will be extolling the virtues of algebraic data t…

God what's the compilation time of millions of line of Haskell? > In 30 years time, I'm sure the industry will be extolling the virtues of algebraic data types, purity, immutability and referential transparency. There are plenty of industrial languages with algebraic data types and immutability. Not as many as I would like with purity but I doubt it will take 30 years.

Purity is nice and clear to reason about. But when you want the last drop of performance, having a place to overwrite memory as you invoke a SIMD algorithm or cast and do bitwise stuff is invaluable from a performance point of view, whether we like it or not.

Re: Go generics are not bad

#243
post #240
post #196

Earlier quoted context omitted.

That was a generic argument, but still a valid one. Go is a language that indeed misses several features, including safety features, that help people perform their job better, and their excuses for that aren't exactly well thought. It is a systemic issue with the language, and criticising it ca feel like a cheap shot, but that's they way it is. It's nice that they're reverting their position on that (re: generics), b…

> I don't understand why this always happens in Go discussions. It's a language with a lot of potential, but people still stoop down to attacking others in order to defend it should be frozen in time. It's not about wanting it to be frozen in time, it's more about wanting to have an interesting discussion. Repeating the same mantra in every Go thread is cheap, tiring even. Before it was generics, now is some vague 'l…

Who cares if it’s cheap and tiring, it’s the truth. When it was missing generica, saying so was also called a “cheap shot”.

There’s plenty of proposals of thing that can be improved in this thread alone. Not every post has to contain them to be valid criticism. Sure it could have more but that doesn’t warrant personal attacks.

Re: Go generics are not bad

#244
post #196

Earlier quoted context omitted.

That was a generic argument, but still a valid one. Go is a language that indeed misses several features, including safety features, that help people perform their job better, and their excuses for that aren't exactly well thought. It is a systemic issue with the language, and criticising it ca feel like a cheap shot, but that's they way it is. It's nice that they're reverting their position on that (re: generics), b…

> Go is a language that indeed misses several features... that help people perform their job better... It is a systemic issue with the language The only language in which "misses several features" is not "systemic" is C++, and having every feature seems also to not really help anyone do their job better. I'm sure your language of choice is perfect, though.

Bullshit. “Misses several features” doesn’t mean “misses all features ever invented”. What an absurd interpretation. There are several languages in between Go and C++ that suffer from neither problem of having too much or too little.

Re: Go generics are not bad

#245
post #244

Earlier quoted context omitted.

> Go is a language that indeed misses several features... that help people perform their job better... It is a systemic issue with the language The only language in which "misses several features" is not "systemic" is C++, and having every feature seems also to not really help anyone do their job better. I'm sure your language of choice is perfect, though.

Bullshit. “Misses several features” doesn’t mean “misses all features ever invented”. What an absurd interpretation. There are several languages in between Go and C++ that suffer from neither problem of having too much or too little.

Your lack of specifics means you’re more interested in language bashing than discussing the relative value of features for different contexts.

It’s been almost two decades of increasing memory latency relative to clock yet Java still lacks value types? Unusable!

Re: Go generics are not bad

#246

Earlier quoted context omitted.

Go helps devs by creating extra work like checking for inner nil and outer nil, hitting the "if err != nil { return nil, err }" button on their keyboard, using reflection to instantiate unexported structs written by library authors who decided nobody should ever be able to make an interface-compatible wrapper that adds capabilities to their library, and relying on the language to enforce the checking of error return…

There is no “inner/outer nil”. People just need to understand how interfaces work (they’re a reference type and sometimes they reference another reference type, so just like any language with nullable pointers/references, either the pointer or the pointee can be nil). 101 level stuff. There are valid criticisms of Go (I’m not a fan of nil in the first place, for example), but this inner/outer nil myth needs to die.

Sure, if any method anywhere takes a pointer receiver, then anyone can declare an interface that matches that method, and that interface is (among other things) like an Option> in Rust or a ??T in Zig. It's weird to post "There is no inner/outer nil" since the most straightforward interpretation of that claim is that there is no None/Some(None) distinction, and this is straightforwardly not true.

For some reason, most languages do not encourage the users to create types that are similar to Option>.

Have you actually taken this stuff to a group of first-semester CS students and had them understand it and think it was a good design?

In the stdlib there's this function:

  // String returns the source text used to compile the regular expression.
  func (re *Regexp) String() string {
   return re.expr
  }
which takes a pointer-to-struct receiver and does not check it for nil before using it. So any program that declares a Stringable interface, diligently checks Stringables to make sure they are non-nil, then calls String() only on the non-nil ones is allowed to panic on this line from the stdlib because re == nil. The wonderful tutorial[0] teaches beginning go programmers to write the same sort of bug in the first lesson about interfaces.

[0]: https://go.dev/tour/methods/9

Re: Go generics are not bad

#247
post #237

Earlier quoted context omitted.

> Go is a language that indeed misses several features... that help people perform their job better... It is a systemic issue with the language The only language in which "misses several features" is not "systemic" is C++, and having every feature seems also to not really help anyone do their job better. I'm sure your language of choice is perfect, though.

Missing features is not the problem. A language is just as much what it has as much as what it doesn’t have. But the actual feature-set and lack-of-features Go has for it is ripe for plenty of valid criticism as is.

> the actual feature-set and lack-of-features Go has for it is ripe for plenty of valid criticism as is.

But this, as a criticism of Go, is vapid. Level the actual criticism, not a vague gesture towards the possibility of it!

Re: Go generics are not bad

#248
post #238
post #205

Earlier quoted context omitted.

Right. My view is: Go brings back a lot of the great traits of languages like Pascal and Modula. Fast compilation speed, a simple static typed language, a modules concept. Adding a few nice things like GC, high order functions and some more. I feel, programming too often lost productivity with quite a few modern languages. Go brings that back and adds a good amount of modern features, but doesn't get too much distrac…

How does it bring back productivity when it has the expressivity of C (at least before generics, it’s a bit better afterwards)

C doesn’t have methods, interfaces, closures, newtypes, packages, map or safe slice and string types, or safe automatic allocations.

What bad faith nonsense.

Re: Go generics are not bad

#249
post #162

Earlier quoted context omitted.

Can’t hate on generics, so we need to find something else. Go takes away type system fidget spinners and leave devs with nothing to do but the actual job, which they hate, and thus they hate Go.

That’s actually a brilliant assertion (sorry for the crap pun). The majority of developers I work with are only aware of the success paths of their code. That means we’re knee deep in exception corpses because they avoided doing part of their job. Go makes them deal with it.

Sure, Go makes you write code to do something in the case of an error - over and over again at every level in the chain. Which tends towards programmers putting in minimal effort each time, often meaning when some low level error occurs in the resulting application little information is forthcoming to the user as to why it's just aborted on them. Good and bad error handling can be done in any language. I've not seen any evidence that Go apps and libraries generally do it better than those written in exception-enabled languages.

Re: Go generics are not bad

#250

This seems very basic. Not to dunk on prof. Lemire, i know he has some great posts. This one is just barely scratching the surface of what makes a language good at supporting polymorphism or not.

If I was a researcher focused on developing efficient algorithms for numerical data this example would also seem to be one of the most critical for my work.
Post reply on HN