Who? I am convinced you have misheard, as nobody in their right mind would make that claim. We have a ton of code, and thousands and thousands of programmers, so it's just not realistic. These kind of hyperbolic statements are harmful as they build distrust in what we're doing. I, a Go core dev, have no interest in being anything but straightforward on this topic.
Google uses C++ for most compute-intensive code.
I feel though that having a set, or a multiset, whatever... is exactly the kind of abstraction that makes it easy to think about your programs.
In the end I felt that my Go port of some Python felt much more error prone that the original code.
I agree. But many abstractions meet that criteria. That doesn't mean you include it in the language.
Also, it isn't just easy to implement a set with a map in Go, it's downright trivial:
type Set map[string]int
// Create set
set := make(map[string]bool)
// Add to set
set["new element"] = true
// Remove from set
delete(set, "new element")
// Membership test
if set["new element"] {
// "new element" is in the set
} else {
// "new element" is not in the set
}
Of course, this lacks common set operations like intersection, union, difference, etc. But in my experience, sets are most useful in their ability to represent a unique collection of elements with fast membership testing.Of course, it was simple to write a removeDuplicates fn that inserted elements from the array to a map, and back to an array. But that is the point of my parent comment... :)
Once, while writing something in Java, I found out that I needed a Multiset (didn't knew the term) and that Java had a implementation. As strange as it sounds, that made me very productive and confident my code was working... (Of course, soon you're writing getters and setters and hating Java again..)
type Set map[string]int
// Add to set
set["element"]++
// Remove from set
s[el] = max(0, s[el]-1)
// Membership
s[el] > 0
Here's a working example: http://play.golang.org/p/zMvVF1yERcN.B. This is a fiendish way of making good use of "zero" values in Go.
So to me it seems the Set type should be map[string][]type_of_elem, if that is possible.
[edit]
I'm confusing Multiset with Multimap... sorry.
[note]
Actually Multimap/Mutliset is not shipped with Java, but from Google... So it's not that "included".
Yeah. Remember, a multi-set is just a bag. If the bag is `{a, b, a, a, b}`, then it can also be represented as a simple frequency vector: `{a: 3, b: 2}`. There's no need to actually store duplicate values.
> So to me it seems the Set type should be map[string][]type_of_elem, if that is possible.
OK, now I see. It depends on what your definition of equality is. If the entire value represents identity, then my solution works. But if only part of your value (say, some but not all fields in a struct) represents identity, then my approach won't work at all. My approach relies on Go's built in definition of equality, which isn't flexible and cannot be changed. For instance, if you're storing values with this type in your set:
type MyValue struct {
Id int
Tag string
}
And these two values are equivalent: MyValue{5, "abc"}
MyValue{5, "xyz"}
Then you'd have to roll your own implementation. (Since in the eyes of Go, these two values are not equal. And that cannot be changed.)There are elegant ways around this, but it is certainly more clumsy in Go than it would be in a language with some sort of ad hoc polymorphism (like overloading in Java or type classes in Haskell). I think your idea is pretty close:
type MultiSet map[MyValueIdentity][]MyValue
type MyValueIdentity int
Anyway, best of luck to you. Don't be afraid to drop by the #go-nuts channel on IRC. We're a friendly bunch :-)
But I can imagine, seeing how obsessive Google with performance usually is, that it mostly will be rewritten to save "millions of years" in optimizations. I believe Google is mostly using Java and Python.