Introspection with Perl’s Moose

Posted: August 11, 2010 by mpdehaan in Uncategorized

Here’s how to get a free “to_json” method in every object you write. Just extend from a common introspective base class:

use MooseX::Declare;

class BaseObject {

    use signatures;
    use JSON::XS;

    has 'id' => (isa => 'Int', is=>'ro', writer => '_id');
    # and more ...

    sub to_json($self) {
        my $result = {};
        foreach my $attr (__PACKAGE__->meta()->get_all_attributes()) {
            $result->{$attr->name()} = $attr->get_value($self);
        }
        return encode_json($result);
    }
}

Obviously this code needs to check for any objects that it should nest recursively and those that don’t support JSONification*, but that’s coming.

* = is too a word.

Skip your MBA, Play Starcraft

Posted: August 10, 2010 by mpdehaan in Uncategorized

Theory: All good business strategy can be learned from computer games.

(A) You must get your base in order before you to go war.

(B) You must consistently invest in tech upgrades or you will get clobbered by more advanced units.

(C) You can’t concentrate on giving orders to all of your units at once. Thankfully, workers keep mining minerals until they run out. They don’t need a lot of clicking. Invest time in moving the right units.

(D) Avoid “all in strategies” like the protoss cannon rush or zergling 6 pool (especially for startups).

(E) You have to scout your opposition frequently. React to their changes in game plans, but also force them to react to you (then plan for their reaction).

(F) You have to talk to your allies to formulate a joint plan. Going in all with random strategies rarely works. Sometimes you just have to go along with the flow, if they are attacking, don’t let their plan fail.

(G) All your troops attacking at once is better than each of your troops attacking one at a time. Strength in numbers.

(H) Don’t forget your barracks can fly. What direction the “business” is going in is completely arbitrary and can be whatever you want. Don’t confine yourself to what you conceived the definition of X to be 5 years ago.

(I) Always have a plan. You can change the plan, but always have a plan.

(J) Keep building new worker units, cause they are going to get killed off by reapers eventually.

(K) Try not to keep too much gold on hand. If you have a lot of money, don’t pay your CEO’s lottery money. Use it to buy upgrades for your troops and buy new troops where you need it.

(L) There are no rules. It’s a game.

(M) Be aggressive. If you sit back and turtle up in your base, you will get smacked down by void rays.

Next up in the series — how doing your own plumbing is just like Super Mario Brothers.

Moose is a really impressive object system for Perl (mixins! traits! AOP! all optional fancy stuff!). MooseX::Declare is even more impressive, because it adds a clean Python/Ruby style syntax for methods, but also allows type checking. It’s pretty awesome. Though, there’s some perception that it’s slow. Is it?

(edit -- work in progress)

‘function’ above is a non-OO double loop that does something ‘remotely meaningful’. As you can see, moving to Perl OO makes it signficantly slower … but what’s amazing here is that MooseX::Declare or Moose does not really impose any additional cost to method calls. MooseX::Method::Signatures seems to totally suck, so we’ll throw it right out. But the other results — this is quite something. Note that this is without any type checking, but it shows that no additional cost is imposed. What about object initialization?

Moose new    6250/s
MooseX::Declare new  83333/s
normal perl OO new     200000/s

Here you see that there’s an obvious cost to Perl OO versus MooseX::Declare, but that’s blindingly fast. The relative speed is not important in the context of an application that does anything on top of this. The other interesting fact is that the much more desirable “MooseX::Declare” is actually faster than the regular Moose with regards to new. I haven’t determined why yet, but haven’t found the need to look — the better of the two alternatives came out on top. The next step is test the cost of the type checking with MooseX::Declare versus basic Perl OO untyped methods to see what that is.

One interesting find here is that if you use Moose and actually add the “package” keyword (which is unnecessary because the package name is the class name), they do get slower. Not sure why, but if you leave it out, the performance quickly falls in line with Perl OO norms. Also note all the tests are running non-trivial functions (just a couple of nested loops and a return) so that’s included in the test results. Given that Perl is known to be somewhat faster than a few other dynamic languages anyway, this is quite promising. The result is that Perl OO with Moose probably is probably on par with Python or Ruby, if not faster. The concern about overhead expressed in the Perl community really isn’t that serious at all.

