Python: teaching kids and biting bits don't mix

April 9th, 2008

Today an important thing happened in my professional life. I was told to take a break from The Top Priority Project, so that I could deal with a more important project. The evaluation of the expression max_priority+1 caused my wetware registers to overflow. Therefore, you should consider the following piece of whining as an attempt of a brain to recover from deadline damage. That is, you won't get the kind of deep discussions and intellectual insights you've come to expect from yosefk.com. Instead, you'll get shallow, plain, simple and happy Python hate. That's the kind of thing we have in stock right now.

It has been known for quite some time that a specie called the Idiot is out there, and its revolting specimens will mercilessly prey on your belief in the future of the human race. The time has come for me to share with you some of the shocking experience from my encounters with idiots. Believe it or not, there exists a kind of Idiot who sincerely thinks that a Person should not complain about Technology or Tools he or she gets to use, and that such complains are deeply wrong on this or other level, depending on the exact idiot in question. Well, I hereby inform the idiots, at least the ones who can use a browser and read text, that I (1) have a bad attitude, (2) am not a good workman, so (3) I'll complain about any technology I use as I damn please and (4) I don't give a flying fuck about your moronic opinion, so don't bother to share it with me.

So, Python hate. I don't really hate Python; it's a figure of speech. You know what I really hate? Of course you do. I hate C++. C++ is the hate of my life. I don't think I'll ever be able to hate another programming language. For me, to hate means to recognize that something is inherently evil and should be exterminated. Reaching that status is outstanding achievement for any technology. Your typical piece of software never gets that far. All it does is it does something you need most of the time, and then does something extremely brain-damaged some of the time. So you kinda like it, but sometimes it just pisses you off. It's gotta piss you off. It's a machine. It's doesn't have a pigeon crapload worth of common sense. Of course it pisses you off. Don't lie to me! A person who was exposed to machines and doesn't hate them is either an idiot or is completely devoid of soul! Step back, the child of Satan!

You know what really pisses me off about Python? It's the combination of being BDFL-managed and having roots in the noble idea of being The Language for Teaching. Sure, having lexical scoping wouldn't hurt, and having name errors 5 minutes down the road in a program that happily parses already hurts, and Python shells aren't a picnic, blah blah blah. But nothing is perfect, you know, and people adapt to anything. I learned to live in tcsh and vim as my IDE. So I know how adaptability can bring you quite far, sometimes much farther than you wish to get. But this BDFL+teaching combo really bugs the hell out of me. Allow me to elaborate.

Ever heard about programming languages with an ANSI standard? Sure you did. Well, the other kind of languages have a BDFL standard. It's when a Benevolent Dictator For Life, typically the Punk Compiler Writer (PCW) who invented the language and threw together the initial (and frequently still the only practical) implementation, decides what happens with the language. I plan to blog about PCWs at some point, but this isn't about PCWs in general, this is about PCWs who've been elevated to the BDFL rank. So they bend the language as they damn please. Sometimes it splits the user community (as in Perl 5 vs Perl 6) and sometimes it doesn't (as in Python 2 and Python 3, or so it seems). I'd say that it's totally stupid to use a BDFL-governed language, but I can't, because that would offend C++, The Hate Of My Life, who does have an ANSI standard. Relax, darling. It's you, and only you, that I truly hate. The others mean nothing to me.

So that's what the "BDFL" part means. The "teaching" part is about Python being supposed to be a good (the best? of course, the best) language for teaching kids how to program. While I'm not sure whether the BDFL part is inherently wrong, the teaching part is sure as hell wrong, in two ways:

  1. Why the fuck should kids program?
  2. Why the fuck should I program in a language for kids?

I didn't program till the age of 17, and I have absolutely no regrets about it. I know quite some other programmers-who're-really-into-software-someone-call-for-help who didn't hack in their diapers, either. I also know a bunch of people who did program since they were 10 to 12 years old. They are all burnt out. They're trying to look for some other occupation. Theater, psychology, physics, philosophy, you name it. I haven't gathered that many data points, just a couple dozens. Some people won't fit the pattern I see. But it's enough for me to assume that kids could have better things to do than programming. Watching cartoons is one thing that sounds like fun. That I always liked.

I'm not sure kids shouldn't program. We need scientific data on that one. I'm no specialist, but locking a large enough set of kids in the basement and have them implement progressive radiosity sounds like a good start. Anyway, as you probably noticed, while I'm curious about the scientific truth, I don't care much about kids. I care about me.

