Name your functions well.

A good name describes its returned value.

Function names should not be vague. It should be immediately
obvious what you’re going to get when you call the function.

A function is a method that takes zero or more inputs and returns an output. When the output is an object in the business domain, it’s generally much more helpful than when it returns primary types.

Say you have a function that takes a zip code as an input and returns a list of nearby stores. If you named the function “getLocations()”, it is rather vague. What locations? How do I use them? What kind of object am I getting back?

On the other hand, “getStoresNearZipCode(ZipCode)” gives you the idea that it is returning an array of Store objects. It also points you toward passing a zip code object as the argument.

This type of thing may seem like a trivial issue, but it dramatically increases the speed of development and improves the understanding of the code by others.

Leave a Reply

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

You are commenting using your 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: