I’m Checking Stuff

I’m recently reading a lot of functions which look like checkFoo(). They always return void and I invariably have to read them to figure out what they do. They either test some state and possibly throw an exception or they fix up some internal state.

void checkTheWeather(); // throws if it's too cold to go out

void checkTheStove(); // turn the stove off if it's on

From the context above it’s clear what’s going on, but mostly I can’t tell. This naming seems preferable.

void validateGoodWeather(); // throws if it's too cold to go out

void turnOffStove(); // idempotent ftw

Advertisements

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 )

Google+ photo

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

Connecting to %s