domingo, 19 de septiembre de 2010

ESUG 2010: It's awesomeness all way down





ESUG 2010 was held at Barcelona (well, technically, Cornellà). For people that don't know what's ESUG, it's one of the most important smalltalk events worldwide.

A week full of talks, great fun, hours of hacking and chatting with other smalltalkers.

The weekend before the conference, citilab was open to all smalltalkers who wanted to participate in the SmalltalkCamp. Two days of coding and meeting with other smalltalkers. I started rereading the seaside book and got some help from Bernat. It was fun to see the creators of what I was trying to understand (seaside) walking and coding around. Another nice curiosity was when someone entered the SmalltalkCamp with an OOPSLA t-shirt. It was like: "wow, important people around!" :)

Monday, at 9:00 the conference started officially, but by then, I had already met some great smalltalkers. Here is the schedule of the whole esug.

90% of the talks where amazing, I mean, good contents, with an accurate dose of humour, and talks given by people with nice speech skills.

Xtreams (Martin Kobetic), Design decisions behing Patagonia(Hernán Wilkinson), All Esteban Lorenzano's talks (mars and reef), Helvetia (Lukas Renggli), Stephane Ducasse's talks, Richie and ..... too many good ones to remember the name of all.

Citilab made a great job organizing it all, and we, the local group had very little to do (thanks to volunteers too). Myself I just had to help some people with maps, subways and take some smalltalkers to 'visit' Barcelona. :)

I bought a special edition of the seaside book and got it signed by Ducasse and Renggli. WOW!

Well, it's been a short and late post, but I can't write a post with all cool things I learned there, so it's more a "I've survived" post than a "hey, look what they showed us".

Soon, citilab will make the recordings of ALL the talks available on the web. I think they'll be hosted in cincom's servers. I'll post about that when it effectively happens.

I met many people and had lots of fun talking not only about smalltak but technology in general, and life, universe and everything. Mostly argentinians but not only them. Gabriel, Gabriela, Hernán Wilkinson, Leandro, Richie, Javi, Nico, Ricardo, Esteban Lorenzano,... Great people.


martes, 7 de septiembre de 2010

Capture the flag with Moose

In today's post, I'll show some ways to get program options via flags (--flags) I discovered recently.

CPAN is crowded with Getopt::* modules, but I'm going to explore the Moose universe.

Moose

At $work, we often have write commandline apps that end with lots of parameters and flags, and 'shift @ARGV' is not an elegant nor flexible solution. I've been using GetOpt::Long for years, but now, using Moose, I discovered an extension Called MooseX::Getopt.


MooseX::Getopt

This Moose eXtension allows you to fill attributes of an object directly from commandline.


We just have to use MooseX::Getopt in our Class, and change the creation of the object from Foo->new to Foo->new_with_options.

Tada!



Now, our program can get all Foo's attributes through the commandline. Note that if you try an invalid flag, it will output the accepted ones.

- But wait, I do not want to allow users initialize all attrs.

Ok, then we should hide the attr under a name beginning with underscore, and set the accessor to our desired name. MooseX::Getopt will understand you don't want it to be accessible through command line options.



MooseX::SimpleConfig

The summum of DWIM is you can also exploit the same introspection capabilities to enable configuration files to setup the execution of the files. And it costs you just one line.
with 'MooseX::SimpleConfig';




The code above will activate an extra flag (--configfile) where you can indicate where to reach the configuration file.

There are more goodies you can add on top of these modules, but for now, I think it's enough for me. :)

From these findings, you can see, Moose is not only a great OOP platform for perl but a higher level base for perl hackers to put stuff on.

Thanks Perl community.

viernes, 3 de septiembre de 2010

Parallel::Iterator. Independent tasks are independent

OH HAI!

Today's module is Andy Armstrong Parallel::Iterator. I discovered it through Dagolden's blog, and tried it by myself that same day.

The idea is simple. You may have many slow tasks to do that don't have dependencies between each other. A typical example is fetching for webs using lwp, but I can think of lots of processes doing similar things, for exmple, ssh-ing some command to many different servers.

So it's like an autothreading map. Well sort of.

As tasks are not guaranteed to end in order, and you probably want to know which source procuded each result, the function you'll apply to each element will have to take not one but two parameters, the first being just an index that you can throw away. At least it seems so. I'm not sure I understand it fully, but for the moment that's what I gathered.

The module provides two sets of functions, iterate, and iterate_as_(array|hash), iterate returning tuples ($index, $result), and the others returning the wanted structure.

But what puzzles me is that I cannot easily migrate a normal map to this parallel::iterator because functions sent to map have to accept an extra parameter (just to throw it away?). Two days ago I read another post related to it but it didn't comment anything about that 'strange' use of it.

So I hacked a higher order function that mimics map signature but uses parallel::iterator. I'm probably missing something because it's strange the author didn't provide something like that in the module. Anyway, here it is:



