Re: Re: Function size

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

 



On Tue, May 29, 2012 at 11:40:25PM +0200, Matijn Woudt wrote:

[snip]

> On Tue, May 29, 2012 at 11:06 PM, Paul M Foster <paulf@xxxxxxxxxxxxxxxxx> wrote:

[snip]

> >
> > I think a lot of coders try to be kewler than the next 18 guys who are
> > gonna have to look at the code, so they use a lot of "compression"
> > techniques to reduce LOC. Plus, they're lazy. I'd rather see everything
> > with lots of spaces and plenty of comments and blank lines. Especially
> > since I'm sometimes that 18th guy to look at the code.
> >
> > Paul
> 
> Paul,
> 
> Are you stating here that compression is a bad thing?
> 
> That means you consider this nice:
> 
> if ( action == A )
> {
>     doA();
> }
> else if (action == B )
> {
>     doB();
> }
> else
> {
>     doC();
> }
> 
> Or perhaps flooded with comments that merely say the same as the code does?
> 
> I'd go for
> if(action == A)
>     doA();
> else if(action == B)
>     doB();
> else
>     doC();
> 
> or , if it's really that clean, i'd probably go for
> if(action == A)  doA();
> else if(action == B)  doB();
> else doC();

No, that's not what I mean. It's not necessarily compression in the
sense that the coder is taking up less actual space. It's hard to
explain, and I'm not good at it because I try not to do it. It's more
along the lines of using very terse and peculiar coding techniques to
save time and look kewl. Maybe something like this:

The "long" way:

$alfa = 0;
if ($bravo) {
	if ($delta)
		$alfa = echo();
	elseif ($foxtrot)
		$alfa = golf();
}
elseif ($hotel) {
	$alfa = india();
}

The "kewl" way would be to translate the above into a single expression
using solely multiple nested terniary operators ( ? : ) on a single line.
Nothing wrong with the functionality of the result, but it becomes hard
has hell to read and figure out what the code is trying to do. And
nothing against terniary operators. I use them where appropriate. But in
a complex conditional like the above, they really only serve to
obfuscate the meaning of the code. We might marvel at the skill of a
programmer who did such a thing, but he's obviously not looking down the
road at the other people who will later maintain his code.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

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