Files used as a result of these tests can be found here. More likely to come, as well as examples of clever tricks that can be done with the library.

Update: combine “use MooseX::Declare;” with “use signatures;” and you loose some control over typing (and maybe some AOP), but “use signatures;” is exceedingly fast.

use MooseX::Declare;

class Foo extends Bar {
    use signatures;
    method new(...)
    sub other_stuff(...)
    ...
}

It’s also very easy to use methods for when you need them, and to mix and match the two. What would be really nice though is if there was no time/speed penalty for using “method” when “method” specified no types. I’ll have to ping the author about that one.

Mine’s not a high horse

Posted: July 17, 2010 by mpdehaan in Uncategorized

Previously on this blog I’ve posted a lot about Open Source Software Development.

I have determined that, while in many ways, while OSS has benefits, in general this is not what I liked about OSS. Primarily I used OSS to supplant an actual local team, formal Q/A, budget, and marketing at a certain OS vendor. If I had actually had those things available to me, that would be superior. (And, I bet, I’d have a lot better of an application).

OSS generally does well at producing at development tools — ultimately there are a lot of things OSS can’t create quite as well — multimedia applications (Lightroom, Hollywood animation packages), high end music production programs, best of breed CAD packages, desktop environments (OS X), really good games (many OS purists have consoles and don’t just play TuxRacer), iPads, motor vehicles. In many cases, going OSS for these things is product suicide — there’s no win giving it away (your competitor will just use it), and listening to too many voices at once is bad for you, just like multitasking too much it can make you stupid and not allow you to depth first dive into new territory. Further, you need paid employees and domain experts working on these things — there’s a huge cost to releasing really good software, and it’s not a hobby. Management software? I think there’s a good benefit still to being able to take patches, but there is no substitute for being able to fund developers to help you out. The idea that people just come together and hand you brilliance is not /totally/ the case. One thing I really do hate though is the idea of community Q/A’d or poorly Q/A’d software. This often makes OSS projects less reliable in many cases. Not a good thing. Is it good for operating systems and hardware support? Maybe… but I like OS X hardware just working and not having to fight ‘xrandr’ more than having freedom over the right to choose my monitor. But that’s just me.

I think another thing I liked was the BFDL position — in that vein, it’s fun to do everything and have your hands in all aspects of a project — it’s not found in many places unless you are employee #1 or so. It’s also a tremendous battery drain that haunts your dreams (how many dreams did I have about systems management? how do you keep the world happy?). So it’s good and bad. OSS communities aren’t all the same either — some are very very different. Lots of projects don’t have any community, and people get a lot of happiness out of the code. That’s fine. Lots of groups build things internally and then “throw the code over the wall”. If you have a local team, use it. That’s fine — going “really open” has a ton of cost. Trying to please everyone is not a good thing, for sure. OSS users can be very demanding for the levels that they give back (or don’t). In retrospect, as much as I enjoyed it, my level of community involvement could have better been applied to development in many cases… but I wouldn’t have as wide of a following, because you do win fans touring, so to speak. And by touring I mean “helping out on IRC”. Though I think that’s not the only way to market an application. (I am still wondering how much I could have made if Cobbler had gotten a commission off of each of the servers it deployed).

Anyway, I thought I should clarify my position just a bit, having had quite a while since I left Cobbler and associated projects. My advocacy earlier implied some other routes of development were less pure. This is wrong. My interest is really in creating things and collaborating. I think your frame of reference (working for a major open source OS vendor) it makes it easy to get caught up in the cause and quasi-religions of it sometimes, and when you see it from the outside, you see how the support model *mostly* depends on you having a codebase people are afraid of — like the kernel. If you have an end user app — it working too well cuts into your support.

Open & transparent government is a good cause. Open & free educational resources is a remarkable cause. Software? About as important to me (personally) as refrigerators being open. As I hinted on when I was searching for higher meaning in software — the legacy of OSS software will be on what /else/ it opens up. Open Source is fun, I’ve learned from it, but we can take lessons from proprietary applications as well — particularly in terms of how you can better organize a set of people all working towards a common cause, rather than 100 slightly different causes. I also enjoy talking more to people who are willing to pay for what they use and need — I find them to be much more reasonable.

I have believed in things for the wrong reasons basically. Had a certain OS vendor given me, say, staff, I wouldn’t have cared if they were Microsoft. I don’t hate Microsoft because they are closed, I do because they make really bad software that eats viruses for breakfast — and tends to go after other innovators. But for being closed source? Not at all anymore.

Monomachine Sunday

Posted: July 11, 2010 by mpdehaan in Uncategorized

Today, I found some time to play with my new Monomachine for more than 30 minutes. By which, I mean, about an hour.

This was done in song mode, and then recorded straight through Reaper, with no external effects. I’ll get to something more deliberately composed (and longer) later — I really want to crank out something a little more Zelda/Castlevania/Megaman chiptuney, or maybe MacGyver Theme Song meets Pseudo-Industrialness.

I also found some time to play around with the SV-1 some more, with the reverb on 11 and the univibe on 12 a wurlitzer can get pretty interesting :)

BTW, I’m kind of liking the new Broken Bells album (love the Hammond mixed in with that style of music) … which makes me think, in the vein of all of this, Danger Mouse needs to hook up with the Minibosses and do an album. I need to pick up the new Robert Randolph album — kind of curious to see how their direction is shifting, and wish they’d come back through NC again soon.

Creating Case Sensitive Volumes on OS X

Posted: July 6, 2010 by mpdehaan in Uncategorized

For future reference, seeing the OS X GUI tools aren’t too clear about this, here’s how to create a case-sensitive 5 GB volume using command line tools:


hdiutil create -megabytes 5000 -fs "Case-sensitive Journaled HFS+" -volname SomeName ~/SomeFileName

For encrypted volumes, add:


-encryption -stdinpass

Book Quotes II

Posted: July 1, 2010 by mpdehaan in Uncategorized

The Kindle (or app) has a nice feature where it can save quotes from books. Here’s some extracted quotes and randomness from a few books. I’ve read a lot of other things in the meantime, but for some reason I find Card and Herbert more quotable than most. Herbert perhaps too much so in a good way. Card has obvious religious overtones at times, but it’s still interesting. I think some of this is relevant to government, some to life, some to work / programming, and some to global thermonuclear war, and some simply not relevant to anything but just interesting.

Orson Scott Card’s “The Speaker For the Dead”: — read this before when I was a kid, decided to re-read it.

“The difference between raman and varelse is not in the creature judged, but in the creature judging. When we declare an alien species to be raman, it does not mean that they have passed a threshold of moral maturity, it means that we have.” — Demosthenes, Letter to Framlings

“his genius — or his curse — was his ability to conceive events as someone else saw them”

“Watch closely, folks, here it is: Science, the ugly beast that devours itself!”

MIRO: “Haven’t any of you ever touched the fence? (Human does not answer.) It’s very painful to touch the fence. To pass over the fence would be like every part of your body hurting as bad as possible, all at once.”
HUMAN: That’s stupid, isn’t their grass on both sides?

“We become one tribe because we say we’re one tribe”

“When you really know somebody, you can’t hate them.” / “Or maybe it’s just that you can’t really know them until you stop hating them.” / “Is that a circular paradox? Dom Cristao says that most truth can only be expressed in circular paradoxes.”

“When it comes to human beings, the only type of cause that matters is the final purpose. What a person had in mind, Once you understand what people really want, you can’t hate them anymore. You can fear them, but you can’t hate them, because you can always find the same desires in your own heart”

“As long as you keep getting born, it’s all right to die sometimes”

Frank Herbert’s Chapterhouse: Dune — I think I finished book 6 finally earlier this year. Towards the end of the series he gets into some interesting political/philosophical stuff, despite the story getting a little less focused. You have to ignore most of the middle books before Leto becomes the giant worm, because it’s just random and not that philosophical, IMHO.

“Those who would repeat history must control the teaching of history.”

“… humans were life designed by evolution to create order.”

“Because you’re human and humans have this deep desire to classify, to apply labels to everything” / “Why do we have to name things like that?” / “Because that way we lay claim to what we name. We assume an ownership that can be misleading and dangerous.”

