Simon Willison wrote:

a = request.GET.as_int('a')

Looks like I will be the one breaking the party :-)

I don't like this idea for two reasons.

The first is simple: it makes code ugly and much less readable. I had this experience with Delphi where you have always do something like Table.FieldByName('Title').AsString.

The second reason is that it breaks DRY: you have to specify types manually while somewhere in the system there is already a knowledge about of what type should be this thing.

In many cases you just don't need to know the type. For example if you just compare things like

if request.GET['a']==5:

then for any non-numerical string it should be just as 'False' as with, say, 3. On a similar note I'd like to propose even changing request.__getitem__ to return None instead of raising exception when there is no key. I find myself writing request.GET.get('a',None) way too often...

There is of course place where typing is needed. It's when data is stored in db. But Django already has such filtering in the form of do_html2python in manipultors. Why is it not enough?

Reply via email to