|
Posted by Robert Cummings on 09/17/05 08:14
On Sat, 2005-09-17 at 00:14, Jasper Bryant-Greene wrote:
> leaf wrote:
> >
> > 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
>
> And what about someone else that has to read/maintain your code in the
> future? What about when you come to read a "clever" but compact line of
> code that does 5 or 6 things on a single line, a few years down the
> track, and spend valuable time just trying to figure out what it
> actually does?
>
> > 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.
>
> Sure, when there actually *is* an array to pop. In the following
> situation there is no array to actually pop (remove and return) the last
> element from, since you're using the return value of explode() while
> array_pop() expects a reference to a variable:
>
> $element = array_pop( explode( ',', $some_string ) );
Ahhh but there is an array to pop, returned arrays are still containers
and generally follow the semantics of declared containers (obscure
segfault bugs notwithstanding).
Personally I find:
$element = array_pop( explode( ',', $some_string ) );
More readable than:
list( $element ) = explode( ',', $some_string );
But that's because I find assigning to something that looks like a
function disconcerting :)
Maybe what we really need is:
//
// First parameter should be a reference and will be altered to
// reflect the popping of the substring separated by the separator.
// The second parameter is the separator to use, comma is defaulted
// but we set it explicitly for readability ;)
//
$element = str_pop( $some_string, ',' );
Of course, as soojn as you do that, you know someone will do the
following:
$element = str_pop( $some_part1.$some_part2, ',' )
Or even worse (teehee):
$element = str_pop( implode( ',', $some_array ) )
Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
[Back to original message]
|