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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Rather than use a flag argument, define separate methods

3 点作者 invisiblefunnel将近 14 年前

1 comment

bartonfink将近 14 年前
I'm not sure this sort of logic scales. The examples he uses with a single boolean are simple enough because you're just writing two methods instead of one. What if, however, you have a signature that takes multiple booleans, either as formal parameters or as part of a struct? Do you write exponentially more methods, requiring the caller to be familiar with your naming conventions, just to free the caller from having to remember what the parameters represent? For that matter, what if you're passing in an enumeration? That's also a "flag" that is frequently used to switch behavior, and again, would require expanding one method into n, each with human-readable names.<p>If there's some a way to win big by doing this, I just don't see it.