Don’t Repeat Yourself (DRY)

The DRY concept comes up a lot in programming (you already saw it in database design—don’t repeat data in multiple tables), and it is especially important in organizing your code. If you have two different functions that do almost the same thing, you will end up writing the same instructions twice, which is a waste of time. What’s worse, though, is that when you find a bug in one of your functions (and, believe me, you will find a bug), you will have to fix it in both functions. Even worse still is when you fix the bug in one function but forget to fix it in the other function, and you end up thinking, “What is going on? I already fixed this bug.”

The first big project I worked on was a somewhat complex website for ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.