Re: Proper code formatting
| From: | Jason Pruim | Date: | Mon, 23 Mar 2009 12:48:22 +0000 |
| Subject: | Re: Proper code formatting | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-290568@lists.php.net to get a copy of this message | ||
George Larson wrote:
On Mon, Mar 23, 2009 at 8:23 AM, Shawn McKenzie <nospam@mckenzies.net>wrote:hasBob McConnell wrote:To each his own. Whatever floats your canoe. Just whatever you pick, stick to it throughout your code.others as well. Are there any rules or advice I can use for formatting (especially indenting) code? for example how best to format / indent this ?From: Michael A. PetersAngus Mann wrote:yet.Hi all, I'm fairly new to PHP so I don't have too many bad habitsI'm keen to make my code easy to read for me in the future, and forI'm using "PHP designer 2008" which does syntax coloring but if it
asomething to automatically indent - I haven't found it yet.It probably allows you to either set a specify a tab as a real tab or
specified number of spaces. Auto-indenting - this isn't python, the compiler doesn't enforce it's way, you follow the convention of the project you are working on - so I suspect many php editors tailored toTo take this question a step further, is there a PHP best practices document available? I am looking for one that I can give to a new programmer and tell her "do it this way until you can explain to me why you shouldn't." Bob McConnellphp don't have an auto indent.I've never of course tried that specific product. I use bluefish, vi, and emacs.
There are various coding standards. There is one for PEAR, the ZendFramework and most frameworks/large projects that take contributions have them. Here's Zend: http://framework.zend.com/manual/en/coding-standard.html -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Being a greenhorn, I too can benefit from this thread. Is that to say, Shawn, that you personally find this (Zend) standard as good or better than the rest? I actually just went through this wit ha group of people that come from all different levels and back grounds in regards to programing. Trying to decide whether to use spaces, or tabs, short hand or long hand... It took quite a bit of discussion before we arrived at an agreement... It really didn't matter what format we used as long as we stayed consistent throughout the file. In other words, if you are going to edit a file and it uses spaces instead of tabs, use spaces.... So absolutely, develop some standards if you are going to have multiple coders working on it... But they don't have to be set by someone else... Personally though, I go for readability it may at times take longer to write it out, but since we all type 500 words permit with 100% accuracy it won't be a problem right? ;) And then when you go back to the code in 6 months, a year, 2 years... It's still easily read able :)