TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why does everyone love polymorphism over switch case

9 pointsby ayrobluover 4 years ago

1 comment

mimixcoover 4 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.