Created
June 15, 2012 16:35
-
-
Save mnuck/2937474 to your computer and use it in GitHub Desktop.
Why if/else will eventually bite you
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# option 3 (ternary) | |
for perm in ['modify', 'view', 'execute']: | |
fn = assign_perm if request.POST[perm] == "public" else remove_perm | |
fn(perm, anon, rs) | |
# option 3.1 (switch/case-in-a-dict) | |
fn_selector = {"public" : assign_perm, | |
"private" : remove_perm } | |
for perm in ['modify', 'view', 'execute']: | |
fn_selector[request.POST[perm]](perm, anon, rs) | |
# option 3.1.5 (switch/case-in-a-dict) | |
fn_selector = {"public" : assign_perm, | |
"private" : remove_perm, | |
"acl_controlled" : ACLify_perm} | |
for perm in ['modify', 'view', 'execute']: | |
fn_selector[request.POST[perm]](perm, anon, rs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment