Archive

Posts Tagged ‘templates’

Keeping your code DRY is also in the details

November 27th, 2009

What you should know already…

If you have been a developer for a while, chances are you’ll have come across the term DRY. It stands for Don’t Repeat Yourself, and it is actually a form of art. Keeping your code DRY ensures you have to think well before you start coding. Instead of randomly throwing code in your IDE, you should create the reflex of thinking how you can achieve what you want, without having to type too much code.

Not out of laziness, but because you’re smart. If you ever have to change your code, you’ll be glad you decided to write that particular bit only in that particular file. Sometimes it’s much easier to just copy/paste code from one class into another. But if you have to modify that piece of code, you’ll have to remember all the places that same code appears. Unless you kept it DRY of course.

Usually when an article talks about DRY, it will be in the context of Object Oriented Programming and model abstracts/inheritance/whatnot and making sure you don’t repeat the same code in different places. But the same principle can also be applied to other aspects of our code.

Read more…

Tom PHP, Programming , ,