Entries in category “Programming”

Making magic

Published December 3, 2007

In yesterday’s article I spent a fair amount of time talking about the word “magic”, specifically in the context of Clarke’s Third Law, which states that

Any sufficiently advanced technology is indistinguishable from magic.

A big part of what I was getting at was that a lot of things which seem to be explicable only by appealing to “magic” are really just cases of technology — sometimes extremely simple technology — being used in a ...

Read full entry and comments

Clarke’s Third Law

Published December 3, 2007

Every so often, a TV producer who wants to get ratings will air a “documentary” about some wonder of the ancient world. Say, the great pyramids at Giza. The formula for this “documentary” is pretty simple: you get a bunch of people from modern, industrialized nations to go crawl over these huge ancient monuments in Egypt and speculate on how those ancient Egyptians managed to build them. And, inevitably, a lot of these people will ...

Read full entry and comments

Be careful with your URL patterns

Published October 14, 2007

Tonight in the Django IRC channel, someone stumbled across a seemingly-odd error when trying to use a generic view:

TypeError: object_list() got multiple values for keyword argument 'queryset'

The problem turned out to be the URL pattern which was routing to the generic view. Consider a simple example, as might be found in a weblog application:

from django.conf.urls.defaults import *
from weblog.models import Entry

info_dict = {
    'queryset': Entry.objects.all()
}

