The importance of setting a good example

Most developers will pay just enough attention and do just enough work to get their current task done. To that end, and to reduce mental burden, whatever patterns the current codebase does are copied/extended/emulated. After all, most development work consists of changing existing code to do something else as well as whatever it did before.

As I mentioned to a colleague once, “code cruft happens little by little, never in one fell swoop”.

So it’s important to set a good example by not doing things the hacky way. Or, at least, by not leaving the code hacky by the time the next developer looks at it. The other day at work I implemented a proof-of-concept by modifying my carefully designed pristine code and, because it was easier, added a global variable to get the job done. It was a quick hack, I knew it was a bad idea and I could always fix it later, right?

Fast-forward a few weeks and 2 other developers had been working on this code. Now we had a dozen global variables. The two other devs aren’t bad at what they do; but having had a global there in the first place caused new ones to grow. Bad ideas are infectious.

So be sure to try and do things the right way. Other people will copy the patterns you write, whether good or bad.

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

%d bloggers like this: