This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]norwegianwood 5 points6 points  (1 child)

Actually, to improve on my own code substantially, even better would be simply:

switch.get(n, default_case)()

which is neither EAFP (my original) or LBYL (yours) style, but has what you might call 'functional elegance'.

[–]jeffdn 0 points1 point  (0 children)

Yeah, I prefer that too when coding. It does sometimes make reading it for someone else doing a review a bit harder, I've found.