4 ms·
As much as a I like Go in general, there are two pythonic things that, IMO, really should go into the next major revision. 1: sets; in this day and age, not ha
by bostik 9y ago
As much as a I like Go in general, there are two pythonic things that, IMO, really should go into the next major revision.
1: sets; in this day and age, not having sets as native, stdlib-provided data types is simply unacceptable.[ß]
2: The ease of python's "in" keyword; being able to test for a key in a map
(or set!) without any indirection is crucial
ß: granted, IIRC python moved sets into native stdlib types only somewhere in 2.x but better late than never
- hellcow 9y agoSets, if you mean a collection that contains no more than 1 of something, are easy. Use a map with struct{}{} values. If ordering is important, it's ~30 lines of simple code to encase a slice and a map in a struct and define your desired interface. Testing for a key's existence is easy as well. Accessing a map returns two variables--the 1st is the value itself. The 2nd variable is that "exists" variable you're asking for. It's true when the key is present in the map and false if not. Often you'll see the 2nd variable omitted, but if you need to test for existence it's there for you to use.
- chomp 9y agoYes you can hack sets into most any modern language, but mostly involves writing annoying looking boilerplate, or pulling in external libraries. I think parent is looking for a native set type (which I agree with). I don't know if it has a place in golang, but I always sigh and roll my eyes when I have to implement a set in most languages.
- keenerd 9y agoTesting membership is the easy part of sets. What about subset, superset, union, intersection, difference? So many problems are trivial thanks to sets. I'd sooner give up regex support in python than the set type, that is how useful they are.
- frou_dh 9y agoThis repository was named to emphasise the comedy of its existence :) https://github.com/frou/poor-mans-generics/ https://github.com/frou/poor-mans-generics/
- slrz 9y agoOuch! type Strings map[string]stdext.Unit […] func (a Strings) Intersection(b Strings) Strings { result := NewStrings() for as, _ := range a { for bs, _ := range b { if as == bs { result.Add(as) break } } } return result }
- bostik 9y agoYes, the boolean group operations make many otherwise non-trivial problems remarkably easy. That's why I consider sets such a crucial feature.
- jooke 9y agoCould you give some examples please?
- c-cube 9y agoSets don't need to be native in languages that are both fast and have a proper type system. For example, rust and OCaml have a standard set in their stdlib, but it's not builtin. Of course, go lacking generics makes it impossible to implement a decent set type in it.
- xapata 9y agoSet literals are nifty. If they're in stdlib rather than built-in, they can't be literal syntax.
- ZenoArrow 9y agoI wouldn't hold up OCaml as an example of how to structure your standard library, the lack of standardisation in its standard library is one of the remaining weak points of an otherwise excellent language. For those that don't know, there are multiple standard libraries for OCaml, each with different trade-offs, leading to unnecessary fragmentation.
- c-cube 9y agoAgreed, some things are still missing (in particular my pet peeve, iterators; also unicode strings). But for what it provides, OCaml's stdlib is reasonably well designed and performs well.
- jwilk 9y ago> granted, IIRC python moved sets into native stdlib types only somewhere in 2.x but better late than never Built-in set objects were added in Python 2.4: https://docs.python.org/2/whatsnew/2.4.html#pep-218-built-in-set-objects https://docs.python.org/2/whatsnew/2.4.html#pep-218-built-in...