Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
XP is just a number
 
PerlMonks  

Re: Re: Re: Structure is more important than speed

by Anonymous Monk
on Sep 09, 2002 at 23:46 UTC ( #196478=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Structure is more important than speed
in thread Which way is faster?

D'oh. Thinko causing typoing. Make the obvious fix and the comment remains true.


Comment on Re: Re: Re: Structure is more important than speed
Re: Re: Re: Re: Structure is more important than speed
by sauoq (Abbot) on Sep 09, 2002 at 23:58 UTC
    D'oh. Thinko causing typoing. Make the obvious fix and the comment remains true.

    I don't see an "obvious" fix that will make

    if (defined(my $foo = exists $hash{$key})) { # ... }
    work like
    if (exists $hash{$key}) { my $foo = $hash{$key}; # ... }

    I guess that's either because there isn't one or because I'm not enlightened. Would you enlighten me?

    Before you answer: Please notice that exists $hash{$key}; is not equivalent to defined $hash{$key};.

    -sauoq
    "My two cents aren't worth a dime.";
    
      If undef is not a valid value in your data structure, then:
      if (defined(my $foo = $hash{$key})) { # ... }
      You are right. That is an assumption. Very often you can tell that it is true. Many optimizations add assumptions. Don't do them if the assumptions are wrong. Don't do them if you don't need the speed. Programmers should know this.

      That assumption was obviously right and I needed the speed. Adding that assumption seemed better than rewriting in C. Programmers sometimes must make such choices. That choice worked.

      Do you feel enlightened about my reasoning?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://196478]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-04-21 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls