[wp-hackers] Coding style

Mark Jaquith mark.wordpress at txfx.net
Mon Jul 3 21:35:23 GMT 2006


On Jul 3, 2006, at 4:23 PM, Matt Mullenweg wrote:

> Anything else we should put on there?

About a year ago, I picked up on the coding style that you and Ryan  
had settled upon, and submitted a few "massive code cleanup" patches  
that brought older files up to that standard.  Here's the methods I  
used.  I'm not saying they're better than anything else, but it  
seemed to be what you and Ryan were doing on new code you were  
writing, and it seemed clean and readable to me.

1. Tabs instead of spaces for block intents
2. Indent blocks like if, elseif, else, for, foreach, switch, while,  
etc...
3. Use of whitespace around and within said block items:
	bad.	if('something' == $foo){
	good.	if ( 'something' == $foo ) {
4. 'something' == $foo, rather than $foo == 'something'
5. If at all possible, omit curly braces.
	bad.
		if ( 'foo' == $bar ) {
			do_foo();
		} else {
			do_bar();
		}

	good.
		if ( 'foo' == $bar )
			do_foo();
		else
			do_bar();
6. cast to array before foreach
	bad.	foreach ( $foo as $bar ) {
	good.	foreach ( (array) $foo as $bar ) {
7. Spaces between parameters:
	bad.	do_foo('bar1','bar2',false);
	good.	do_foo('bar1', 'bar2', false);
8. Eliminate unnecessary trailing tabs or spaces:
	bad.	do_foo();\t\n
	bad.	do_foo(); \n
	good.	do_foo();\n

This may be too intense for coding guidelines, but it seems to be the  
convergent style.
--
Mark Jaquith
http://txfx.net/




More information about the wp-hackers mailing list