Re: how to write good code

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

 




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.




--
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