>>>>> "SB" == Steve Bertrand <st...@ibctech.ca> writes:

  SB> In all honesty, I think I'm learning more about Perl (and my own
  SB> programs) writing the tests than I do when I'm writing the programs
  SB> themselves. (Same goes for keeping up with the documentation!).

coding is coding and the more you do the more you learn. tests are a
particular area but they don't necessarily use different coding
constructs than other projects use.

  SB> Given your comments above, would you say that this is better?

  SB> my %typedefs = (
  SB>                 plan_info       => \&plan_info,
  SB>                 user_info       => \&user_info,
  SB>                 plan            => \&plan,
  SB>           ...etc...
  SB>           );
  SB> ...

just so you know, that is called a dispatch table. it is used to lookup
a sub based upon a key. it is used in many sorts of projects. i wouldn't
use the name %typedefs as it doesn't say much about the use of the
table. note that names should reflect how something is used, not what it
contains. maybe type2info is a better name. i still don't get the use of
this so i can't create a proper name for it.

  SB> my @known_types = $vardb->is_type();

  SB> my @missing_types;
  SB> my %data;

  SB> for my $known_type (@known_types) {

  SB>     unless (exists $typedefs{$known_type} ) {

again, you don't need exists there. since your dispatch table's values
are always code refs so they will always be true.

  SB>         push (@missing_types, $known_type);
  SB>         next();
  SB>     }

  SB>     %data = &{ $typedefs{$known_type} };

you didn't get my point about redundancy. $typedefs{$known_type} is used
twice which is once too many. if you refer to a hash value (especially
deep hashes) more than once, it is usually better to grab it into a
scalar and use that. it will likely be faster (saves hash lookups), it
is shorter (removed duplicate code) and is usually less bug prone as you
one have the expression (which can be complex) in one place.

  SB>     eval { $sanity->check_type( $known_type, \%data, $error ) } ;

  SB>     unlike ( $@,

again, what is unlike? i now guess it is from a test module. does it
take a regex as an arg?

  SB>              '/not a defined datatype/',

that isn't a regex, just a plain string with / chars on the ends. maybe
the unlike call will convert that but the / will be literal / chars. use
qr// or maybe the string without /.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to