RE: Function size

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

 



> My monitor can also display about 55 lines of code, my functions are, on
> average, just a few lines of code though -- a maximum of about 20, with an
> average of around 5 or so.
> 
> This is because the rule of thumb I follow is that a function should do
one
> thing, and should be named well. The biggest downside to the type of style
> I have is that if not done "correctly", people can feel like they're
> swimming in a sea of chasing down functions to find out wtf is going on.
> When done "correctly", it leads to pretty clear code, IMO.
> 
> --

Tedd,

I think the length of code depends on a few different factors, what if you
have your docblocks, and comment lines, as well as your bracing style?
Where do you consider your function to start?

Personally, I use this bracing style:

# decide if we should work, or sleep
if($do == $something)
{
	# do something here
	$work = 'done';
}
else
{
	# something isn't being done now
	$work = 'sleep';
}


In this (really crude) example, there are 11 lines of code.  Granted, the
way you do your bracing you can lose a few lines, and within this example,
it could be written as:

# decide if we should work, or sleep
# default action for if something isn't being done
$work = 'sleep';
if($do == $something) {
	# do something here
	$work = 'done';
}

So, with that craptastic example, we've taken 11 lines, and compressed it to
7.

Anyways, I get the "rule of thumb" to be able to fit a function on a
"screen", or to make it as small as possible, but sometimes comments can get
in the way, and if you like your bracing style, you end up with a lot of
extra lines of code too (also if you like to have blank lines between
actions).


Anyways, my IDE that I use, shows 47 lines on the screen, at 145 characters
across, using Courier New 9pt, and I try to keep it to 80 characters wide,
but that doesn't always happen :P

Steve.


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