O'Reilly logo

Refactoring Workbook by William C. Wake

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Conditional Logic

Note

“If wishes were horses, beggars would ride.”

It's natural that object-oriented programming is focused on objects and their relationships, but the code within an object is important too. Classic books like Jon Bentley's Programming Pearls or Brian Kernighan and P. J. Pike's Elements of Programming Style can help inspire you to write good, clean code.

Conditional logic is often the trickiest part of such code.

  • It's hard to reason about, since we have to consider multiple paths through the code.

  • It's tempting to add special-case handling rather than develop the general case.

  • Conditional logic sometimes is used as a weak substitute for object-oriented mechanisms.

Smells Covered

  • Null Check

  • Complicated Boolean Expression

  • Special ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required