Require a small number of parameters.

Your method definitions should not be overly long.

If a method has a long series of parameters it can become a problem for other developers to use. Every time they use the method they’ll need to research its full definition, determine which parameters are nullable, and what order they need to be in. Fortunately, better languages have named arguments so the order becomes less of a concern. Still, a large quantity of parameters causes headaches.

You can group associated parameters into an object. For example, instead of “x, y, z”, maybe a Coordinates object is called for. Passing Coordinates instead of three unknown temporary variables is a ton easier to understand.

Having too many dependencies is a sign your method is doing too much. Try to reduce your method’s responsibilities and the number of required parameters should also come down.

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 )

Google photo

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