php to eat, python to grow!

Just saw this gem on reddit: http://www.reddit.com/r/Python/comments/9pd33/dear_redditpy_could_you_help_me_convince_myself/c0dt5wa

Also, good luck on implementing an http-proxy in PHP, the damn thing would have to be huge, ugly and would require at least one PEAR lib to do it the right way.

And for some reason wordpress post by e-mail has a low google ranking, so I thought I should +1 that. Though I personally prefer a clunky interface to an ajax one any day.

Language Performance Analysis

These have to be some of the most interesting things I’ve seen recently:

  1. The Computer Language Benchmarks Game – compare how cpu, memory footprint and source size of all your favorite languages. Also tested is multi-core vs single core and 32 vs 64 bit.
  2. Meta analysis of the above game – visualizes all of the data from the above benchmark. No ground breaking conclusions, but the graphs are very nice to look at.

It’s really interesting to see this information so plainly so one could learn a few ball park performance coefficients. There are a few things that the benchmarks don’t measure ie readability, richness of library, strength and size of the developer  community, etc, but it’s interesting none the less.

Standard library granularity in python, argparse vs getopt

Is it ok that python has 2 modules for option parsing, 3-4 xml packages, 3 HTTPServer modules, etc? This issue hit me when contemplating the deprecation of getopt as a part of the inclusion of argparse. Whenever I want to parse xml/html I get overwhelmed by the options in the std-lib. I remember myself annoyed and confused by getopt/optparse both showing me 2 different ways of doing something so similar. As a newcomer to python, I wanted python to show me the right way of doing things.

So following that line of thought, getopt is the ugly way of doing option parsing. It imitates an option parsing flow that came from the old C days (and thus unpythonic), making it very attractive for people familiar with getopt/xgetopt. So what’s more important: easy learning curve or enforcing best practices?

I wanted to see how ugly getopt code looks so using google code search I found a few real life usage examples.

getopt sample code, or check out the search results yourself:

optparse sample code:

At first I thought the learning curve thing was important, but in the end, getopt is a very unpythonic module that I would rather not see any of my colleagues use at all, except for rare cases where an awful lot of flexibility is needed. For example, getopt could be an easy way to implement optparse, or a completely different alternative. For example pyopt uses getopt in such a way. So IMHO getopt should be in the std-lib, but the documentation should have a very big sign saying “use the awesome optparse/argparse, this is a very simple parser with barely any of the features you probably need”.

Thoughts On Ecosystems And If There Is No Cold

  1. Does a self sustaining ecosystem aquarium/zoo exist? I mean like a closed space with a few different kinds of animals that sustains itself without an external food supply. Of course I’ve heard of a few lakes that only have water coming in and out, but what is the minimum size of a body of water or piece of land that can sustain a non-trivial amount of life?
  2. We like to think of ‘cold’ as the lack of heat. Why? Because there is a minimum of heat, or you could say a maximum of cold. But actually there’s also a maximum of heat, though it probably would be hard to reproduce in a lab. The maximum temperature is what you get when you make all the particles in the world explode thus summing up all their energies into one particle. That one last surviving particle that contains all of the universe’s energy, it’s temperature is MAX_T. So maybe this whole ‘there is no cold’ fiasco was a simplification of the real situation. Hot/cold is just a scalar with two end-points, call it heat, call it coolness, whatever.

Google Code Doesn’t Network

When I search for “pyopt” on google the first result is the PyPI page which is pretty amazing considering it didn’t exist before a few hours. The google code page for pyopt is nowhere to be seen, a search for “pyopt site:google.com” gives only some mathematical optimization module. Strange stuff google, strange. Maybe I should’ve went with github.

update 15-11-2009: now I do get the top ranking search result on google for pyopt but zero results on yahoo search’s first page. Wtf is Peyote? So anyway the conclusion is it takes google at least a week to crawl google-code. Strange.

You Think You Know Pi…

Did you ever think you could compute pi to whatever digit you like? Given a computer, there is no algorithm that can infinitely print out the next digit of pi for ever. Any and all algorithms will eventually run out of memory and break. Sorry. Because your computer is a finite machine with a finite amount of states, eventually your algorithm must repeat itself and pi doesn’t. When I thought this up I was like “holy shit” at first but then I calmed down after realizing knowing pi to any digit was only for people with OCD’s anyway…

Where’s toString?

Why don’t python integers have a smart toString method like java/javascript? It’s easy to convert strings into numbers using int(str_whatever) or float(str_whatever) but to convert them back you have only the decimal system (using str(number) or “%d” % number). In case you want to convert to binary, base32, base36, base64, you’re gonna have to write your own conversion function. Batteries included?

Use either:
http://pastebin.com/f54dd69d6

http://code.activestate.com/recipes/65212/

http://code.activestate.com/recipes/111286/

I added a feature request, lets see if it gets completely shot down:

http://bugs.python.org/issue6783