News for hackers. Stuff that matters.
Re:Go 1.18 by preseinger on Tuesday March 15, 2022 @07:07PM (#30693135)
Problems are not generic. "I need a N-ary binary tree over arbitrary comparable types" is not a problem. Problems are expressed in terms of domain concepts that are unique to the problem space, the organization, the business need. Some _implementation details_ or maybe patterns that can be used to solve those problems may be generic. That's separate.
Re:Go 1.18 by codeflo on Tuesday March 15, 2022 @09:02PM (#30694024)
That’s true, a binary tree isn’t a problem, it’s a tool for solving a certain class of problems. Since you can’t build reusable tools in pre-generic Go, (and, to be honest, only a limited set of tools with Go’s new generic system), programmers are forced to reinvent half-baked ad-hoc solutions all over their code base. I once read an article about a C codebase that contained dozens (!) of specialized linked-list implementations. Large Go codebases, from everything I’ve seen, aren’t all that different.
Re:Go 1.18 by hodgesrm on Tuesday March 15, 2022 @10:00PM (#30694398)
Specialized collections are not necessarily bad. ClickHouse has dozens of hash table implementations, each tuned to a specific use case. It's what you do when you need something to go very fast.
Re:Go 1.18 by jen20 on Tuesday March 15, 2022 @11:50PM (#30695122)
Several specialised implementations of a concept with different algorithms is quite different to several implementations of the same algorithm because the language does not support their reasonable reuse. Rust gives you “specialised collections” via monomorphisation.
Re:Go 1.18 by lanstin on Tuesday March 15, 2022 @10:32PM (#30694643)
And that is the exact joy of using a language like C or Go; you need to sort your things, just add in two pointers and make it a list you sort on. Eight or now sixteen extra bytes and you have a good tuned data structure. I don’t want to use a bunch of generic structures, I want to use the ones that solve my particular use case best.
Re:Go 1.18 by eternityforest on Wednesday March 16, 2022 @05:06PM (#30704102)
I always say "Just right is all wrong". The time and standardization cost is often just too much for the small gains. I'd much rather have everything be reusable, abstracted, and one size fits all, aside from the tiny fraction that matters enough to optimize.
Re:Go 1.18 by lanstin on Wednesday March 16, 2022 @11:32PM (#30707372)
Good points. But for myself, I like it when the structure of the code and data structures exactly fit the need. Like the old quite, “show me your header files and hide the C files, and I will understand your program.”
Re:Go 1.18 by nine_k on Tuesday March 15, 2022 @08:38PM (#30693832)
Some problems are technical problems, posited and solved by engineers.

Solving them helps better solve the product and business "real-world" problems.

Re:Go 1.18 by rtpg on Wednesday March 16, 2022 @12:39AM (#30695378)
I mean Go has map right?

"I need a priority queue for X" isn't generic, and "I need a priority queue for Y" isn't generic either. But well if you're doing it a lot, would be nice to not just reproduce the same bugs over and over again, yeah?

Everyone's worried about Go turning into Java and I can't speak too much to the utility (I have written maybe 50 pages of go in my life) but anyone who uses Python's standard lib can point you to 10 different things that are nice to have bug-free versions of and that "just work" thanks to Python's "generics".

Re:Go 1.18 by lenkite on Wednesday March 16, 2022 @05:47AM (#30696922)
I guess you used map[interface{}]interface{} everywhere you needed to use a Go map ? If not, then your statement is a logical contradiction.
Re:Go 1.18 by preseinger on Thursday March 17, 2022 @04:17PM (#30715434)
Of course not. I use map[myKeyType]myValueType, depending on the problem I'm solving.
Re:Go 1.18 by viraptor on Wednesday March 16, 2022 @09:21AM (#30698451)
It depends on the level of abstraction you're addressing. One level may be "i need to store things with a quick search function", another may be "i need a storage of ordered names and expiry date for things", etc until you get to "I need a binary tree which orders by comparable types".

Where you split that process as a separate library you either decide to write or reuse - that becomes the problem to solve. A set implementation may be a problem to solve: https://github.com/deckarep/golang-set A btree may be a problem to solve: https://gitlab.com/cznic/b/-/tree/master/v2

Re:Go 1.18 by diehunde on Tuesday March 15, 2022 @11:27PM (#30695011)
Go is used a lot for systems programming where you do see those problems.
Re:Go 1.18 by john567 on Wednesday March 16, 2022 @04:53AM (#30696635)
No you don't.

If you do, you haven't understood the problem that you need to solve and you are reaching for things you don't need to use.

Re:Go 1.18 by diehunde on Thursday March 17, 2022 @10:43PM (#30718231)
Seems like you are not aware of the kind of problems they solve. Systems engineers have been writing generic programming code for years to build databases, message queues, file systems, etc where you do need data structures that support arbitrary types/functions.