Date: 2005-02-23 12:21 am (UTC)
There's no switch statement in python, right? Usually people use a pile of if/elif/elif/else statements, like this:
if   cmd == 'print': doprint()
elif cmd == 'save':  dosave()
elif cmd == 'read':  doread()
elif cmd == 'quit':  doquit()
else: raise ErrorMessage, "WTF?"

What Guido intended, however, was that we'd write this:
{ 'print': doprint,
  'save':  dosave,
  'read':  doread,
  'quit':  doquit }.get( cmd )()


Which is much more like the scheme-like engine he was implementing at the core of the Python interpreter. We can discuss whether the latter is more clear than the former, but you can't argue that it's much more concise. As one commenter wrote, "You've got a high-level language. Use it, for god's sake."
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

elfs: (Default)
Elf Sternberg

May 2025

S M T W T F S
    123
45678910
111213141516 17
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 14th, 2025 04:49 pm
Powered by Dreamwidth Studios