Jump to the navigation menu

Don't make assumptions

I was recently writing code for a project and found myself making assumptions about what I was writing.

I was creating my own requirements.

Something no-one asked for.

I was assuming a value was always going to be a certain number of digits long.

I was writing code that verified this was true or throw an Exception.

Until I found out that that one of the values wasn't the same length as the others.

This could be an error in the data or it could correct.

No-one told me the lengths were always going to be the same.

So why was I checking it?

Why was I adding bugs to the code?

I've reverted the code that checks the length of the value and gone to find clarification.

If it's an issue, it'll be fixed in the source data.

If the lengths should all be the same, I'll potentially re-add the check.

Until I'm sure, I'll only write what's needed to deliver the feature and stop adding my own requirements and assumptions.

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 18 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.