Posts tagged: PROGRAMMING

Two new Django-powered sites

One of the neat things about PyCon, even for those of us who aren’t attending, is that people save up goodies to announce and release during the conference. Django is certainly a hot topic at this year’s PyCon, and as of today at least two significant new Django-based sites have launched:

One is CheeseRater (great name!), from Jacob Kaplan-Moss, a quick-rating system for items in the Python community’s official package index, the Cheeseshop. In other words, if you think PyOMFG is the greatest module ever you can vote it up, and if you notice that PyFlockOfSeagulls hasn’t been updated since 1992 you can vote it down. The Cheeseshop is one of several pieces of python.org that I’ve thought could benefit from the application of some crowd wisdom; Jacob gets a prize for taking action. It will be interesting to see how this evolves.

Neat Python hack: infix operators

I came across this neat Python hack on reddit today, a technique for defining arbitrary infix operators. Not overriding + or >> et al., but creating keyword-style pseudo-operators that… well, the code is probably as clear as any description I could come up with:

class infix(object):
    """
    Clever hack (slightly modified) for defining infix operators. 
    Via http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122
    Intended for use as a decorator.
    
    >>> @infix
    ... def removing(str, chars):
    ...     for char in chars:
    ...         str = str.replace(char, '')
    ...     return str
    ...
    >>> print 'Hello, world!' |removing| 'eo'
    Hll, wrld!
    """
    def __init__(self, function):
        self.function = function
    def __ror__(self, other):
        return infix(lambda x: self.function(other, x))
    def __or__(self, other):
        return self.function(other)
    def __call__(self, value1, value2):
        return self.function(value1, value2)

Some people hate this kind of stuff. That’s why we call it a hack, to indicate that we don’t think it’s a great building block for your missile control software. Some of Those People still get their underoos in a bunch regardless. But you have to admit it’s damned clever.

Dreaming In Code: The Interview

Dreaming in Code Over on the Well we’re having a discussion with Salon.com co-founder (and longtime Well member) Scott Rosenberg about his new book, Dreaming in Code. The book follows the Chandler project – conceived as a radical reinvention of the personal information manager – from its inception in 2002 through… well, through multiple stalls and restarts that lead not to a triumphal “Rocky of software” finish but to our embedded journalist moving on after deciding he just can’t wait any longer. Oddly, this a more satisfying ending; more honest, more interesting, and, for most programmers, more painfully familiar. It’s a postmortem on a project that hasn’t actually died.

Interview with TextMate creator Allan Oddgaard

Over at Rands in Repose there’s a nice, if short, interview with Allan Oddgaard, creator of my favorite text editor TextMate.

For me the core of TextMate’s power comes from its bundle and scope systems. Allan has a little bit to say about that in the segment of the interview about sources of inspiration:

A big non-editor inspiration was CSS selectors which is what I recreated as scope selectors. The first time I read the CSS specification I was pretty excited to try out the concept. Unfortunately I did not have access to any browser which implemented it, so I started writing my own implementation, though I never got very far with it. Still, a seed had been planted and on an unconscious level I have probably tried to find a place where I could implement them, ever since.

Yegge's crusade

I’m generally a big fan of Steve Yegge’s rants. See this earlier post for links and quotes from some of my favorites. His writings were a significant influence in my decision to seriously look for a new language to learn in 2007 – I even bought Programming Language Pragmatics on his recommendation, piecemeal reading of which has definitely expanded my thinking (as well as dredging up parts of that Compiler Construction course I took back in 1989…).

Learning Haskell inch by inch

I did some more Haskell reading over the long weekend, mostly from Yet Another Haskell Tutorial*. There is definitely some challenging stuff (the Monads chapter in A Gentle Introduction to Haskell begins, ‘This section is perhaps less “gentle” than the others…’).

Overall, though, the combination of elegance and power and consistency in Haskell is very satisfying. The language has very little to apologize for.

I’m not really able to write much code yet, but I’ve started to be able to read it. I’m playing with adding Haskell coloring to dpaste, via the HsColour colorizing engine (written in Haskell, naturally). In trying to track down some formatting glitches – which may well turn out to be in my code, not theirs – I was actually able to look at the HsColour source and kind of understand how it does its thing.

The whitespace brigade

Syntactically significant whitespace is one of those debating points frequently raised in unproductive language thrashes involving Python. One persistent implication made by SSW-haters is that it’s a freakish mutation unique to Python. Or, if they’re feeling particularly vicious, they’ll bring up Fortran. Cold comfort.

In fact, there are quite a few other languages that have gone down this path. Flipping through a big fat book that I bought because Steve Yegge recommended it, I came across mention of a couple that were new to me. Then I went digging for more. Here’s an incomplete list: