canspice.org

home about code feeds archives links

Archive for July 2008

OSCON 2008: log4perl, by Mike Schilli

Why log? Logging can help you debug during development, go back in time and figure out what happened, measure performance, and to trace activity on live systems.

So why use Log4perl? It doesn’t have any CPAN dependencies. It’s easy to use, but scales with complexity. And it has some unique features.

There are four different kinds of remote controls: levels (log/suppress priority/level), loggers (locate it in the system), layouts (format it), and appenders (write it out).

In your code, you can set different levels by doing things like:

DEBUG "Starting up";
ERROR "Cannot open file $file";

The output layout can be modified:

Log::Log4perl->easy_init( {
  level => $DEBUG,
  layout => "%r %M %F-$L>%m%n",
});

If you’re doing more complex things like this, Schilli recommends using a config file: Log::Log4perl->init( “l4p.conf” );. The benefits of config files is that you can modify them independently from the program, modify it while the program is running, and it can be modified by people who don’t know (or can’t access) the code.

You can set Log4perl up so it looks for a specific configuration file. Not only that, you can set it up to reload that configuration file at any given frequency, which allows your logging to be modified while your program is running.

The available appenders are: Screen, File, Socket, DBI, Synchronized, RRDs, and a bunch more supplied by Log::Dispatch. You can set up rotating logfiles via Log::Dispatch::LogRotate.

Layouts support all kinds of different information, and if there’s a layout pattern that you want that’s not available, you can define new ones.

Log4perl isn’t “free” in the speed sense: 50k logged messages per second gives you some overhead in your program.

Wouldn’t it be nice if more CPAN modules were Log4perl-enabled?

Tags: , , ,

Yahoo! Music being turned off

Compare this snippet from c|net news:

Yahoo is shutting off support for Yahoo Music after September 30, which means starting October 1, if users want to move music to new hard drives or computers, they will be out of luck.

…with this snippet from canspice.org:

However, if the company goes bust or raises its prices, you’re left high and dry. You could either continue to pay the monthly fee or not be able to listen to your music.

This disadvantage for the pay-per-month scheme is huge, and is the major reason why I think it’s the stupidest idea ever, and people who “buy” their music this way are throwing away their money.

I hate to say “I told you so”, but I told you so. Subscription-based music stores were stupid, are stupid, and will continue to be stupid.

Tags: , , ,

OSCON 2008: Ultimate Perl Code Profiling, by Tim Bunce

Tim Bunce is the author of the recently-released NYTProf v2.

I unfortunately missed the first five minutes of this seminar, as I was tied up giving an interview for O’Reilly News with chromatic. Tim, chromatic says hi and thank you for the help with XS.

NYTProf v2 does subroutine profiling, meaning it is a statement and a subroutine profiler, at the same time. The subroutine profile tracks time per calling location. It calculates exclusive time on-the-fly, and discounts the overhead of statement profile. To minimize disk I/O, it does everything in memory and writes to a file at the end. It’s also extremely fast. Statement profiler gives correct timing after leave operations.

v2 does sub microsecond resolution. It reports correct timing for mod_perl, handles forks with no overhead. Profiling can be enabled and disabled on the fly, and can profile compile-time activity.

When Tim asked for questions, Adam Kennedy asked, “The only question is, ‘Why are you so awesome?’”

The plan is to merge multiple runs, so say from running code through a test suite.

Reporting is only done via HTML or a CSV file. Tim isn’t too happy with this, thinking that he could come up with some pluggable class structure.

Trace file size depends on how long the profiler runs on your program. For example, running perlcritic on the NYTProf source code created a 360MB to profile 26 million statements. This ran for a minute and a half (which normally takes 30 seconds).

Tags: , , , ,

OSCON 2008: Skimmable Code, by Michael Schwern

The full title of this talk is “Skimmable Code: Fast to Read, Safe to Change”, and it’s presented by Michael Schwern.

What does Schwern mean by “skimmable”? He means in terms of like skimming a book — you skim through the book to find info you want, rather than studying the entire thing, because you want to find the info fast.

Why skim? It allows you to focus on a single task. It lets you slice through hairy code. It lets you free up brainpower. This talk is essentially applied best practices, it explains the reasoning behind best practices.

How do you skim? It all comes down to narrowing your focus. How do you do that? Your primary weapon is “lexical encapsulation” — look at the stuff that’s right in front of your face. Not the subroutine calls, not method calls, just the stuff between the braces (that’s in your lexical scope).

Tests are useful for making code skimmable, because at the touch of a button you can see if your modifications have broken anything. When refactoring code, refactor, then test, then commit, then repeat. If you fail a test, you can find out where you’ve broken things (and always test before committing).

Rename refactoring: use good names. For example, calling something $arg isn’t useful; call it something that describes what it is actually used for. This way you don’t have to keep referring back up to the top to figure out what the argument is.

Extract refactoring: extract routines and methods out to prevent other routines from doing too much that you can’t keep it all in your head. After you extract routines out to subroutines, it cleans up the structure of your program and you may be able to extract more routines out to subroutines again.

