Avoid excessive switches and flags.

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

When you’re building an API, sometimes 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 just end up with a confusing mess that’s hard to understand.

Sometimes, it’s better to simply move some of that functionality to a new verb. This is especially true if it will make the API more expressive, which makes it far more readable and understandable to the consumer of the API.

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: