Click to See Complete Forum and Search --> : Indentaion Style


Sxooter
10-10-2002, 02:30 PM
So, how do you guys indent (if you do hehe) your code. Mine is:

tab=8 spaces (remain tabs though)
style:

function name (args,args) {
first level;
if (something==something){
next line;
}
}

How about the rest of ya?

examancer
10-10-2002, 04:04 PM
looks like you forgot the closing [/code] tag.

I indent using 2 spaces, not tab. Here is a function I made:


// sytax: string dump_array(mixed $value [, string $value_boundary [, string $key_boundary [, int $r_flag]]])
// dumps the array into "key : value" pairs recursively:
// argument 1 is required, and can be any variable type... but if its an array, it will be dumped recursively.
// argument 2 is optional and is a string. This string is the boundary between values. the default is " : "
// argument 3 is optional and is a string. This string is the boundary between the keys. The default is "<br>";
// argument 4 is optional and is a number. 1 means that the function call is a recursive one, and not the original.
// argument 4 is for internal function use only and should not be set in the original function call from the script.
function dump_array ($x) {
if (gettype($x) == "array") { // if value is an array...
// then the value is split into key:value pairs, which are each sent back through the function
// to make sure they are not arrays themseles... and if they are, they are split again, and again, and again, etc...
$vb = ' : '; // default boundary that seperates values from each other and their key.
$kb = '<br>'; // default boundary that seperates keys.
if (func_num_args() > 1) { // if arg 2 is set...
$vb = func_get_arg(1); // the value replaces the default value boundary.
if (func_num_args() > 2) { // if arg 3 is set...
$kb = func_get_arg(2); // the value replaces the default key boundary.
}
}
/*if (func_num_args() > 3 && func_get_arg(3) == 1) { // if the function call is a recursive one...
$kb = $vb; // the key boundary is removed, since the key is really just a value for another key.
}*/
while ($a = each($x)) { // walks through the key:value pairs for each key in the current array.
// a string containing all the key:value pairs is generated:
// - both the key and the value are sent back through the function to ensure they are not arrays.
if (func_num_args() > 3 && func_get_arg(3) == 1) {
@$table .= '(' . dump_array($a[0], $vb, $kb, 1) . $vb . dump_array($a[1], $vb, $kb, 1) . ')';
} else {
@$table .= dump_array($a[0], $vb, $kb, 1) . $vb . dump_array($a[1], $vb, $kb, 1) . $kb;
}
}
return $table;
} else { // if value is not an array, the value is returned untouched.
return $x;
}
}


its a nice little function I keep around to check the content of arrays.

largo
10-11-2002, 11:53 AM
I use the following standard Sxooter:

http://pear.php.net/manual/en/standards.php#standards.indenting

8 spaces (for tab) is a bit much.... though default for most editors.

-m.

Sxooter
10-11-2002, 05:56 PM
The reasoning for 8 spaces is that if you find yourself having a hard time reading the code because it's so indented, it's time to break your code apart into more manageable pieces. 8 spaces, by the way, is also the standard for the Linux kernel. Just fyi.