Re: Long Live GOTO

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

 



On 12-02-06 11:58 AM, Tim Streater wrote:
On 06 Feb 2012 at 09:48, Adam Richardson<simpleshot@xxxxxxxxx>  wrote:

On Mon, Feb 6, 2012 at 4:25 AM, Adam Richardson<simpleshot@xxxxxxxxx>wrote:

On Mon, Feb 6, 2012 at 4:07 AM, Tim Streater<tim@xxxxxxxxxxxxxxxx>  wrote:

I disagree that the nested function is a straw-man. I (just as the other
authors I'd linked to describing the "arrow" pattern of code) have seen
plenty of examples of similar code.

I guess what I meant was, that I'd never have written it that way in the first place, so as an example it felt contrived. Amateurs or people with no training (in particular physicists at CERN 40 years ago) should be kept well clear of the goto. I'd probably write your function like this:

function val_nested ($name = null, $value = null, $is_mutable = false)
      {

      static $values   = array();
      static $mutables = array();

      if  ($name===null)  return $values;

      if  ($value===null)  return isset($values[$name]) ? $values[$name] : null;

[-- SNIPP --]

I always add blank lines for clarity. Remove those and the above is 30% shorter than yours - as far as I could tell, none of the else clauses was required.

My approach is:

1) deal with the trivial and error cases first

Some say you should never return early from a function... I too think that early returns can improve the readability of a function-- especially if they are short snippets of logic that clearly indicate the reason for an early exit (usually edge case constraints).

:)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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