Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^4: Named Subroutine Parameters: Compile-time errors vs. Run-time warnings

by TheDamian (Priest)
on May 29, 2009 at 23:47 UTC ( #766987=note: print w/replies, xml ) Need Help??

in reply to Re^3: Named Subroutine Parameters: Compile-time errors vs. Run-time warnings
in thread Named Subroutine Parameters: Compile-time errors vs. Run-time warnings of the MTOW you promote TDI is, if not wrong, then sub-optimal

One of the points I make in PBP is that "sub-optimal" is not a easy thing to judge as soon as you have more than one metric to optimize. PBP suggests at least four: maintainability, robustness, performance, and conciseness (and argues that that is the approximate order of importance of the four).

The recommendation to use anonymous hashes when passing one-off argument lists trades a little less performance for a little more conciseness, some improved robustness, and (if used consistently throughout the code) better maintainability.

Of course, you're perfectly correct to factor out the hash memory reallocations into a single declaration if you're going to repeat the same call hundreds (or millions) of times, but as a default habit, just building an anonymous hashref at the point you need it is cleaner, less error prone, and more concise. And the performance cost on a single call at modern processor speeds isn't worth the hassle of coordinating between separate hash declarations and uses.

All of which is why inlined hashes were the default recommendation in PBP.

PS: You also asked what worse mistakes I made in PBP. One of them was not finding a way to adequately get across that the advice in the book is meant to be a starting point, a default zero-state, an initiator of conscious thought, rather than an end-point of discussion. Gods know, I tried to convey that (devoting most of the first chapter to the idea), but I stupidly didn't put any code in that chapter, so most readers just seem to skip straight over it. :-(

  • Comment on Re^4: Named Subroutine Parameters: Compile-time errors vs. Run-time warnings

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://766987]
[Corion]: Hmm - HTC Vive reduces its price to EUR 700 (from EUR 900). Now I have to look what graphics cards prices are - maybe a good enough VR rig can be had for EUR 1500 now instead of EUR 2000(+)
[Corion]: Hmm - nVidia GTX 1070 + Vive makes EUR 1130, leaving EUR 370 for CPU+case+cooler+ RAM - not bad
[Corion]: (I'm not a fan of AMD)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-08-21 08:31 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (319 votes). Check out past polls.