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

Re^2: Creating accessors on the fly, or not...

by dsheroh (Prior)
on Jun 13, 2009 at 12:16 UTC ( #771222=note: print w/replies, xml ) Need Help??

in reply to Re: Creating accessors on the fly, or not...
in thread Creating accessors on the fly, or not...

Can you point me to a good explanation of why make_immutable is recommended?

Going through the first 50 google results for "perl moose make_immutable", I came across a few statements that "make_immutable is a Moose best practice", but none of them stated the reason for it. Is this solely because it makes object creation faster (as shown by Pichi's Moose benchmarks) or are there other reasons aside from performance?

Replies are listed 'Best First'.
Re^3: Creating accessors on the fly, or not...
by stvn (Monsignor) on Jun 13, 2009 at 18:07 UTC
    Can you point me to a good explanation of why make_immutable is recommended?

    So in an effort to contribute to the Iron Man blogging challenge I have posted a response here. I will copy the "short answer" part of my post here, but for a more detailed and in-depth explanation check out the blog post.

    So the short answer is that making your class immutable is good because it memoizes several metaclass methods and installs an optimized constructor and destructor for your class and therefore helps reduce a fair amount of the cost (during runtime) of all the abstraction that the MOP provides.

      Thanks for the very thorough answer! It really clarifies why, in Pichi's benchmarks, the immutable version creates objects about 10x faster than the mutable one. (And I'm always happy to provide someone with an excuse for an Iron Man post, seeing as I always seem to be looking for them myself.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://771222]
[Corion]: holli: Hahaha :-D
[choroba]: When working at a bank, we had a colleague who entered mining early enough to have lots of bitcoins. He used to say "I go to work just because I'm too bored at home."
[Corion]: choroba: Aah, no, I do it because of the money :)
[choroba]: And when asked "How are you?" in the morning, his reply was usually "I don't know, haven't checked the bitcoin rates yet."
[Corion]: Heh - if I defined myself through the money I make, I would now only be 80% myself :-D
[choroba]: :-D

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2017-09-21 15:29 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (249 votes). Check out past polls.