Re: fun with hashes!
Uri Guttman <[email protected]> Fri, 23 Nov 2007 23:53:28 -0500
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "SHC" == Shawn H Corey <[email protected]> writes: SHC> A. Pagaltzis wrote: >> * Mr. Shawn H. Corey <[email protected]> [2007-11-24 00:50]: >>> my $sub = ( exists $dispatch{ $key } && ref( $dispatch{ $key } ) eq 'CODE' ) >>> ? $dispatch{ $key } >>> : $dispatch{ 'default' }; >>> >>> Just because you're not paranoid doesn't mean computers don't >>> hate you :) >> So why did you skip the check for whether the default value is >> a CODE ref? SHC> Because I don't like dispatch tables. When I see them I want to SHC> convert the whole thing to objects and starting thinking about SHC> inheritance and polymorphism. Which will take care of such SHC> problems at "compile" time. and how would an object remove the need for a dispatch table? you can't always map keys to methods and OO isn't needed in all cases. you can also do dispatch tables inside a class and again much simpler than OO or polymorphism. inheritance is right out as it is baggage in most designs. people think OO eq inheritance and that is so wrong. i prefer message passing and its flavor of polymorphism any day over inheritance and its rigid class hierarchies and dependency trees. SHC> But this thread is about hashes not objects. SHC> (And I still think computers hate me.) not as much as i hate (but have used) inheritance. i should start a side thread for this: ever write an OO system where one class ISA and HASA another class at the same time? i have and for a good reason and it works so elegantly. :) thanx, uri -- Uri Guttman ------ [email protected] -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org