I'm leaving my current $work, and changing to another one. Being the first one I'm starting not as an university student but a 'professional' one feels strange, and I'm somewhat thrilled. Will I be good enough for the job? I hope so :)
These last days I'm reviewing some of my old code with the guy who will inherit my codes. A cool programmer, with lots of knowledge I wouldn't expect from an average young programmer (it's actually a bit older than me but, you know... not everyone reads 'refactoring', code complete, and GoF just for fun :) ). We've had good times. Transfering info would be quite more difficult without such a good learner. In little less than a week, he also explained me some ins and outs about some agile methodologies, or good programming practices (some cool refactorings, Log4X modules, etc...). We both learned quite a lot from each other.
Some of the neat advices that I liked.
- use Logging modules. They pay off. And they are quite easy to set up (opposed to what I thought)
- refactor any piece of code that is repeated more than 1 time (if it's easy to do). calling a simple join(',' , @array) three times in the same function can be refactored into a meaningful name sub. You get the name explaining what your code does, and if you want to change ',' to ':', only one change does it.
- Codes that you write separated by 2 newlines, like paragraphs, and start with a comment that explains what that snippet does, are screaming for a new function. You can use the first words of the comment as a hint for the function name.
- Take a look at AOP, it's cool. a really cool thing.
lunes, 15 de noviembre de 2010
jueves, 4 de noviembre de 2010
I'm in ur shell, watching your repos
I'm using more and more a little script that Cornelius called cpans.sh (for cpan search)
It's dead simple, but great anyway, and, it lets me use ratfinder to browse cpan modules. And to give credit where the credit is due, I'll just embed his gist.
Simple idea, neatly used. curl, file tests, zgrep and some bash bits.
It's dead simple, but great anyway, and, it lets me use ratfinder to browse cpan modules. And to give credit where the credit is due, I'll just embed his gist.
Simple idea, neatly used. curl, file tests, zgrep and some bash bits.
lunes, 18 de octubre de 2010
Courier new WTF (or, monospaced is not enough)
Via reddit , I found this pearl:

From wikipedia:
Courier New is used extensively in programming. For example, online forums, such as phpBB, SMF, and vBulletin, will use Courier New for <code> blocks; on Microsoft Windows it is a default monospaced font for a variety of applications, such as Notepad, Visual Studio (although the Consolas font family is provided as an alternative
Seriously, if you have to write code, go and get a font that doesn't suck. Monospaced is not enough.

From wikipedia:
Courier New is used extensively in programming. For example, online forums, such as phpBB, SMF, and vBulletin, will use Courier New for <code> blocks; on Microsoft Windows it is a default monospaced font for a variety of applications, such as Notepad, Visual Studio (although the Consolas font family is provided as an alternative
Seriously, if you have to write code, go and get a font that doesn't suck. Monospaced is not enough.
viernes, 15 de octubre de 2010
ubigraph: an interactive 3D graph creator
A few days ago I read a funny post on HN. A guy was presenting some clojure code that used ubigraphto produce 3d navigable graphs.
To make ubigraph portable and interoperable with many languages, they present the app as an independent window (embedable, I hope) with its own process that acts as a XML-RPC server, so if you don't have an specific API for your language, you can use plain XML-RPC calls.
I've written a simple fibonacci function with a callback that draws the flow of the calculations.
Here's the code, and a (static) image of the graph.

To See how memoizing works, I've modified the code a bit using Memoize and a normalizer function and now we see how the number of steps is O(n).
To make ubigraph portable and interoperable with many languages, they present the app as an independent window (embedable, I hope) with its own process that acts as a XML-RPC server, so if you don't have an specific API for your language, you can use plain XML-RPC calls.
I've written a simple fibonacci function with a callback that draws the flow of the calculations.
Here's the code, and a (static) image of the graph.

To See how memoizing works, I've modified the code a bit using Memoize and a normalizer function and now we see how the number of steps is O(n).
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.
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.
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 :)
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 :)
Suscribirse a:
Entradas (Atom)