4 ms·
> I believe Google is mostly using Java and Python. Google uses C++ for most compute-intensive code.
by BarkMore 14y ago
> I believe Google is mostly using Java and Python.
Google uses C++ for most compute-intensive code.
- bradfitz 14y agoWe don't use much Python. Mostly C++ and Java.
- SiVal 14y agoIs Google's use of Python growing or shrinking? And how does it compare to your use of Go?
- swah 14y agoThe other day I was surprised to see that Go didn't have sets. After searching Google Groups, it was clear that the rationale is that "sets are easy to implement with hashmaps". 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.
- burntsushi 14y ago> 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. 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.
- swah 14y agoThanks for answering. You're right, but in my case, I was adapting http://norvig.com/spell-correct.html http://norvig.com/spell-correct.html, and the set operation (constructor, actually) was exactly what I needed. 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..)
- burntsushi 14y agoAh, I see. What if you represented a multiset as a map just like in my parent comment, but with integers instead of booleans? 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/zMvVF1yERc http://play.golang.org/p/zMvVF1yERc N.B. This is a fiendish way of making good use of "zero" values in Go.
- swah 14y agoIt seems you're just counting ocurrences? The Multiset actually stores them IIRC. 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".
- burntsushi 14y ago> It seems you're just counting ocurrences? 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 :-)