News for hackers. Stuff that matters.
Re:Most popular Python packages now support Python 3 by keenerd on Saturday December 02, 2017 @02:27PM (#15833531)
Testing 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.

Re:Most popular Python packages now support Python 3 by frou_dh on Saturday December 02, 2017 @02:55PM (#15833676)
This repository was named to emphasise the comedy of its existence :) https://github.com/frou/poor-mans-generics/
Re:Most popular Python packages now support Python 3 by slrz on Saturday December 02, 2017 @05:57PM (#15834716)
Ouch!

  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
  }
Re:Most popular Python packages now support Python 3 by snakeboy on Saturday December 02, 2017 @07:44PM (#15835283)
Re:Most popular Python packages now support Python 3 by frou_dh on Saturday December 02, 2017 @06:22PM (#15834872)
Ick, good point. Since the fake set is a map, that should use key lookup?
Re:Most popular Python packages now support Python 3 by slrz on Saturday December 02, 2017 @06:28PM (#15834923)
Yes. Basically:

  for k := range s1 {
    if s2.Contains(k) {
      result.Add(k)
    }
  }
Re:Most popular Python packages now support Python 3 by bostik on Saturday December 02, 2017 @03:41PM (#15833947)
Yes, the boolean group operations make many otherwise non-trivial problems remarkably easy. That's why I consider sets such a crucial feature.
Re:Most popular Python packages now support Python 3 by jooke on Saturday December 02, 2017 @05:51PM (#15834674)
Could you give some examples please?
Re:Most popular Python packages now support Python 3 by bostik on Sunday December 03, 2017 @04:54AM (#15836857)
Sure, let's get a really simple one.

You have N groups of something (persons, sales units, cars, tools, whatever). Find the values that are present in all of them. This problem comes up, all the time, in some form.

With sets it's trivial. Take the first set, and calculate a cascading intersection with every other set. At the end you're left with only the values that appeared in every one. In very clear python the code might look like this:

    common = ALL_SETS[0]
    for _set in ALL_SETS[1:]:
      common = common.intersection(_set)
    return common
Now, you can argue that underneath the hood that's still going to do N expensive iterations and you'd be right. This is where proper optimisations come in - when provided by a robust stdlib, we expect the set operations to be implemented with bitmaps.[0, 1] These are not something you'd see in a casual implementation.

Btw, in the above code example I have deliberately omitted a trivial optimisation. Let's leave that as an exercise for the reader. :)

0: http://roaringbitmap.org/about/

1: https://en.wikipedia.org/wiki/Bit_array

Re:Most popular Python packages now support Python 3 by keenerd on Wednesday December 06, 2017 @12:32AM (#15858782)
Examples like this really make me miss fold.

    return functools.reduce(lambda x,y: x&y, ALL_SETS)
Re:Most popular Python packages now support Python 3 by slrz on Saturday December 02, 2017 @05:46PM (#15834660)
If sets are a good match for your problem (and I agree, they tend to be for many common ones), you definitely should use them in Go. Just write the fucking code.

Even if you use the most obvious, naive code to implement fundamental set operation in Go, the resulting program is probably still faster than whatever you're going to write in Python.

In the absolute worst case, you need to generate an extra copy to use with some other type. Mildly annoying for sure, but easily dealt with.

Re:Most popular Python packages now support Python 3 by erik_seaberg on Saturday December 02, 2017 @05:57PM (#15834718)
If a hundred people need to write that code anew a thousand times, somebody's going to screw it up. Widely used and heavily tested code is how we get a more powerful foundation to build on.

If the answer is to generate the Go, then we should be having human beings focus on the more powerful language controlling that generator.