1 |
-----BEGIN PGP SIGNED MESSAGE----- |
2 |
Hash: SHA1 |
3 |
|
4 |
Alec Warner wrote: |
5 |
> On Tue, Feb 10, 2009 at 2:53 AM, Douglas Anderson <dja@××××××.com> wrote: |
6 |
<snip> |
7 |
> belongs.py has this gem: |
8 |
> q.append(('^' if query[0] == '/' else '/') + re.escape(query) + '$') |
9 |
> |
10 |
> I realize it works; but honestly, not readable. |
11 |
> |
12 |
> append_str = "" |
13 |
> if query[0] == '/' append_str += '^' else append_str += '/' |
14 |
> append_str += re.escape(query) + '$' |
15 |
> q.append(append_str) |
16 |
> |
17 |
> Slightly better (if append_str has a shorter name, maybe). I don't |
18 |
> like 1 line if EXPR STATEMENT else STATEMENT but sometimes they are |
19 |
> shorter |
20 |
> Putting a conditional in the function call is horrible looking though. |
21 |
|
22 |
It's called functional programming. Maybe it takes a little getting used to, but |
23 |
as your own example shows, it can cut your code base by a significant factor. |
24 |
|
25 |
Marijn |
26 |
|
27 |
|
28 |
- -- |
29 |
Sarcasm puts the iron in irony, cynicism the steel. |
30 |
|
31 |
Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML |
32 |
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode |
33 |
-----BEGIN PGP SIGNATURE----- |
34 |
Version: GnuPG v2.0.9 (GNU/Linux) |
35 |
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org |
36 |
|
37 |
iEYEARECAAYFAkmUB54ACgkQp/VmCx0OL2wIOQCfdd0U1TJ/GXxTwvV8vmMpW2u9 |
38 |
hfsAoIXkWvJP8sOGK4NstuXiCAgy5OIf |
39 |
=qfq4 |
40 |
-----END PGP SIGNATURE----- |