Whitespace allows clarity. Vertical whitespace can be used to differentiate between major blocks in your code. Similar things should look similar, so if you’re using a hash constructor try lining up the fat commas.

Different things should be displayed differently, e.g. $lexical vs $Global.

Red flags: No documentation. No tests. Things are deeply nested. Compound names (e.g. make_waffles_and_pancakes. Generic names (e.g. @list, $arg, $data). Overly verbose (e.g. $total_amount_spent_on_food). Globals. Scope closing comments. Long routines.

Tags: ,

OSCON 2008: Thursday Morning Keynotes

We kick things off with Keith Bergelt talking about “Open Invention Network and Its Role in Open Source and Linux”. We’re just part of a larger group that exists to tackle current realities and problems with intellectual property and open source. One of the realities is that open source is the single-most important invention and innovation modality to come into being in the post-industrial era. (Oh no he just used the word “utilize”. Oh no “paradigm”.)

<CosmicRay> is this one of the talks that was randomly generated by that conference talk generator that was on /. awhile back?

The reality is that there’s a growing number of patent trolls, and people are turning this into a business model. Defensive patent pools are growing. Rabble rabble business speak rabble rabble.

Next up is Peter H. Salus talking about “Anniversaries”. Please don’t be as boring as Keith Bergelt, please! This looks to be an historical talk about software and whatnot. We talk about anniversaries and make the call that anniversaries are special when they’re divisible by 5 or 10. For example, this year is the 250th anniversary of Darwin’s birth. Last December was the 60th anniversary of the transistor. In the same year, IBM installed the first SSEC — selective sequence electronic calculator — the first electronic computer, in the modern sense of the word. A decade later DEC started with venture capital of $40,000. In 1963 Project Mac was formed at MIT — and out of that came computer sharing. Ten years after that the first Unix paper was written by K&R.

Next year is going to be a great one for anniversaries: moon landing, Unix, ARPANET with four nodes — expanded to 216 in eight years and they were worried about hitting 256 and running out of address space. “If you pay attention to history, all of the stories are old stories. The magnitude may change, but they’re all the same stories.” First free software meeting was in 1996.

He’s coming out with a book soon about the history of open source, which should cover most of what he’s said in this keynote.

After Peter comes David Recordon of Six Apart with a talk titled “Supporting the Open Web”. We’ve been talking a lot about open source, and there’s a lot of open source to talk about. Open Data is increasingly important as services move apart. The open web needs open data, and open data needs open specifications. The web needs to be accessible everywhere. In 2007, the web started becoming more open. OpenID, OAuth, and Open Social are all quite similar: they have communities ranging from individuals to companies, implemented in many languages, being adopted at an increasing rate, and are occurring outside of formal standards bodies. The Open Web Foundation is announced so companies and individuals can come together to work on the open web. It will focus on four things: incubation (creating new open specifications for the web), licensing (or really no licensing; non-assertion agreements), copyright (Creative Commons for each specification), and community (to support the open web).

Danese Cooper comes next with her presentation about how “Why Whinging Doesn’t Work”. She kicked things off with the Helsinki Complaints Choir. Why do we love to whinge? There are a lot of theories: misery loves company, we do it because we’re fundamentally afraid. Confirmation bias is “what you believe comes back to you” — if you believe that the glass is half-empty, then you’re going to see half-empty glasses wherever you look.

What does complaining do to us? It makes us isolated. You need to think differently — Billie Jean King pulled her competitors together to rally for equal pay for female tennis players as male tennis players. We need to recalibrate our language. We need to radiate gratitude — i.e. Randy Pausch. We need to acknowledge others. We need to be the world we want to live in.

Yay! Nat is back! Nat’s talk is titled “fork() && exec(): Spawning the Next Generation of Hackers” which sounds awesome. No aloha shirt though. :( This talk is not about how to have sex. This talk is about raising children to use computers. When Nat moved to New Zealand, he found that the primary school had utter crap for computers, and the administrator had the best one in the school. Nat ran Kiwi Foo and took some of the leftover money and bought the school a nine new computers. Then who could teach the kids how to use them? The teachers couldn’t because they had crappy computers and didn’t have the right skills, so Nat did. He had to start off with basic computer skills, but he wanted to move to teaching them how to program.

Programming is like changing a tire. It’s not rocket science. Nat kicked things off by running a computer club. He started with Lego Mindstorms, but the kids found them lame. You can make them go forwards, backwards, turn, and follow a line on a page. But they don’t, so robots aren’t that great for kids who need consistency and get disappointed when the Mindstorm goes off on some random tangent. scratch is much better for kids. With his own kids, once they progressed past scratch he moved to processing, which is more complex.

Lessons: lectures suck. You have two minutes tops when you stand up in front of kids. The gender gap is not what you think (at the eight-year old level). You have to follow their interests. Keyboards are a challenge. Math skills aren’t there yet (angles, e.g.). Teachers need teaching. Robots = lame.

An immodest proposal: 1) Volunteer in schools. 2) Courseware. Look at scratch, build your own courseware and share it.

Further reading:

Tags: ,