sábado, 20 de noviembre de 2010

I'm a LOL programmer (wannabie)



In my new job, it seems I'll be writing ruby (on rails).

I've been trying the language in my spare time, and it seems a fairly good compromise between Perl and Smalltalk.

Except a couple of features or idioms I saw, everything else was quite intuitive or easy to understand (at least coming from Perl/Smalltalk).

+ Sigils do exist, but denote scope oposed to type.
+ __DATA__
+ '=' can be part of a method name. And there's some magic involved there. def method=(attr) can be used as an assignment (sintactically) as parens are optional.
+ Integer class can be expanded or subclassed.

Here are the codes I wrote to grasp the language. These are the usual examples I write in every language I try to learn:

- a program to center paragraphs.
- guessing number
- Network with hosts that pass messages one to the other.



Here is a link that I found useful about ruby patterns and idioms.
http://scriptlandia.blogspot.com/2009/02/design-patterns-in-ruby.html

lunes, 15 de noviembre de 2010

Last but not least

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.

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.

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.

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).


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.