Me. I'm a professional programmer. By which I mean to say, I shovel through piles of virtual shit for a living. And to shovel quickly and happily, I need a big shovel. Python is one of my shovels. Core dumps are one of my piles of shit. Python, meet the core dumps. Core dumps, meet the Python.

Core dumps are spelled in hexadecimal. I mean "core dumps", "spelled" and "hexadecimal" in the broadest sense, as in "things having to do with machine encoding and that sort of low-level crud are viewed and edited in tools that tend to emit and consume integers in hexadecimal notation". Or "core dumps are spelled in hexadecimal" for short.

To deal with hexadecimal, Python has a hex() function and a '%s' format string like it should. Well, almost. Python thinks that hexadecimal is like decimal, except in base 16 instead of 10. Integers are naturally spelled in sign magnitude format: 1, 10, -1, -10. In hexadecimal, that's 0x1, 0xa, -0x1, -0xa. "-0x1"? "-0x1"?!! FUCK YOU, PYTHON!!

You see, all computers that have been out there since the year 19-something store integers in 2's complement format. There used to be 1's complement and sign magnitude machines, but they are all dead, which is a good thing, because 2's complement is a good thing. In 2's complement, -1 in hexadecimal is 0xffffffff. If you use 32-bit integers. And twice the number of f's on 64-bit machines. Do I give a flying fuck about 64-bit machines? I think you know the answer. If I cared, I'd run Python on a 64-bit host. An old version of Python.

In old versions of Python, hex() worked about right. Python has ints and longs (that's fixnum and bignum in Lisp, and it would be int and BigInteger in Java if ints didn't overflow but would instead turn into BigIntegers when int wouldn't have enough bits). hex() assumed that if you're using ints, you're a bit biter, and you want to get 0xffffffff for -1, and you should get your non-portable, but handy result. If, on the other hand, you used longs, you probably were a mathematician, so you'd get -0x1. And this was juuuust riiiight.

However, starting from version 2.something, hex() was "fixed" to always do "The Right Thing" – return the portable sign magnitude string. That, my friends, is what a kid would expect. You should know – you were a kid yourself, didn't you expect just that?! Naturally, breaking the frigging backwards compatibility is perfectly OK with the PCW BDFL, who sure as hell doesn't want to add another function, sex() for "sexadecimal". That function could (preferably) do the new thing, and hex would do the old thing to not break the existing programs. Or it could (passably) do the old thing so that people could at least get the old functionality easily, even though hex() would no longer work. But noooo, we need just one hex function doing the one right thing. Too bad we only found out what that right thing was after all those years went by, but in retrospect, it's obvious that nobody needs what we've been doing.

Now, could anybody explain me the value of hexadecimal notation outside of the exciting world of low-level bit fucking? Why on Earth would you want to convert your numbers to a different base? One particular case of this base brain rot is teaching kids to convert between bases. As Richard Feynman has pointed out, and he had the authority to say so and I don't and hence the reference, converting between numbers is completely pointless, and teaching kids how to do this is a waste of time. So what you do is you give me, the adult programmer with my adult core dump problems, a toy that a kid wouldn't need or want to play with. Thank you! You've found the perfect time, because I have a DEADLINE and this fucking shit CRASHES and I couldn't possibly have BETTER THINGS TO DO than WASTING TIME ON CONVERTING BASES!!

I know that I can implement the right (yes, THE RIGHT, damn it) hex and put it into my .pythonrc and that would solve the interactive shell annoyances and I could carry it around and import it and that would solve the non-interactive annoyances, thanks again. Until now I've done it in a cheaper way though – I had a Python 2.3.5 binary handy, and that did the trick. 2 Pythons, one with new libraries and shiny metaprogramming crap and stuff, and one with a working hex(). I like snakes.

Why do I attribute this business to kid-teaching, of all things? I don't lurk on Python forums, so I'm basing this on rumors I heard from die-hard Python weenies. Another, TOTALLY INFURIATING thing: a/b and a//b. int/int yields a frigging FLOAT in Python 3!! This has all the features of hex(-1) == '-0×1':

You know, I'm actually more willing to upgrade to C++0x, whenever that materializes, than I am willing to upgrade to Python 3. At least it would be "for(auto p=m.begin()..." instead of "for(std::map<std::string,std::string>::const_iterator p=FUCK OFF AND DIE YOU EVIL PROGRAMMING LANGUAGE FROM HELL!!".

What's that? Who said I liked C++0x more than I liked Python 3?! Upgrade, I said, "willing to upgrade"! Don't you see it's relative to the previous version? In absolute terms, who can beat C++?! Come back, C++! I still hate you!!