Re: how to write good code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 1 Sep 2008 08:50:45 -0700 (PDT), larry wrote:

>Write a lot of code, rewrite code you think is messy (we can always do
>better).
>The more you do the better you should get.
>
>Here is some inspiration on that:
>http://www.codinghorror.com/blog/archives/001160.html

NB: the message of that blog post isn't valid at the most simplistic
level (just write lots of code), and the comments to the post explain
why. Don't just read the guy's blog, read the comments! As an extreme
example, consider the latest repost of a classic at TheDailyWTF:

http://thedailywtf.com/Articles/Classic-WTF-To-the-Hexth-Degree.aspx

5,000+ LOC that misses the point, and can be easily replaced by a
one-line framework call. Clearly, just writing lots of code wasn't this
coder's greatest challenge.

Practice makes perfect, but only if you review your output with an eye
to pick up faults.

On rewriting messy code, I've always approached a bug fix on legacy code
with the view that tidy code breaks less, or at least breaks where you
can see it. More often than not, tidying up some rat's nest of code will
magically fix the problem anyway, and if it doesn't, it can make the bug
very clear to see. This even has a name: refactoring.

I would posit that writing lots of code is good practice, but learning
good from bad comes from reading code. Read your old code (if you can!)
Read other people's code. Read sites that make fun of bad code (great
way to learn what bad code looks like!) Read what makes code good and
what makes it bad. Then write some more code :)
-- 
Ross McKay, Toronto, NSW Australia
"Before enlightenment: chop wood, carry water;
 After enlightenment: chop wood, carry water" - Wu Li

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux