News for hackers. Stuff that matters.
Re:Python 3 Q&A by a prolific core developer by thu on Friday June 29, 2012 @04:10AM (#4175724)
The following situation happens with other data than just unicode. This seems an argument for static typing in general.

  The reason this approach is problematic is that it means the traceback for an unexpected UnicodeDecodeError or UnicodeEncodeError in a large Python 2.x code base almost never points you to the code that is broken. Instead, you have to trace the origins of the data in the failing operation, and try to figure out where the unexpected 8-bit or Unicode code string was introduced. By contrast, Python 3 is designed to fail fast in most situations[...]
Re:Python 3 Q&A by a prolific core developer by qznc on Friday June 29, 2012 @04:26AM (#4175765)
I agree that static typing would helps for such bugs.

However, not "in general". The general problem is that bogus data leads to an irreparable situation. To fix that bug, you have to find out who broke the data. Consider for example, a circle in a linked list. You would need quite an expressive type system to prevent that statically (dependent types might suffice? Theorem provers are the ultimate hammer).

Re:Python 3 Q&A by a prolific core developer by DannoHung on Friday June 29, 2012 @05:08AM (#4175847)
Uhh, how would you make a linked list with a circle in it with the Haskell List type?
Re:Python 3 Q&A by a prolific core developer by dbaupp on Friday June 29, 2012 @05:31AM (#4175895)

  a = 1:a
Re:Python 3 Q&A by a prolific core developer by ufo on Friday June 29, 2012 @09:29AM (#4176491)
This trick is often called "Tying the Knot", if anyone is interested.
Re:Python 3 Q&A by a prolific core developer by qznc on Friday June 29, 2012 @05:33AM (#4175897)

  makeCircle rst = rst ++ makeCircle rst
The thing is that a circular list is actually an infinite list in Haskell. ;)
Re:Python 3 Q&A by a prolific core developer by DannoHung on Friday June 29, 2012 @11:27AM (#4177077)
If you want to prevent that then you want to take general recursion out of your programming language and if you're gonna do that you might as well make it Turing incomplete.

These aren't "circles" per se, they are partially evaluated recursive structures. If you expand them you end up with evaluated list structures that are non-self referential.

Re:Python 3 Q&A by a prolific core developer by ufo on Friday June 29, 2012 @09:31AM (#4176494)
This is not a real circular list though, since it does not tie the knot as in dbaupp's comment.
Re:Python 3 Q&A by a prolific core developer by zanny on Friday June 29, 2012 @04:43AM (#4175807)
Different implementations for different use cases in different situations :P
Re:Python 3 Q&A by a prolific core developer by gardentheory on Friday June 29, 2012 @04:27AM (#4175766)
Well the lighter solution and more Pythonic solution is strong typing. If a Unicode string and a byte string could not be combined then the problem would not exist AFAIK. For example "a" + 1 is an error, why is u"a" + "s" not an error?
Re:Python 3 Q&A by a prolific core developer by masklinn on Friday June 29, 2012 @05:20AM (#4175872)
> For example "a" + 1 is an error, why is u"a" + "s" not an error?

"a" + b"s" is an error in Python 3.

Re:Python 3 Q&A by a prolific core developer by gardentheory on Friday June 29, 2012 @01:33PM (#4177846)
Sorry, that was my point. Strengthening the types in python3 solves the problem without static typing being needed at all.
Re:Python 3 Q&A by a prolific core developer by masklinn on Friday June 29, 2012 @03:05PM (#4178449)
ok.

Static types solve it earlier though, especially for little-exercised code paths which could be forgotten or missed in testing.

Re:Python 3 Q&A by a prolific core developer by xerula on Friday June 29, 2012 @04:31AM (#4175776)
But b"s" + "a" is an error in Py3.
Re:Python 3 Q&A by a prolific core developer by qznc on Friday June 29, 2012 @05:03AM (#4175841)
This just gives a different error message. It does not help to find the error source.

The programmer would probably just try to fix it via str(u"a")+"s" or u"a" + unicode("s").

Re:Python 3 Q&A by a prolific core developer by slurgfest on Friday June 29, 2012 @10:53AM (#4176879)
It is an argument for failing fast in general. Static typing isn't guaranteed to pick up every mistake at its origin, because far from every mistake is of the "int rather than string" variety.

Since you have brought up the general case, the origins of many bugs involve something sophisticated going wrong which would require you to encode much of your program (hopefully not too redundantly) into a Turing-complete type system. Rather than stuffing square pegs into round holes, you could just write the appropriate error handling code (or even just asserts).

Re:Python 3 Q&A by a prolific core developer by earl on Friday June 29, 2012 @02:22PM (#4178186)
Please:

   alias hncomment='fold -w 77 -s | sed "s/^/   /" | pbcopy'

   use:
   echo "blah blah blah" | hncomment
   command-v
Thus:

     The reason this approach is problematic is that it means the traceback for 
   an unexpected UnicodeDecodeError or UnicodeEncodeError in a large Python 2.x 
   code base almost never points you to the code that is broken. Instead, you 
   have to trace the origins of the data in the failing operation, and try to 
   figure out where the unexpected 8-bit or Unicode code string was introduced. 
   By contrast, Python 3 is designed to fail fast in most situations[...]