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.

Rather than use a flag argument, define separate methods

3 pointsby invisiblefunnelalmost 14 years ago

1 comment

bartonfinkalmost 14 years ago
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.