[Python-ideas] Ruby-style Blocks in Python Idea [with examples]

Leif Walsh leif.walsh at gmail.com
Wed Mar 11 08:25:16 CET 2009


Apart from the fact that I don't think blocks are needed for any of the above, I feel compelled to poke a hole in one of your examples:

On Mon, Mar 9, 2009 at 2:47 PM, tav <tav at espians.com> wrote:
> # Django/App Engine Query
>
> Frameworks like Django or App Engine define DSLs to enable easy
> querying of datastores by users. Wouldn't it better if this could be
> done in pure Python syntax?
>
> Compare the current Django:
>
>  q = Entry.objects.filter(headline__startswith="What").filter(pub_date__lte=datetime.now())
>
> with a hypothetical:
>
>  using Entry.filter do (entry):
>      if entry.headline.startswith('What') and entry.pub_date <= datetime.now():
>          return entry
>
> Wouldn't the latter be easier for a developer to read/maintain?

Probably, but it doesn't matter, since Django lazily evaluates chained querys, and doesn't actually evaluate anything until you tell it you want elements.  I don't believe there's any way to do this with blocks.

-- 
Cheers,
Leif

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090311/0c9917d2/attachment.pgp>


More information about the Python-ideas mailing list