Fosdem 2011 Report – Day 2

Second day at Fosdem. This year, I decided to go and visit the perl community, as I’m more and more coding in perl, and would like to learn more about news, additional modules, and meet more perl hackers !

Gabor SzaboUsing Perl6 today
No real 6.0 announce. Already published and improving. Gabir gave lots of info on perl5/perl6 differences:

  • hash element prepended with % (including pointers)
  • array element prepended with @ (including pointers)
  • Expressions in {} are interpreted and executed
  • Variable may be typed
  • Chaining conditions 23 <= $age <= 42 (avoids and)
  • Junction if $age == 2|3|4 (avoids or)
  • Easier access to array elements (including in pairs, …) with missing parts managed – matrix type of computation
  • New ‘Z’ operator which allows array combination
  • lazyness allow infinity to exist: doesn’t generate the full list anymore from scratch. my @x = 1..Inf exists !
  • functions parameters number are checked, type as well. So we can now pass multiple arrays in functions without attribution issue. It also manages optional params.
  • Types can be defined by the user. Constraints can be put on params.
  • Operators can also be combined (Z and ~ – concat) on arrays e.g. (Notion of meta operator, hyper operator, user created operator)
  • Perl 6 manages classes methods (public, private)
  • Regex also have evolved a lot – Grammars can also be defined (based on regex) and inherited as well.

One quote I really liked: “Perl6 is fully buzzword compatible”.
A very intresting presentation on perl’s future, well present in fact, even if I’ve not tested it up to now. Looks promising but a huge change.

Damien Krotkine (Curses::Toolkit)

Damien advertized the French perl event (French Perl Worskhop 2011) in Paris, Perl Dancer community, his book, Perl Moderne. As it was also warmly recommended by Dominique Dumont (author of Config::Model), I bought it, and even had the author’s signature on it !! I started it in the train back from Brussels, and indeed it’s a good one, focussing on specific topics, (so not a bible), but very nice to read, and informative. Of course, as you guessed with the name, it’s in french ;-)

Damien then talked briefly about Curses::Toolkit, as all these advertizing took a bit too much time IMO. He covered:

  • Curses::Toolkit curses binding for perl inspired by GTK
  • Why Curses::Toolki ? Existing Curses is too low level, Curses:UI buggy and inflexible; Curses::Widget
  • Curses::Toolkit real toolkit with widgets and events, OO, kbd, mouse, timer events driven, using POE.
  • Curses::Toolkit uses themes and is very easy to customize

Damien then concluded by making an impressive demo of modern caracter based interface

Mark Overmeer (Perl Data Structures)

Excellent talk by Marc who covered in 1 hour as many topics as he had on his list, without exhausting it !

