4 ms·
Not very compelling at the moment considering how few examples there are. But fully explaining why Python 3 is worth it is at this point, actually quite hard. T
by jchw 9y ago
Not very compelling at the moment considering how few examples there are. But fully explaining why Python 3 is worth it is at this point, actually quite hard. Things like better Unicode support, type annotation syntax, and removal of old school classes are some of my favorite reasons.
Also, when making kwarg only functions, you don't need to name the rest args parameter. You can do this:
def a(a, b, *, options=None):
I think this case also enforces that you don't add any additional positional arguments that go unused.
- Animats 9y agoUnicode support and new style classes were in Python 2.7. Type annotations that don't do anything are one of the worse ideas I've ever seen in a programming language. Optional type annotations that are checked and used for optimization would be fine. But what's gone in is useless. Also, the syntax, which puts some type information in comments, is lame. Python 3 isn't bad at this point. The first few years of Python 3 really sucked. The syntax was less compatible, and particularly hard on those who used Unicode in Python 2.7, because u'abc' was prohibited. "2to3" didn't work very well. Many, many libraries were not converted. The newer libraries for Python 3 were buggy due to being underutilized. Python 3 before Python 3.3 was quite bad. Most of that's been fixed. The "six" module was a big help in porting. Eventually, "u'abc" was allowed. Most of the libraries were ported and available and debugged on both 2.7 and 3.x. But it took many years, and gratuitous incompatibilities made it harder than necessary. It's fitting punishment for Von Rossum that he's forced to maintain the Python 2.7 system at his day job at Dropbox.
- dragonwriter 9y ago> Type annotations that don't do anything As in any language, they “do something” in Python, to wit, enable static type checking. Now, static type checking is provided by systems separate from the language implementation, but the still exists. > Also, the syntax, which puts some type information in comments, is lame. The comment-based component of the syntax is a compatibility feature for Py 2.x.
- Animats 9y agoNow, static type checking is provided by systems separate from the language implementation, but the (sic) still exists. That's almost a direct quote from the static typing proposal. No such checker existed at the time. There's a half-completed one, "mypy".[1] It's a bit different from Python 3.6 type annotation, though it tries to stay close.
- pddubs 9y agoI think mypy can be considered the canonical type checker for python, Guido van Rossum works on that project. It uses python 3.6 type annotations fully as far as I know.
- joshuamorton 9y ago> But what's gone in is useless. Also, the syntax, which puts some type information in comments, is lame. This is only the case in python2. In python3(.6), I don't believe there is any type information that cannot be expressed only in comments.
- canjobear 9y ago> Unicode support and new style classes were in Python 2.7. Unicode support is tremendously easier in Python 3. You don't have to deal with the confusing encode and decode stuff, and Python 3 strings have the right behavior in a lot of weird cases where Python 2.7 unicode objects do not. Unicode support was my biggest reason for switching to Python 3, because I was dealing with natural language data with a lot of emojis and Python 2.7 was just an endless headache.
- mjevans 9y agoI actually argue that it's worse. In Python 3 you are FORCED to deal with unicode encoding; Python 3 does not react well with legacy data that should just be handled as is (without making things worse or incompatible). The alternative is to use a byte array without an encoding, which would be OK if Python 3 made coercion between the two easy (and had the concept of a 'validated' unicode string; operations known to keep a unicode string valid could leave that set, otherwise it would be 'not validated' but you wouldn't /need/ to care).
- zzleeper 9y agoThat prevents lots of mistakes. You only specify encodings while reading external data, and then everywhere else in your code you know you are dealing with strings and that's it (instead of your code working until a random Fóréígner trips it out)
- dbcurtis 9y agoWell, I spend most of my time dealing with internet and serial protocols, and the strict demarcation between unicode strings and byte strings is what keeps me sane. Explicit encode/decode calls are a feature, IMHO.
- Avernar 9y agoI wouldn't mind the strict demarcation if the internal format was UTF-8. Then a simple validate call on input would be all that was needed.