urlpatterns = ('',
    (r'^(index ...

Read full entry and comments

The types will save us!

Published April 1, 2007

So, that went over well. My goal was simply to point out that strong and static typing are not the same thing (and, correspondingly, that weak and dynamic typing are not the same thing), and somehow the comment thread got derailed into people trotting out exotic type systems and theoretical work to try to prove… well, I’m not sure exactly what they want to prove. But one big thing that seems to be causing ...

Read full entry and comments

Typo

Published March 26, 2007

One of the great holy wars in programming concerns itself with “type systems”, usually in the sense of “static typing” versus “dynamic typing”, and from time to time it flares up again. Unfortunately, most of the loudest voices are quite content to argue without really understanding the subject, and so proceed to build straw-man-style arguments based on what they think they know. Most often this seems to be a result of inexperience — far too many ...

Read full entry and comments

About model subclassing…

Published February 20, 2007

In Django 0.90 and 0.91 we offered the ability to subcless models, and a nasty hack called replaces_module which would let you tell Django to use a subclass in place of the original model it was inheriting from. The magic-removal changes broke that ability, and we’ve been slowly working toward getting it back (well, actually Malcolm has been rolling the Sysiphean rock up the hill and the rest of us have mostly ...

Read full entry and comments

The JavaScript knowledge gap

Published February 16, 2007

JavaScript is a paradox of a language. It has nearly universal availability in its target market — client-side Web scripting — and is a major component of “Web 2.0”, but very few people actually write or even really know JavaScript. Many “modern” web-development frameworks remove the need for that by offering direct translation from some other language to JS, or by offering “helpers” which generate and include JavaScript automatically. And even among the few folks who ...

Read full entry and comments

Choosing a JavaScript library

Published January 22, 2007

Previously we looked at some objections to JavaScript libraries and some possible responses. Now it’s time to ask a bigger question: do you need a JavaScript library, and if so how should you go about choosing one? I’m not going to recommend any particular library, because I don’t think there’s such a thing as one-size-fits-all in web development, but I can list a few things which are useful to keep in ...

Read full entry and comments

Let’s talk about JavaScript libraries

Published January 15, 2007

JavaScript’s got a bad rap; it’s the language everybody loves to hate, and the one language which, more than any other in the modern web developer’s toolbox, people will go to insane lengths to avoid writing directly (witness Google Web Toolkit, JavaScript “helpers” in server-side frameworks, etc.). Which isn’t fair, really, because (as I’ve said many a time) most people don’t actually hate JavaScript the language; they hate the ...

Read full entry and comments

I can’t believe it’s not XML!

Published December 21, 2006

As you may or may not have heard, JSON came to Dave Winer’s attention today. He is, quite obviously, of the opinion that this is just a reinvention of what people are already doing just fine with XML, thank you very much, so what’s the point?

Of course, this ignores the fact that the Lisp folks have been making the same argument for years, wondering why there was this great pressing need to ...

Read full entry and comments

Programming tips: learn optimization strategies

Published November 5, 2006

Recently I spent a little time talking about the tradeoffs between “concise” code and readable code in Python. Throughout that entry, I was using as an example a simple function which calculates numbers in the Fibonacci sequence; here’s one variation:

def fib(n):
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)

The Fibonacci sequence is a classic example from introductory programming materials, because it teaches recursion, and recursion is an ...

Read full entry and comments

Python tips: don’t be too concise

Published October 28, 2006

There’s an inherent tendency programmers have to take a piece of code and reduce it to the shortest possible form. The holy grail is, of course, cutting something down to a single line of code while still providing the same functionality; reducing a particular piece of code to a “one-liner”, especially if the code is somewhat complex, is sometimes viewed as a measure of a programmer’s intelligence or talent or both, and is ...

Read full entry and comments

How I got here

Published October 16, 2006

I’m not a formally-trained programmer. I wasn’t a computer science major in college (my degree is in philosophy), and my first job after graduation didn’t involve programming (it was phone-based customer service at a health-insurance company). But here I am, developing software for a living.

I’ve never written a compiler. I’ve never hand-tuned something by dropping in bits of assembly, or even by writing C extensions for an interpreted language ...

Read full entry and comments

The functional language that’s right under your nose

Published October 11, 2006

Recently I’ve been getting an itch to learn a functional programming language. I’ve made a couple attempts on Lisp over the years, with mixed results; I can write fairly basic Common Lisp, and hack on Emacs a bit, but I’ve never advanced much beyond that. I’d been looking at some of the trendy, popular functional languages (well, popular among certain circles) like Haskell, OCaml and Erlang, when I remembered that I ...

Read full entry and comments

Django tips: using properties on models and managers

Published August 18, 2006

While working on a little side project this week, I ran into a couple of very common use cases that often result in a lot of extra typing:

  1. Defining a BooleanField, or an IntegerField or CharField with choices which will, logically, break up instances of the model into certain groups which need to be accessed often.
  2. Repeatedly wanting to calculate a value based on the values of several fields of a model.

Let’s look ...

Read full entry and comments

Quick note for pydelicious users

Published August 15, 2006

If, as I do, you use pydelicious to handle automatically posting links to del.icio.us, you’ll want to take note of the fact that the switch of the del.icio.us API‘s location, previously announced, has happened.

It doesn’t look like pydelicious has updated (and given the spamfest that is their Trac, I wonder if it’s being maintained), so in the meantime here’s the quick fix:

Crack open pydelicious ...

Read full entry and comments

Django tips: A simple AJAX example, part 2

Published August 5, 2006

Last time around we looked at how to write a simple view which processes a form and either returns errors or returns success, and then tweaked it slightly so that the same view could handle either a “regular” form submission (in which case it operates normally), or an XMLHttpRequest (in which case it returns JSON).

Today we’ll look at writing the JavaScript side of it; for reference, here’s the live example we’re ...

Read full entry and comments

Django tips: A simple AJAX example, part 1

Published July 31, 2006

One thing that’s come up over and over again in the Django IRC channel and on the mailing lists is the need for good examples of “how to do AJAX with Django”. Now, one of my goals in life at the moment is to try to fill in the gaps in Django’s documentation, so…

Over the next couple of entries we’re going to walk through a very simple form, which will submit ...

Read full entry and comments

Helpers, scaffolding, tradeoffs and other stuff

Published July 17, 2006

In one of the very, very few coherent things I’ve seen him say in comments posted here and elsewhere, one Lucas Carlson brought up the other perceived advantage of JavaScript helpers: they save time:

Sure it is possible to add javascript helper functions to Django, and yes that would speed up initial development times and reduce bugs since Python is usually more terse than JS… even for expert JS programmers.

I’m going to ...

Read full entry and comments

Django tips: Hacking FreeComment

Published July 16, 2006

Django’s bundled comments application (found in django.contrib.comments) is incredibly useful; it gives you a nice, out-of-the-box system for adding comments to any site. But, if you look at it closely, really feels more like two applications:

  1. The Comment model and its helpers, which only allows registered user accounts to post comments.
  2. The FreeComment model and its helpers, which allows anyone at all to post comments.

The first one — based around Comment — is ...

Read full entry and comments

Let’s talk about Python and Ruby

Published June 18, 2006

As a result of various things I’ve been reading up on recently, I’ve been exposed to far too many Python vs. Ruby flamewars. As someone who’s used both languages (though I’ve got much more experience with Python, and a Python-based framework is now how I make my living), I think they both solve similar problems in slightly different syntactical ways, and are pretty much equivalent on functionality.

But the debates, when ...

Read full entry and comments