I do quite a lot of futzing around developing web apps, and as a result I'm often needing to choose colours to use in them, and I want those colours in HTML hex form – e.g. #ff0000 (bright red). The standard Mac OS X colour picker is a pretty reasonable colour picker, with all the features I want: colour wheel, RGB sliders, HSB sliders etc. but it lacks the most crucial feature – easy output of HTML hex codes! This is clearly a criminal omission, and it meant I'd frequently have to convert from RGB 0-255 numbers down to hex, which is tedious in the extreme.
I've been banging away at my Google App Engine application. It'll be a little while yet, but in the meantime, a particular observation about Python. I keep getting tripped up when I refer to a member function without the parenthesis. For instance:
I like witbiers and have always found Hoegaarden to be a classic example. It's a shame that it's another example of a decent beer getting bought out by the faceless mega-corporation – InBev in this case. Read about the history of Hoegaarden Brewery at Wikipedia.
This is a tight crop of the front of the 'cable car' that runs up the hill in Wellington, New Zealand. It was absolutely bucketing it down, and windy too, so we never got to walk back down through the botanical gardens as we planned.
My MacBook laptop has had to go in for repair as a sliver is splintering off the plastic palm-rest where the lid touches it at the edge. There are also myriad hairline cracks appearing in the bottom shell around the front and back. The repair guy I took it to assured me this wasn't my fault and that it would be covered under warranty, which is good since I've got less than a month left on the year long warranty. Phew!
Look at this little fella – isn't he cute! Taken this morning amid preparations for wassailing in the orchard.
Another 'what I had for dinner' post. Sorry.
I've spent a bit more time learning Python, because I've been dabbling with Google App Engine (which I'm going off rapidly) but mainly because it's an interesting language. What's particularly intriguing to me is its similarity to Ruby, and hence where it differs in syntax or approach makes for a notable point of comparison. Of course it's probably more correct to say that Ruby is similar to Python than the other way around. From my still very small exposure to Python…
- Less confusion with the way classes work. Or maybe I just haven't stumbled into Python's equivalent of meta-classes and class vs instance variables.
- @classmethod is a much neater way of stating what's a class method rather than an instance method, compared to all that self gubbins, or the dreaded <<.
- Optional named arguments for functions, allowing more flexibility for optional arguments and greater clarity when calling. [As an aside I like Objective-C's way of building argument labels into the method signature, but not it's square brackety syntax: [obj message:foo]. I'd much rather do obj.message(foo) and in fact with properties in Objective-C 2.0 we see more of this style.]
- I think I probably prefer explicit return statements rather than the Ruby way of returning the last evaluated thing in any expression.
- List comprehensions. To start with it just seems like a syntactic difference – Python: [x*2 for x in my_list] Ruby: my_list.map {|x| x*2}. But Python's party trick is excluding elements as it goes: [x*2 for x in my_list if x != 3].
Nasty things about Python:
- Seriously – indentation to demarcate blocks? Apparently I'll get used to it.
- Double underscores. __init__ is a complete pain to type. Why not just a single underscore at the start or something?
- Fiddly module system. Why the need for an __init__.py file in a directory, just to make it a module? Why the need to explicitly define an __all__ method just to be able to import everything in a module? I want to be able to create a "model/" directory, put all the .py files for my DB classes in there, then import the whole lot from my other classes with ease. When I add a new model class, I shouldn't have to go and modify the __init__.py file. It seems to be a real pain to split code up into multiple files sensibly in Python. If I've missed a trick here – please somebody show me the light!
- The string interpolation is OK I suppose, giving the full power of C style formatting, but most of the time you're just doing simple interpolation and Ruby's syntax is far more pleasant and readable. Python: "Hello %s, from %s." % (person, greeter) Ruby: "Hello {person}, from {greeter}." Ruby also has a full on formatting system for the few times when you need it.