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

Re:Most popular Python packages now support Python 3 by c-cube on Saturday December 02, 2017 @01:53PM (#15833331)
Sets 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.
Re:Most popular Python packages now support Python 3 by ZenoArrow on Sunday December 03, 2017 @08:10AM (#15837431)
I 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.
Re:Most popular Python packages now support Python 3 by c-cube on Sunday December 03, 2017 @11:19AM (#15838182)
Agreed, 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.
Re:Most popular Python packages now support Python 3 by xapata on Saturday December 02, 2017 @07:37PM (#15835254)
Set literals are nifty. If they're in stdlib rather than built-in, they can't be literal syntax.
Re:Most popular Python packages now support Python 3 by _mhr_ on Saturday December 02, 2017 @11:13PM (#15835934)
Unless the language has macros.
Re:Most popular Python packages now support Python 3 by xapata on Sunday December 03, 2017 @02:38AM (#15836489)
Touché
Re:Most popular Python packages now support Python 3 by jwilk on Saturday December 02, 2017 @08:46PM (#15835545)
> 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...

Re:Most popular Python packages now support Python 3 by hellcow on Saturday December 02, 2017 @01:47PM (#15833297)
Sets, 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.

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.

Re:Most popular Python packages now support Python 3 by chomp on Saturday December 02, 2017 @01:55PM (#15833342)
Yes 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.