Avoid excessive switches and flags.

Sometimes it’s better to have something else handle those cases.

When you’re building an API, it can be tempting to add flags and options to increase the flexibility and power of a method. But if you bury an API’s verb with too many switches and flags, you will end up with a confusing mess that’s hard to understand.

Sometimes, moving some of that functionality to a new verb is better. It will make the API more expressive and far more readable. In addition, the API will be more understandable to the consumer.

The more your code reads like language and less like 1990′s PERL, the better off you’ll be.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: