Re: Quick Poll: PHP 4 / 5

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

 




----- Original Message ----- From: "Jasper Bryant-Greene" <jasper@xxxxxxxxxxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Friday, September 16, 2005 4:45 PM
Subject: Re:  Quick Poll: PHP 4 / 5


Stephen Leaf wrote:
So yes a bug. But for those that want to be able to grab only what we need. in my case array_pop's returned element. I don't wanna be hassled with the "are you sure you wanted to ignore part of what we did?" It's almost like every program asking "are you sure you wanted to close me?" everytime I get asked that I always think... "I did just click the X.. so.... Yah......."

But why use array_pop() to get the last element, when you know it's intended to shorten its passed array as well?

I mean, sure, it might take a few more lines of code to do it properly, but it has the advantage that whoever has to look at the code next might actually understand what's going on in your head.

$array = explode( ',', $some_string );
$last_element_pos = count( $array ) - 1;
$last_element = $array[$last_element_pos];

[ sure, you could put the count( $array ) - 1 as the array subscript but I was just extending it out for illustration... it's probably easier to understand later on anyway. ]

Actually I choose array_pop for 2 reasons.
I like short code. I don't want to read thousands of lines just to get an idea. I tend to think in very compact code. if you find that ugly and unreadable. that's your preference. I find extended coding very ugly, mostly because I'm a slow reader, and that is my preference I got use to working with pop and shift while I was doing perl work. so to me pop'ing an array makes perfect sense.


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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