News for hackers. Stuff that matters.
Re:Half a million lines of Go by tptacek on Sunday May 16, 2021 @08:30PM (#27178712)
Roughly the same way containers work in Python.
Re:Half a million lines of Go by dragonwriter on Sunday May 16, 2021 @08:52PM (#27178843)
> Roughly the same way containers work in Python.

That’s not really true, since built-in containers are special sui generis generics in Go, whereas in an untyped python they get by being untyped, and in python’s statically-checked type system (as implemented in pyright, mypy, etc.) they use general-purpose generics.

Re:Half a million lines of Go by tptacek on Sunday May 16, 2021 @08:54PM (#27178858)
That complaint is as old as the language --- the first piece about Go I ever read, after my friend Yan convinced me to pick up Go, called it out for having "generics for me and no generics for thee". I've never understood why I'm meant to care. I get, if you want to write your own generic containers, being irritated that there aren't universally available generics (yet). I don't get being upset that the language has some special-cased generics. It's not personal. They're not rubbing salt in your wounds. They just need a map type that works.

At any rate: the person asking the question is wondering how you manage to have performant containers with reasonable interfaces in a language without generics. That's a good question! If you've worked a lot in C, you might be imagining a horrible mess of void-stars or something. But no, the ergonomics are basically those of Python, with extra typing.

Re:Half a million lines of Go by joshuamorton on Sunday May 16, 2021 @09:15PM (#27179033)
Given that they stated "Do you basically have to declare and implement types/methods for each different contained type?" in the comment, I don't think they were wondering if you end up using void*/interface{}.

I really don't understand how the python comparison makes sense. Since those particular containers are special cased, the ergonomics are also the same as java (and I'd argue more like java than python). Other than ownership, I don't think go's maps are any more python like than C++s or Rusts either.

> reasonable interfaces in a language without generics

and with static typing. Python doesn't fall into that category. It either doesn't have static types, or does have generics. The answer (as others have mentioned) is that go does support generics for a few particular container types.

Re:Half a million lines of Go by dragonwriter on Sunday May 16, 2021 @10:39PM (#27179566)
> That complaint is as old as the language

I’m not making a complaint, I’m pointing out a fact without a value judgement.

> At any rate: the person asking the question is wondering how you manage to have performant containers with reasonable interfaces in a language without generics.

Uh, I don’t see either “performant” or “with reasonable interfaces” there, the question is: “How do container types, like arrays or hashmaps work without generics? Do you basically have to declare and implement types/methods for each different contained type?”

The answer is, for built-in containers, “no, because they use special-purpose generics”. For custom containers, its basically “yes”, but you probably only want a single contained type with an appropriate interface anyway. In neither case is “basically the same as Python” particularly accurate, though I suppose the former case is similar to typed python using generics in the same way as any language with generics would be, while the latter is loosely similar to bare Python or typed Python using protocols instead of generics. But only loosely.

Re:Half a million lines of Go by masklinn on Monday May 17, 2021 @04:42AM (#27181290)
> The answer is, for built-in containers, “no, because they use special-purpose generics”.

Unless you want to implement utility helpers working on them then it’s yes again, because Go doesn’t have generic functions either, so while it does have a few builtin generic containers, you can’t operate genetically over them.

Re:Half a million lines of Go by tptacek on Monday May 17, 2021 @12:18AM (#27180008)
Yeah, I'm choosing not to die on this hill. I'm just saying that Go has first-class table and resizable array ADTs.
Re:Half a million lines of Go by masklinn on Monday May 17, 2021 @04:45AM (#27181306)
They’re not first class though: you can not take in, return, or work with the ADTs, only with concrete instances of them.
Re:Half a million lines of Go by tptacek on Monday May 17, 2021 @03:30PM (#27187345)
Hey, there, I'm over on this other hill now, not dying on that one. :)