Settings

Theme

Why does everyone love polymorphism over switch case

stackoverflow.com

9 points by ayroblu 6 years ago · 1 comment

Reader

mimixco 6 years ago

Personally, I agree with the author. Since code executes linearly (in a single-threaded app), it makes sense to write it that way, too. We recently wrote a large a complex parser, interpreter, and backing database for a new text processing language we're developing and it was done entirely without classes or OOPS-type constructs. As the author suggests, it's mostly a lot of switch/case (or in our case, lisp cond expressions) that test for and handle the various cases that the parser might encounter, much as a human would. We've found this design much easier to reason about and debug than a bunch of classes that depend on each other.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection