Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by Anonymous Monk
on Sep 09, 2002 at 23:46 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://196478]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found