Bad Developer, No Twinkie Part 4: Gigantor functions

I think at one point or another, we’ve all done this.  We started off with a nice small function, but kept adding functionality to it.  Just a few lines here and there, and before you know it, you’ve created a 1100 line long gigantic function that everyone refers to as “Gigantor”.  It does multiple things, the logic is complex, and the code is a rats nest.  Everyone fears touching it, because no one wants to break it.

It’s easy to say “Don’t do this”, but harder to not do in practice.

My recommendations for avoiding this situation:

  • As you write it, refactor it. When you see an opportunity to clean something up, do it.
  • Make sure a given function does one small thing. If you find a function doing more than one thing, split it
  • Don’t write similar code more than once. If you find you are seeing similar structures within the same function, that should fail the smell test – it’s ripe for refactoring.

It’s better and easier to keep on top of things, rather than one day waking up and having to fight Gigantor. No one likes fighting Gigantor.

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