-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alec Warner wrote:
> On Tue, Feb 10, 2009 at 2:53 AM, Douglas Anderson <d...@gendja.com> wrote:
<snip>
> belongs.py has this gem:
> q.append(('^' if query[0] == '/' else '/') + re.escape(query) + '$')
> 
> I realize it works; but honestly, not readable.
> 
> append_str = ""
> if query[0] == '/' append_str += '^' else append_str += '/'
> append_str += re.escape(query) + '$'
> q.append(append_str)
> 
> Slightly better (if append_str has a shorter name, maybe).  I don't
> like 1 line if EXPR STATEMENT else STATEMENT but sometimes they are
> shorter
> Putting a conditional in the function call is horrible looking though.

It's called functional programming. Maybe it takes a little getting used to, but
as your own example shows, it can cut your code base by a significant factor.

Marijn


- --
Sarcasm puts the iron in irony, cynicism the steel.

Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmUB54ACgkQp/VmCx0OL2wIOQCfdd0U1TJ/GXxTwvV8vmMpW2u9
hfsAoIXkWvJP8sOGK4NstuXiCAgy5OIf
=qfq4
-----END PGP SIGNATURE-----

Reply via email to