LPW Recap

Purdy on 2004-12-14T02:31:32

Long entry here - I wrote this up on the plane ride back ... you've been warned.

7 hours of sleep does do wonders, though I probably shouldn't have gone to bed around 9pm, as my body woke up at 4am and wouldn't go back to sleep. There's really not much to do at 4am, let me tell you! So I flip and flop back & forth, try throwing in earplugs, etc. All to no avail. So around 5am, I give up, wake up, get ready and read and surf the TV channels.

The burst of sleep has helped my attitude – I have decided to not worry about the money and diet parts of this trip, though I won't be doing any Christmas shopping.

I met up with cog in the hotel at 8:30am and we eat breakfast and then walked over to LPW (which was a brisk 30 min. walk – oh well, that should help burn off those carbs I've been downing). Coincidentally, that morning, I saw on the front page an article that Britons are ignoring government warnings on eating healthy, with increased sales of cakes, chocolate, beer and wine, etc. As I mentioned in my previous post, I've found it impossible to stay on my diet over here, so I've just given up. Now I'm not saying that a low-carb diet is THE way to go, but the typical food around here is very unhealthy, with the high-fat AND high-sugar. I almost fell in shock when I saw my first “sugar-free” candy in the tube.

Ok, so back to LPW. Overall, I was very impressed with the workshop. I attended the Learning Perl talks and they were timed at 30 minutes apiece (with some presenters opting for even less time), which made for a good compression rate, as any longer and my attention wanes or my head gets full of the material and cannot handle any more. Another nice feature of the talks was that they started with the basics and built up to more complex matters and upon previous talks.

The first talk (an Introduction by Dave Green) was kind of a keynote, which was pretty funny, which is saying a lot from me, as I find it very hard to laugh that early in the morning. He gave some great Perl cameos in the mainstream media as well as breaking out into some Karaoke, with a homespun song, “Tainted Perl.” Great start!

The next talk was “Perl Gimmes” by Greg McCarroll, which was half-tutorial and half-rant. The one thing I learned from that talk was the difference between || and or, though that was because I was sitting next to cog and he helped me understand it. Basically, Greg mentioned that these two perl lines were different: open FILE, $filename || die “Cannot open $filename: $!\n”; open FILE, $filename or die “Cannot open $filename: $!\n”; I didn't get it.. I didn't see the difference. Thanks to cog, he pointed out that it's a precedense thing, where the difference is like this: open FILE, ($filename || die “Cannot open $filename: $!\n”); ( open FILE, $filename ) or ( die “Cannot open $filename: $!\n” ); So if $filename is true, you'll never get the die to evaluate, regardless if the open failed. So that's cool to know, but I've never had that bite me because I've always used the format: open ( FILE, “$filename” ) || die “Cannot open $filename: $!\n”; That's just my coding style and come to find out, it's helped prevent this from worrying about this.

Greg also highlighted the Log::Log4Perl module, which seems pretty interesting. He said it's a standardized way to do logging on your applications, which I could definitely use. I don't know how many times I've either written my own or used DBI's trace as a log.

The reason I mentioned that his talk was half-rant was that he ranted on “Don't Ask to Ask a Question”

The next talk was “Perl coding best practices” by Mark Fowler and the best thing I learned about this is to not be scared of die(), especially when you're coding in what will be a nested object, because the code that uses it can do an eval and then use $@, like so: eval { $my_object->dicey_function( $dicey_data ); }; if ( $@ ) { # there was some problem } So now in my deeply-nested object, I can put die's all over the place and $@ will contain the message that you passed on to die, so you can do custom error handling.

Next up was “Sorting out sort” by Lance Hoffman, which was a cute little presentation, even involving audience participation. The main thing I learned from that talk was that when you write your own sort method and Perl gives you $a and $b, your custom method needs to return -1 if $a is less than $b, 0 if they're equal or +1 if $a is greater than $b. I never really understood that, as all my custom sort methods are either an override of the standard lexigraphical sort to a numerical sort and then flipping $a and $b if I wanted the reverse. Another important point I learned is that you don't want a lot of time-intensive logic in your custom sort method because it will be called quite a few times in the process of sorting an array. Something like N*log(N), which for an 8-element array can be called 33 times!

Marty Pauley gave the next talk on “Testing basics. Introducing Test::Simple and Test::More”, which was a challenging talk, as I KNOW I should be writing tests before writing the code, but I don't. So this was yet another reminder that I need to get my act together. ;) Marty was very entertaining (what is it with the British and their quick humorous wit? Must be the Monty Python...), too. Test::Harness comes with the prove command, which can be useful for non-module code. Test::More also extends Test::Simple with more functionality (ok, is, isnt, is_deeply, cmp_ok, etc) all while offering compatibility with the Test::Simple API.

Next up was Dave Cross with “Writing objects in Perl”, which I'm sure was a challenging talk to give in 30 minutes! Dave did an admirable job and it really dawned to me what objects really are in Perl. They're simply a declaration (package ...), a constructor (which initializes the internal hash {or other data structure}) and support methods. The only complaint I have w/ the talk is that he didn't go into the export aspects, which is where I am currently in my learning with objects, though I'm sure that was more of a constraint issue with the amount of time that Dave had (or didn't have, rather). No worries, though ... one late-night session with cog cleared that up.

The next class was John McNamara's presentation on “Spreadsheet::WriteExcel”, which is a module I will be looking into real soon. It provides an API to write out data in the Excel binary format. There's even a complementary Spreadsheet::ParseExcel, which could be used to open an uploaded Excel spreadsheet, for example.

After lunch, classes resumed with Tom Hukins talking on Class::DBI. This was one of the main reasons I wanted to come to the conference, because that's the next evolutionary step for me. I was disappointed that Tom spent time on background and DBI itself, but some of the circular concepts he covered did bring up some other modules that I should take a look at, including Ima::DBI, which can be useful for separating the SQL code from the Perl code, and Template::Plugin::Class (actually, I don't remember why I wrote that down now, but I'm going to check it out later).

Leo Lapworth gave the next talk on “Pages, results and caching”, which highlighted the Data::Page and Data::PageSet modules. After going over those, he did get a little more complicated with caching, so it was hard for me to understand, but one thing that came to comprehension is that disk caching is faster than database accesses. After the conference, in a talk with cog & his friend Peter, they also talked about how you could cache into memory to get even faster. Who cares if the data is lost when it could be rebuilt? So this could also have ramifications into how I build our Web applications, so that's pretty neat.

The next talk was on MVC and building Web Apps rapidly, by Ben Evans. Ben talked about separating the code into MVC layers, something I'm very familiar with already, with extensive experience with CGI::Application. It looked like cgiapp, smelled like cgiapp, but Ben actually handrolls his own architecture for every application. I asked him afterwards why and he said it was because he couldn't guarantee that CGI::Application could be installed on the servers he works with.

Barbie gave the next talk on CPAN testing, talking about the Phalanx project and how the CPAN testing service works. The main emphasis is to prompt the module authors to strive for a greater common demoninator and increase the quality of their code and packaging. I know it has helped me with my modules, as I would get messages, letting me know that my package was missing a file. The only gripe I have is that I cannot perform similar testing on my own box (or maybe I can & I just didn't know about 'make disttest' at the time). Someone asked Barbie that and he confirmed that we couldn't do our own testing, but testers are out there (including him) that would be more than happy to run a preliminary test before your module release. Maybe I didn't understand the question/answer, though, as cog & I talked about how it could have been the other platform testing that they were talking about.

After that, David Cantrell gave a talk on API standardization, but it was more like a full-blown rant, as David is tired of running into modules that have different API's to do the same thing, such as getting a string format out of a Class. In his research, he said he's seen string, to_string, tostring, toString, ToString and I think he even said 2string. I feel his pain, as I run into this myself, but it's hard to enforce that kind of thing and David didn't really offer any suggestions, but at least he brought it up and hopefully with that awareness, authors will pay more attention to that.

I bailed on the next talk, because I don't want to learn Python, so I went upstairs to listen to the advanced talk on “Dark Perl” by Simon Wistow, which was kind of disappointing, but I doubt I could actually understand it anyway, even if he had covered the subject matter (it was supposed to cover a lot of stuff like AUTOLOAD, XS, Perl guts, tie-ing and reversible computing) and been able to wrestle an old PowerBook (it was so old, it was black!) into working. Once everything was smoothed out, he talked about the 'whatif' module, which seems really cool and yet Evil at the same time. Basically, it's a module that you can use and then write a block like:

whatif { try_some_dicey_stuff(); # We Succeeded! }

Actually, I'm not sure if that's right or not, it's so beyond me. As it was explained, you set a point somewhere in your code and then later, if something fails, it will return back to your marker as if nothing happened in the first place. Scary, huh? Brilliant work, though.

So that wrapped up the conference and everyone dispersed to the bar downstairs. I was running short on currency, so I left to go find a cashpoints. Little did I know that it would be so far away, near the South Kensington tube stop! So I went back and then cog and his friend, Peter and I trapsed off to go find an Italian restaurant I heard about, La Famiglia. It took us about an hour to get there, with a bad tube run to start with and then the distance it was from the tube destination. By the time we got there, we found out they were booked and we didn't have a reservation, so it was all for naught. We ended up eating at a Thai restaurant next door, which wasn't all that good, but it was neat to introduce people to Thai food (and a good drink, Thai Iced Tea). After that, we caught a cab back to our hotel and talked Perl for a while longer.

The great thing about this conference, as well as attending any conference in general is that they help guide your next steps in evolution. There's a lot to be said for reading documentation, newsgroups, mailing lists, Perlmonks, etc, but it's a completely different thing to interface with fellow Perl hackers face-to-face to ask questions and get advice. The organizers promised the slides would be available shortly. I also noticed a video crew recording the talks and the organizers promised video availability sometime early next year.

You know, the one thing I would love to know is how some of those presentations are put together, technically. I mean, skipping over the obvious PowerPoint and Keynote presentations. There were a couple of them that were nice-looking and used within a Web browser (John McNamara's Excel presentation, as an example). I asked cog what he used and it was a PDF that came out of LateX, so there's one datapoint.

Peace,

Jason


Exporting Objects

Dom2 on 2004-12-14T08:04:28

The reason for not discussing that is that generally, you shouldn't mix exported functions and methods. That's because a method really expects to be called with an object as its first argument, which is less likely to happen correctly if you say method($obj) instead of $obj->method(). Also, you don't get inheritance because you're not going through method dispatch.

I'm sure there are a few cases where you might want to export things, but generally, I'd think twice before pulling in Exporter.

-Dom

Re:Exporting Objects

davorg on 2004-12-14T09:24:10

I was just about to say that, but you beat me to it :)

Wha??

Purdy on 2004-12-14T17:27:01

You lost me. I understand the $obj->method thing, but what I didn't understand and had hoped Dave would get into was the whole Exporter thing. What is it, why is it used, etc...

Some objects are written such that when you use them, you have to import the methods you'll be using, like:

use My::Module qw/ method1 method2 /;

And others are written so you can just say:

use My::Module;

And then you automatically have access to the methods.

Jason

Re:Wha??

Dom2 on 2004-12-14T18:03:48

I think you're getting confused between ordinary functions and OO code (methods). If you don't call it with an arrow, it's not a method, it's a function (with the annoying exception of the indirect method call syntax, but don't worry about that yet).

When you use a module, you're actually using OO behind the scenes, even though the results aren't usually OO. What happens is that Perl ends up calling the import() method of the named class and passing it the list that you have supplied.

What makes it a method is that internally it gets called as My::Module->import('method1','method2');. Because of the arrow, the thing to the left (the class name here) gets put in as the first argument to the import() subroutine. Because it's a class name rather than an object, this type of method is usually known as a class method.

Now chances are that you haven't defined an import() method in your module. But if you've followed the docs, you've got something like this:

require Exporter;
@My::Module::ISA = qw( Exporter );
@My::Module::EXPORT_OK = qw( method1 method2 );

So, when you say use My::Module qw/ method1 method2 /;, you end up calling the import method in your module. Except that it's been set up like a class so that it inherits from the Exporter module. And that's where it finds the import() method. And Exporter::import() knows where to find the list of things to export because it's been given the class name as the first argument. And then it goes away and makes aliases for the subroutines requested in the place that originally said use My::Module ... from.

So, Exporter is an OO module. And because of that, it means that yours is too because of the inheritance. But, that's probably where it stops.

If you write your subs in an OO fashion, then they expect to be called as $obj->method(). Because $obj knows what class it's in, you don't need to import those methods into your namespace. This is why I said above that it's generally a bad idea to mix the two.

Finally, the difference between your first and second example is just a different usage of the Exporter module. If you say @EXPORT = qw( foo bar ), then foo() and bar() will be automatically exported from your module. Whereas if you say @EXPORT_OK = qw( foo bar ); then you have to explicitly request that foo() and bar() be imported by naming them on the use line. This is generally considered to be better design since it doesn't fill your namespace with crap, the way that the POSIX module does.

One tip to note: Even if a module exports stuff by default, you can ask it export nothing by saying use My::Module ().

Re:Wha??

Purdy on 2004-12-14T18:22:49

Thanks, Dom2 - this helps! :)

If I could, I would mod this up. :)

Presentations

Dom2 on 2004-12-14T08:08:50

You might want to look at S5. It's all html, css & javascript.

-Dom

eating healthily in the UK

TeeJay on 2004-12-14T09:31:04

Eating healthily in the UK and even london is fairly easy if you stick to a balanced diet rather than american health fads.

Drink fresh fruit juice instead of fizzy drinks, avoid places like macdonalds and instead go to places like Beetroot in soho or any Felafel restaurant. Even the average pub grub in london is fairly well balanced, just so long as you have carbs in the day and protein in the evening. The hotel you stayed in would have provided continental breakfast so thats the day sorted.

Also avoid sweets - buy fruit, there will be fresh fruit for sale anywhere in london if you bother looking.

Next time you visit remember you are in europe and not america and that we have been eating sensibly for hundreds of years and still haven't ballooned into human fois gras like Texan's.

Re:eating healthily in the UK

Dom2 on 2004-12-14T09:53:32

That said, I still find even the snack food far superior in european countries that aren't the UK. Whilst you can eat healthy in the UK, it's still harder than it should be.

-Dom

Re:eating healthily in the UK

lachoy on 2004-12-14T14:45:26

Not excusing my tubby compadres in America, but I wouldn't be too smug:

(Source) The most comprehensive data on the prevalence of obesity worldwide are those of the World Health Organisation MONICA project (MONItoring of trends and determinants in CArdiovascular diseases study) [14]. Together with information from national surveys, the data show that the prevalence of obesity in most European countries has increased by about 10-40% in the past 10 years, ranging from 10-20% in men and 10-25% in women [15]. The most alarming increase has been observed in the Great Britain, where nearly two thirds of adult men and over half of adult women are overweight or obese [16]. Between 1995 and 2002, obesity doubled among boys in England from 2.9% of the population to 5.7%, and amongst girls increased from 4.9% to 7.8%. One in 5 boys and one in 4 girls is overweight or obese. Among young men, aged 16 to 24 years, obesity increased from 5.7% to 9.3% and among young women increased from 7.7% to 11.6% [17]. The International Obesity Task Force monitors prevalence data (www.iotf.org).

Re:eating healthily in the UK

TeeJay on 2004-12-14T16:31:36

Too true.

And in whose footsteps did we follow this trend..? The home of fast food, the United States.

Fortunately the government acknowledges the problem and is doing something (although, as always, just a token effort rather than really making a difference).

It isn't hard to eat healthily though, most of the obesity isn't because there isn't access of healthy food (very very few people, and certainly a tiny minority of the overweight are more than a mile from the nearest affordable source of fresh vegetables and other balanced food).

In Truro we have farmers markets, a Tesco's, Marks and Spencers, Sainsburies, Co-op, and somerfield all within a short walk of both car parks and bus stations. All of those supermarkets sell a wide range of healthy food. Then we have indian, chinese, and even japanese restaurants, deli's etc including vegetarian and organic restuarants.

Wherever I have lived in london has always been a short walk to at least 2 decent supermarkets and a proper market (with stalls and much cheaper better food).

No excuses, only laziness.

Re:eating healthily in the UK

lachoy on 2004-12-14T17:10:51

No excuses, only laziness.

Unhappily so.

Supermarkets aren't quite so prevalent here (at least in Pittsburgh) because they tend to be larger and most people drive instead of walk for their groceries. (Boo!) But it's actually much easier to eat healthier almost everywhere you go now -- even many fast food places have one or two items that, while you might not want it for every meal, will do in a pinch. (Salads and such.) I don't think it's a coincidence that it's also much easier to get at least decent beer almost everywhere you go as well.

Re:eating healthily in the UK

Dom2 on 2004-12-14T18:08:33

Heh. McDonalds "Salads Plus" is what we have over here. I do wonder how many calories are in the dressing though.

It's similiar to being in a restaurent when somebody chooses the "healthier" fish option without realising that the sauce contains more fat content than the rest of the menu combined.

-Dom

Re:eating healthily in the UK

Purdy on 2004-12-14T18:36:28

No excuses, only laziness.
Well, then as lazy programmers, we are all doomed!

Seriously, this is really the bottom line - we have grown too comfortable with ignoring the nutritional value (or lack thereof) of what we eat. We've also "outsourced" our decisions to companies who really don't care about us, but about their profits. Put 'em together and it's a bad situation where we're creating a demand for Bad Food and it will only get worse.

The South Beach Diet may be a fad, but at least it's creating awareness on what we consume and that awareness has translated into demand, which has translated into companies offering low-carb and healthier options. My point was simply that this concept hasn't hit the UK yet (at least in my limited exposure).

Peace,

Jason

Re:eating healthily in the UK

TeeJay on 2004-12-15T09:16:32

Yes, it is getting worse, for some, but the availability of healthy food for most. Even mcdonalds is starting to get its house in order and provide relatively healthy meals.

You can get low-carb food in any health food shop or pharmacy along with the usual snake oil and trendy gimmicks.

The brits are on the whole aware of what we consume, its just that many of us consume too much and have a drinking culture that adds even more weight.

oh and laziness, the information and the decent food (even organic, lo-carb, lo-sugar, blessed-by-fairies) but are too lazy to exersize.

btw - really, carbs don't make you fat, laziness does - unbalanced diets are no substitute for exersize and eating the right meals at the right time of day.

my wife and sister-in-law are both trained ballet dancers and my sister-in-law is a gym manager with training in nutrition as well as fitness. So I know about the latest fads and why to avoid them.

Anyway, each to his own.