>>>>> "SB" == Steve Bertrand <[email protected]> writes:

  SB> Uri Guttman wrote:

  >> my $item_name = $data->{item_name} ;
  >> $error->add_message( "item_name is undefined" )
  >> unless length $item_name ;
  >> 
  >> my $safe_name = $self->safe_string($item_name) ) {
  >> $error->add_message( 
  >> "item_name has potentially dangerous chars: $safe_name" )
  >> if $safe_name ;
  >> 
  >> that is shorter, faster (no blocks, no duplicate code), and easier to
  >> read in general.

  SB> I get the gist of what you are doing here. My example 'item_name' was a
  SB> bad one ;)

item_name is an ok name if the term item is clear enough. in a proper
context it works. item by itself without context is too generic. so is
name. also it depends on scoping. key and val are poor names but if you
are doing a tight loop over hash keys, they are fine.

  SB> Not every key in the incoming %$data parameter has the same value
  SB> type, so AFAIK, I have to check each item in the hash individually
  SB> as opposed to just assigning it to a temporary var. (...I'm
  SB> working away from a predecessor's method of using $tmp, $a, $b,
  SB> $c, $left, $right and everything else, so I don't do things like
  SB> that ;)

then you should use a validation module or write a sub to do it
yourself. doing validation inline for each field is tedious and
repetitive.

  SB> Common-code doesn't really bother me, so long as I'm writing it in a
  SB> context where it needs to be repeated for different data types, and once
  SB> it's done, I can re-use it. Shrinking the repeating code blocks is a
  SB> different story.

common code should bother you. it is a source of bugs (changed the code
in one place but not the other!), it can slow things down if the code
does repeated slow deep hash accesses, etc. consider the whole concept
of a sub was to factor out duplicated common code into a single
location.

  SB> ps. The module in question is here: http://ipv6canada.com/Sanity.pm
  SB> pps. I'm currently reading "Advanced Perl Programming" by Sriram
  SB> Srinivasan. (Yes, I know there's a new version).

and the two versions are basically very different books. there is almost
no overlap. the first one is also obsolete in many areas or covered
better by new books and docs.

uri

-- 
Uri Guttman  ------  [email protected]  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to