I'm using the iterate_as_array because I want to mimic map signature, so the array to iterate can't be lazy built. That's another feature of Parallel-Iterator : not only the evaluation of the method can be lazy but also the generation of the list.

Ideas? Suggestions? Insults? Go on and comment :)

miércoles, 25 de agosto de 2010

Using AUTOLOAD to build html code

Last week I found a new blog about Io. It's been a long time since I used Io, but maybe this blog will make me look at Io Language again.


In his last post, Dennis Ferron comments on _why's web server yown written in Io. One thing he comments is the slot 'forward'.

As he says, forward is a kind of catch that gets called when a message has been sent to an object and that object didn't have a selector with that name. _why exploits this feature to write an html builder based on that.

What he doesn't mention (I think he's leaving this for another post) is about lazyness. The way _why wrote forward method.

If you define a method without arguments but you call it with some, you can still access them, but with the difference that they won't be evaluated by default. That's called lazyness, and allows you to define the evaluation order of things.

So in the code

html(
title("O HAI")
strong("KTHXBYE")
)


forward will trap html message before title or strong.

In Perl, there's a 'lightning rod' function too, called AUTOLOAD. You can do pretty much the same, but the difference is that perl will ALWAYS evaluate parameters sent to a function before calling it, so the same code would trigger AUTOLOAD on the 'title' call, then 'strong', and last, 'html' and you have to fill the string from the inner tag to the most generic one.

Here's a gist code that emulates Yown Builder.io in Perl 5.




Good luck Dennis with your new blog!

--
raig

lunes, 16 de agosto de 2010

Memoizer in common lisp

Last weekend I finished a fast-read of Ansi Common Lisp. I didn't do the exercices but I did pay attention to code examples (those are what make me really understand things).

Overall I find it pretty good, but a bit simple provided you already know something related to the lisp world.

After finishing it, I tried a couple of tricks in lisp, and was surprised how easy it was to come with working codes of a memoized function. Once you have a memoized function, why not convert it to a memoizer function?

Here it is. (If you're reading it on google reader you won't be able to see it, better read blogposts from the original site)




(setf memofib (memoizer #'fib))
(funcall memofib 10)

And you have now a faster fib than before.

Question: how should I change it to make a generic memoizer that memoizes not only unary functions.
In perl I'd have to just pass @_, I suppose changing arg to '&rest arg' and change funcall to apply would do the trick... I have to try it. Later.

More readings: Scheme R5RS.
I read the part I hadn't read before. I have to say even the scheme spec is minimalist, well written, and didactic. Following the language philosophy even at docs level. :)

And a bit more: A paper on Scheme macros. I think I get them, but I don't see much use for them. I suppose I'm still an average blub programmer.

jueves, 12 de agosto de 2010

Sharing interests with others

Here's another of those shitty trackback posts that add nothing to the original post:

I've read a blog entry that explains what I think about sharing interests with others better than I could ever have written.

I found it in HN, so it talks about sharing prorgamming interests with your partner.

Another funny post of the same kind, in a Bug report format. Hilarious too.

martes, 27 de julio de 2010

Rakudo * is next door



Yes.
Rakudo *, the first official distribution of stable (yet incomplete) perl6 interpreter rakudo. Devs haven't focused on optimizations but features, and it's quite useful as it is IMHO. It brings lots of the crazy Perl 6 features announced in the synopsis like hyperoperators, metaoperators, lazyness, junctions, introspectable OOP, and regex and grammars as first class citizens in the language. That last thing means you can plug a new parser for your program in lexical scope. Welcome DSL world. Early adopters, language geeks, perl hackers, you have no excuse now not to try rakudo :) .

Myself I haven't toyed enough with Perl 6 to do anything useful, but I have done quite a few conceptual tests, and, although I'm still baby-talking Perl 6, it's quite nice to hang around at #perl6 and see perl6 heroes stressing rakudo's features till the unthought limits.

More good news: Audrey Tang appeared a few days ago on #perl6 (I think thanks to masak's post), and started hacking on niecza (sorear's perl6 implementation focused on compiler and interpreter optimization techniques).

I tried to solve one of moritz's perl6 Challenge, implementing Str.trans (á la p5 tr// ) in perl6. Mine, is the (really incomplete babyperly) submitted on a gist pastie. I didn't win the rakudo T-shirt.

More on Perl6. A couple of perl6 related posts reached HN and reddit top page and stayed more than 1 day there. buzz buzz buzz buzz :)

And last but not least, Barcelona Perl Mongers are living a celebration, on July 29th of July, the R* Day (and being the last thursday of the month, which is the usual meeting day) will join at UPC Campus Nord, and Alex Muntada will give a Perl6 introductory talk. Of course, you're all invited. Unfortunately, I won't be able to be there as I'll be in Malta. O HAI Holidays!