“Enclosures of any kind are a fertile breeding ground for a hatred of outsiders”.

“We tend to become like the worst in what we oppose”

“You cannot manipulate a marionette with only one string”

“We become what we do”

“Life is a game whose rules you learn if you leap into it and play it to the hilt. Otherwise, you are caught off balance, continually surprised by the shifting play. Non-players often whine and complain that luck always passes them by. They refuse to see that they can create some of their own luck.”

“All governments suffer a recurring problem: Power attracts pathological personalities. It is not that power corrupts but that it is magnetic to the corruptible. Such people have a tendency to become drunk on violence, a condition to which they are quickly addicted.”

“Memory should bring wisdom but it does not. It is how we order the memory and where we apply our knowledge.”

“And she finds that events are not beyond her influence, but merely beyond her senses”.

“He was not so prescient as he was a cement. He fixed the shape of what he saw.”

“You accumulate a lot of small observations, sensed but never brought to consciousness” … “Cumulatively, they say things to you but not in a language anyone speaks. Language isn’t necessary.”

“I read myself, not the person in front of me. I always know a lie because I want to turn my back on the liar.”

“You approach everything with a clean slate, nothing on you or in you. Whatever comes is written there by itself”

“Mentats accumulated questions the way others accumulated answers…”

“Leto thought of all mankind as a single organism”.

“That is why we accepted him … He did not play by our rules, but he played for our goal.”

“Don’t spend any time dealing with how the conventional teacher feels threatened by emerging talents and squelches them because of a deep-seated desire to feel superior and safe in a safe environment”.

“Many things we do naturally become difficult only when we try to make them intellectual subjects. It is possible to know so much about a subject that you become totally ignorant.”

“Laws to suppress often strengthen what they would prohibit. This is the fine point on which all the legal professions of history have based their job security”

“Show me a completely smooth operation and I’ll show you someone who’s covering mistakes. Real boats rock.”

“There is no reality. Only our own order imposed on everything.”

“The oppressed will have their day and heaven help the oppressor when that day comes. It was a two-edged blade. The oppressed always learned from and copied the oppressor. When the tables were turned, the stage was set for another round and revenge and violence…”

“The more people on the committee, the more preconceptions are applied to the problem”.

“Democracy is susceptible to being led astray by having scapegoats paraded in front of the electorate. Get the rich, the greedy, the criminals, the stupid leader, and so on ad nauseam”

“Democracy is a stupid idea anyway!” / “We agree. It’s demagogue prone.”

“You must pay no attention to the words. Watch what the person does. That way you learn the motives.”

“Face your fears or they will climb over your back.”

“To know a thing well, know it’s limits. Only when pushed beyond it’s tolerances will true nature be seen”.

“Do not depend only on theory if your life is at stake”

“Sympathy for the enemy — a weakness of police and armies alike — Most perilous are the unconscious sympathies directing you to preserve your enemy intact because the enemy is your justification for existance.”

“Never choose a course just because it offers the opportunity for a dramatic gesture”.

“I am not a river, I am a net”

“Our gods should mature as we mature”

“The greatest relevancy can become irrelevant in the space of a heartbeat. Mentats should look upon such moments with joy”

“He asks, I give him candid answers. I don’t believe in doing violence to curiosity.”

“Enter no conflict with fanatics unless you can diffuse them..”

“Does my knowledge still apply?”

“Your habits always come hunting after you. The self you construct will haunt you. A ghost wandering in search of your body, eager to possess you. We are addicted to the self we construct. Slaves to what we have done.”

“War is behavior with roots in the single cell of the primeval seas. Eat whatever you touch or it will eat you.”

“The victors bred. We are their descendants. Victory was often gained at great moral price. Barbarism is not even an adequate word for some of the things our ancestors did”.

“Do not give someone a stick with which to beat you”

“Seek freedom and become captive of your desires. Seek discipline and find your liberty.”

“Making workable choices occurs in a crucible of informative mistakes”.

“Trying to avoid complications often creates them”

New England Aquarium (and other photos)

