4 ms·
I can't trust any programming language where there's data structures I can't implement myself.
by LtWorf 2y ago
I can't trust any programming language where there's data structures I can't implement myself.
- jimbokun 2y agoGenerics really reduced the sets of data structures you can’t implement yourself by a lot.
- divan 2y agoWhat data structures can't be implemented without generics?
- bsaul 2y agoi guess maps and array ? ( if you wanted to reimplement your own in a typesafe way, that is)
- vessenes 2y agoI think anything could be implemented, since you’ve got byte arrays in the language, which I imagine is your point. It’s more what you must implement along with your new data structure to make it usable in the language that was the cry of the generics advocates.
- jerf 2y agoI don't think there's anything you "can't" implement that the language reserves for itself anymore. There may be some edge case or something but in general it's no longer an issue. The language reserves syntax for itself; you can't overload a[b] to mean anything other than either array/slice indexing or indexing into a map. You have to write methods like ".Get" or something, there's no __getattr__ or anything.
- ts4z 2y agoGo has good (enough) built-in arrays and maps. But if you want a tree, without generics, you're really limited. With generics, you can get a nice containerized type, but you don't get the nicer syntax that the builtins have. It's not just types, either. Look at the signature for the built-in sort, which is amazingly cumbersome to use. A generic wrapper around it hides all the ugly.
- vessenes 2y agoYou are not the target market for go then. I personally think using Forth is fun, but not for large projects.
- fuzztester 2y agoexamples?
- wwarner 2y agoanything you can ‘range’ over :)
- dharmab 2y agoI have written my own types that can do this? EDIT: Had to check, yeah I had to implement the iter.Seq type to do it
- School-Cotton 2y agoGo added support for custom iterators a few versions ago.
- hnlmorg 2y agoThat’s been possible for a couple of releases now In fact I created a struct that you can range over just a couple of days ago. I can’t say I love the way Go implemented it though. But it does work.
- wwarner 2y agodid not know this thank you!
- fuzztester 2y agoYou can range over the fields of a struct?
- dharmab 2y agohttps://go.dev/play/p/Is1uwjRGASI https://go.dev/play/p/Is1uwjRGASI But I suspect they meant a struct which contains/encapsulates data which can be ranged over.
- 2y ago