He underlined:

  • the importance of scalars in perl. Used for everything. Consumes 28 bytes each (because they can store multiple values (dual var/$!)
  • False values in perl: undef, 0, 0.0, “”, “0″ (the most dangerous). die "no fn" unless $fn is a mistake as filename “0″ is false even if it exists. Recommends using length instead. $x = $temperature || 20 is also a mistake if temperature is 0. Recent perl provides operator // for that for undefined
  • An array is a copy of a list of params (he insisted on difference between list and array)
  • Context is the specificity of perl. An expression can not be understood without its context in perl. There is a void context. An array in scalar context provides its length. There is list context (@a = 3; works). Good way to loop on arrays foreach my $x (@a) { print $x; }. $x[3] is a promise of a scalar.
  • Array affectatation: @x[1, 3, -1] = 6..8. Also valid is (getpwnal $x)[3,-1] (gives uid/shell). getpwnam in list context gives the 10 elements. In scalar gives the uid (you only know by reading the man page).
  • In hashes, you can delete elements with delete $a{b} . $a{b} = undef is different. if exists $a{b} gives true with undef. if defined $a{b} gives false.
  • Array knows the order, hash doesn’t and is 20 times less performant. $h{time} is a hash but $h{(time)} calls the time function and get result as a key. @h{'x','y','z'} = 1..3 works (again promise of an array) and creates a hash initialized.
  • Tip my %str2errno = reverse %errno2str (list context). Another tip: @h{keys %y} = values %y;

Dense and useful session.

I took a pause and came back half an hour later, time to say helllo to Bdale, and some Mageia friends.

Stefan Hornburg (Template::Zoom)

I had more problems finding that talk interesting. I may not be the right audience, but also the monocord sound of the voice wasn’t helping. Stefan explained that:

  • Base is separation of Web design and programming
  • Some templates do not respect this (Template::Toolkit, HTML::Zoom)
  • T::Z provides static HTML file and spec file
  • Use Interchange (FLOSS e-commerce server) and ITL language
  • Config can be done with XML or Config::Scoped

Examples were given.

SawyerX (Moose: Postmodern metaclass-based object system for perl5)

After the previous talk, it was refreshing to see the enthusiasm that SawyerX deployed to convince us how Moose was wonderful. And I must confess that even if I’m not a big fan of Object Oriented approach (showing my age here !), I was ready to try after that talk. Exceelent one IMO.

First he advocated metacpan.org. Then he went on explaining that objects in perl 5 is a blessed hashref (bless {}, __PACKAGE__; (name space of the package), that the new method is manual, self is the invocant and he underlined problems with std Object in perl. And hows that half code is really needed.

He went on with Moose.
define an object in Moose is as simple as:

package ...
use Moose
1;

has name => (
is => 'rw', # or ro
isa => 'Str', # Attributes have type constraints Str, Int, ArrayRef, Regexp, HashRef[Str] + inheritance + own types
);
# there are setter/getter methods

inheritance is as simple as:
extends 'ParentClass'; (may have multiples)

Roles are behaviours (not a class of its own) is as simple as:
with 'a_role'; (may have multiples)

Hooks are ways to change the behaviour from inside Moose:

before leaving => sub {
my $self = shift;
$self->action;
};
after leaving => sub {
my $self = shift;
$self->action;
};
around login => sub {
my $orig = shift;
my $self = shift;
$self->ecurity_check and $self->$orig(@_); # runs the login method only when security check is ok

Some attributes:

default => 3,
default => sub { {} }, # but rather use builder
required => 1, # it's required
lazy => 1, # Only do the action as late as possible, especially for infinite loops
builder => 'build_it' # Moose doesn't know it so you have to code
sub build_it {
my $self = shift;
...
};
clearer => 'clear_it', # Moose knows it so you have to code, it clears the value as it never existed,
# but do not go back to default
predicate => 'has_it' # it checks that an attribute value exists (including undef) - doesn't create anything
lazy_build => 1 # same as lazy =>1 + lots

The final quote said: “Moose produces beautiful, clean and stable code and is here to stay“.

Additional modules:
MooseX:: SimpleConfig automatic creation of structure from config file
MosseX::Getopt
Catalyst is now based on Moose. Perf penalty is minimal especially for long running apps.

Incredible talk. Worth having no lunch for hearing it.

Then I attended an unplanned session, not on the paper program:

Alex BalhatchetWriting readable and maintainable perl

That talk covered some good tips and tricks on how to write perl code that is just here to stay as well !
Generic advises:

  • use strict is mandatory (avoids typos)
  • use warnings
  • use autodie # make open() and others die on error
  • use feature ‘say’;
  • Advertise CPAN (90000 – mostly well documented) makes code more readable/maintainable. Problem of choice (use testers report, rating date). Task::Kensho gives good recommendations.

Best practices:

  • code in paragraphs
  • throw exceptions (rather than error codes) with die (catch them with eval, or now try/catch
  • use builtins (use readline($fh), warn instead of print STDERR, glob instead of
  • use Scalar::Util List::Util LIst::MoreUtils (comes with most perl) brings min, max, last, first, …
  • Be consistent with existing code base (inconsistent is worse than unreadable)
  • Make sure there are tests, and good tests.
  • Perl::Critic (and perlcritic) does static analysis (referes the whole Perl Best Practices book !!)
  • Perl::Tidy (and perltidy) makes code more readable.

The presentation is available at http://www.sledeshare.net/kaokun

Gabor SzaboPadre
Gabor came back on scene to present Padre, IDE in perl5 for perl. Focus on beginers or occasional users.
I was interested for my son to whom I teach some perl now, and who would be a perfect candidate to use that tool (/me being a vi/vim/gvim user since 24 years, and not ready to change ;-))
He underlined that use diagnostics improves error msgs. He mde a demo of multiple Padre features. ALt-/ shows the contextual menu (for keyboard people !). Variable replacement based on content (differentiate $x from $x[0] and $x{“foo’} and replaces the right one.

Paulo CastroPackaging Perl and it’s deps

Paulo explained his problem: delivering a version of perl with all its modules (400+) for its applications.
He showed multiple possibilities and the one finaly retained, which consists of having a single package including perl and all the CPAN modules built for that version, using a local mirror to build it.
He also mentioned pmtool for inventory, CPAN::Site module and the CPAN Distroprefs features orientation.

Even if interesting, as a packager myself, I still find odd to use that approach, instead of using the packaging format of the underlying Linux distribution to perform this. Even for 400+ packages. In fact for that type of work, I’d myself pick and chose the Linux distribution having the most perl packages already done, and provide the rest myself. Debian or Mandriva/Mageia could be a good start in that perspective.

It was then time to pack everything and go to the train station and back to Grenoble. The 4 and half hours in the train were used to clean up my perl code in project-builder.org, as that series of presentations gave me lots of ideas and energy to do it !!

i look forward participating next year, and hopefully, doing submissions earlier as a speaker again.

About these ads

Tags: , , , ,

One Response to “Fosdem 2011 Report – Day 2”

  1. Let’s meet at Fosdem 2012 in Brussels « Bruno Cornec’s Blog Says:

    [...] attend Fosdem again this year next week-end in Brussels. I’ll deliver a talk on Project-Builder.org as a support [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 99 other followers

%d bloggers like this: