Extreme Programming: Try Avoiding These Usual Suspects

18 Jul

Today I was really lucky to attend an workshop by expert software engineer Corey Haines. Corey challenged us to go extreme with avoiding the following common programming pitfalls:

LOC(M)

Long methods are where bugs go to hide. It’s a good rule of thumb to keep your methods to less than 3 lines. Super long methods are really hard to understand, especially when looking over your code later, or if someone else comes into your codebase. If your methods are getting too long, try to refactor by extracting some of the lines of code into other methods. Keep it simple!

No IF

This one is super counter-intuitive, but if statements are actually not very object oriented (OO). Your method should do one thing. With an IF statement, you’re asking the method to do two things. If you’re finding yourself using an if statement, really think about what you’re trying to accomplish, and whether you need to create another object instead.

No Primitives

Avoid passing primitive data structures (e.g. arrays, hashes, numbers, booleans) between methods. If you’re passing in more than one thing into a method, consider making a new Object. Only objects or lists of objects should be passed between methods.

Advertisements

3 Responses to “Extreme Programming: Try Avoiding These Usual Suspects”

  1. Li Ouyang (@styliii) July 19, 2012 at 10:46 am #

    thanks for explaining why we should be avoiding if statements. i wondered why someone once told me if you’re using if statements, you’re an amateur. touche.

  2. Agnes Mamcarz Hamilakis July 20, 2012 at 11:54 pm #

    Very useful! Thanks:)

  3. derb July 24, 2012 at 6:34 pm #

    We would love examples!

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