As a novice web developer, I
always tend to code stuff up, see if it works, and proceed when it does. Then
back to step one. I think most developers went through just that at one point
or another. Problem with this whole “going back to step one” phase is that I tend
to code stuff up, again, from step one. What is good about this practice is
that it is really easy for a newbie to trace back his steps when he sees
numbers and jumbled symbols instead of words. With the simple stuff that most
newbie developers do, it won’t be much of a burden to the server anyway if he
continues this WET, write-everything-twice, (or more, for that matter)
Principle. Packing as much experience as I do have now (definitely not that
much), it is very much clear that this is a bad practice. Actually, “bad” is an
understatement. Codes come in bits and bytes. Loading them requires bandwidth.
Everything else is simple math: 1 byte is easier and faster to load than 2
bytes.
And along comes Django.
Django has this particular tenet
concerning code repetition: the DRY, don’t-repeat-yourself, principle. Why is
it that important? It’s basically this: if you can kill two birds with one
stone, why bring two stones in the first place? Efficiency is key. And working
with Django over the past month taught me just that: to always bring a single
stone.
If it does the same thing, it
only needs to exist once in the system. If you ever feel the need to edit a
specific entry, you only edit one entry. If you need to delete a specific
entry, a single stone will suffice.
I once read somewhere that the
Y2K bug was caused by the violation of this fundamental rule.
WET coding may be a hard habit to
break but the advantages of DRY coding simply outweighs the former. And if DRY
isn’t a cool enough acronym for you, try this: DIE (Duplication is Evil)
Ciao.