Posted: June 29, 2010 by mpdehaan in Uncategorized

Here are some pictures from the last Boston trip:

Notice I do not take pictures of people giving keynotes and tech presentations. Why? Because no one likes looking at those pictures :)

(The last two in the set are from two years ago)

Red Hat Summit and USENIX, & Putting Hats On Penguins

Posted: June 29, 2010 by mpdehaan in linux

Last week I flew up to Boston to hit up both Red Hat Summit and USENIX.

I’ve posted about Summit before, so not much new, but my talk with Rafael from the NYSE (mostly Rafael’s talk), drew a standing room only crowd (correction: no standing room at all!), which was nice to see again. Red Hat Summit was pretty much the usual; food was pretty terrible (or perhaps San Diego’s Summit was just delicious) but still enjoyed hanging out with friends very much. I also hosted a Campground session afterwards with some of the Red Hat Systems Management guys. Boston was extremely nice, and even had it’s own mini-heatwave to make us North Carolina folks feel like home. Found a little free time to check out the New England Aquarium, which has a fantastic penguin exhibit. It’s not as fancy as Shedd in Chicago (no Beluga whales or fancy theater show), but it’s really good.

Thursday I spoke at the configuration management summit at USENIX (held at the Sheraton, where Summit was 2 years ago) — along with Mark Burgess from cfengine, Aaron Peterson from chef/opscode, and Narayan Desai from bcfg2 and Argonne National Labs. We did regular talks and also the panel thing, which was a bit like I imagine testifying before Congress must be like. No, Mr. Senator, I do not use OS/2! During the afternoon Barcamp sections I also presented on some other systems management tool projects I’ve worked on in the past, which I hope was useful to folks as they fill in the other gaps of their systems management tool suites. It was hot getting back to South Boston — no AC in the T stations — but the underground electric bus tunnels were pretty awesome. Moral of the story though — if you are holding a conference, don’t have it at the same time as vendor conference and an O’Reilly conference devoted to the same subject. 60 or so people came, but there could have easily been a lot more.

Incidentally I’m going to be leaving Puppet Labs after this week, for a new position that I’m very excited about (more details to be announced later). As this signals my exit from open source software and systems management software, I intend to do something heretical that I’ve been unable to do for some time. Maybe I’ll buy an XBox or install Windows 7. Maybe I’ll put a hat on a penguin. Anyway, I’m looking forward to it a ton.

I’m just about done uploading pictures from SouthEast Linux Fest 2010. As Ian Weller mentioned, we had a pretty good random photo walk in the middle of it, and I think that’s a fine conference meme to continue in the future.

But seriously. Damn. What a huge conference for being in Spartanburg, SC. No disrepect, home of the mighty Wofford Terriers, but wow, we did not expect this from you. At all. The South East Linux Fest crew — David, Jeremy, scores of volunteers — well done. You shame Raleigh, Durham, and RTP. You bring envy to Atlanta. You bring folks travelling from near and far. SELF Folks, you not only put my previous attempt at Evil Robot Conference to a level of shame where it looks like kickball to the scale of the world cup, but were also incredible hosts to all of us. Thank you immensely.

I gave a talk about Puppet and why datacenter automation is important, with a few nods to previous projects I’ve worked on (cobbler, Func) thrown in — pretty well received I think, about 60 people were there and there were a lot of good questions. There were a lot of other good talks though, I’m most excited about Ian’s datanommer as it inherits a lot of legacy (euphemism intended) from some past projects of my own. I was also quite happy to see all the new folks who turned out for the FAD– quite a good difference from the usual FudCON where we typically already know most of everyone. I think this underscored, very very well, how much of a democratic and friends-helping-friends kind of community Fedora (and Linux) can be. Major points for reaching out and keeping the barrier to contribution down. Ubuntu can have some very polished initiatives, but they need to work at being less centralized, that is for certain. I hope they learn that lesson as they grow.

It was also nice to talk with lots of folks I had met at previous conferences, plus the cool folks at OpenNMS, ZenOSS, sqlite, and XenSource. I will certainty be back next year. You should to. Especially if it’s right next to the Krispy Kreme again.

Cinnamon Apple Filled, I am glad you are back.