Re:Using Dispatch Tables to Avoid Conditionals in JavaScript
by mgrouchy on Monday May 13, 2013 @09:46AM
(#5698589)
Interesting. Ive seen something similar to this quite often used in Python because it doesn't have Switch statements.
[ Parent
| on HN ]
Re:Using Dispatch Tables to Avoid Conditionals in JavaScript
by gvalkov on Monday May 13, 2013 @11:38AM
(#5699262)
Indeed, it's quite idiomatic. I would have still preferred if there was a switch/case construct that would generate a dispatch table for us (in fact, this was proposed and rejected in pep 3103[1]). A case statement would have been a nice, little addition to the expressiveness of Python, but it's not that big of a deal.
Here's another dispatch table technique that I really like[2].
[1]: www.python.org/dev/peps/pep-3103/
[2]: http://code.activestate.com/recipes/577864-fast-and-elegant-...