Re: [PHP] how to write good code
- From: mailist@xxxxxxxxxxxx (Eric Gorr)
- Date: Sat, 30 Aug 2008 20:46:45 -0400
On Aug 30, 2008, at 8:17 PM, Shiplu wrote:
I wanna know how to write good code in php.
Not oop stuff. I wanna know how to write a good php code file.
documentation, comments. indentation etc.
what are the good practices??
Studying design patterns are a great start to learning how to write good code. Such things apply not only to PHP, but to other languages as well.
A couple of good books are:
Design Patterns: Elements of Reusable Object-Oriented Software
# ISBN-10: 0201633612
# ISBN-13: 978-0201633610
Head First Design Patterns (Head First)
# ISBN-10: 0596007124
# ISBN-13: 978-0596007126
As for comments, the best comments are those that include 'why' the code was written the way it was. What the code does can be discerned by studying the code and is generally less useful.
As for code style (which includes indentation), there is no single good style...pick something that looks good to you and use it. The most important thing is to be consistent. For example, if you choose to write an if statement like:
if ( ... )
{
...
...
}
don't use that in some parts of your code and
if ( ... ) {
...
...
}
in other parts.
As for other tips to writing good PHP code, I'd recommend taking a look at:
Essential PHP Security
# ISBN-10: 059600656X
# ISBN-13: 978-0596006563
But, basically, it just comes down to practice, practice and more practice.
.
- References:
- how to write good code
- From: Shiplu
- how to write good code
- Prev by Date: how to write good code
- Next by Date: Re: Individual bulk e-mails - performance question
- Previous by thread: how to write good code
- Next by thread: Re: how to write good code
- Index(es):
Relevant Pages
|