TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why does everyone love polymorphism over switch case

9 点作者 ayroblu超过 4 年前

1 comment

mimixco超过 4 年前
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.