About time

I have been working with a 64 bit machine running OpenSuse for a while. And I have been surfing the net using a x86 browser to be able to visit all those lame pages that use flash. But finally after reading this post I found out that the there is a 64 bit flash player for Linux, hurray!!!!!!!

You can find it here.

Maths joke

An infinite number of mathematicians walks into a bar. The first one orders a beer. The second one orders half a beer. The third one orders quarter of a beer. It continues that way until the bartender interrupts and says: “You guys are all a bunch of idiots” and pours two beers.

Amsterdam

Two weeks ago a good friend of Bea and I was coming to Amsterdam so we decided to go and visit her. We though that Amsterdam was closer that it really is, around 250 km, took the car and went. It was a really nice day, we visited the city center, the red district and Heineken brewery which was aw… wait for it some (yes, I love How I met your mother).


View Larger Map

Amsterdam overall is quite a good city, but I would not live in it. Don’t get me wrong, the sight seeings are great, people are nice and you have Marijuana and beer, but is not the kind of place where I would like to settle down. The city gave me a feeling of party non-stop which I don’t really understand or like anymore. Maybe a couple of years ago I did not mind to go to work early in the morning and see a man on the floor cover by his own pee and vomit, but know, I really do not want to see that early in the morning when I go to work. I am sure I will be going back and will change my mind about it… anyway as usual you can find the picts at flickr.

Amterdam 009

Faking named parameters in PHP

marco:

Here’s a short technique for faking Ruby’s cool named-parameter ability. It’s useful when you have a function that takes a lot of optional arguments, and you occasionally want to specify a few of the middle values without specifying all of the preceding values (or knowing how many there are). It also helps code readability if you’re willing to make the slight performance sacrifice — and since you’re writing in a dynamic language, that’s probably true.

The function (note the use of extract):

<?php
function my_function(
    $id,
    $start = 0,
    $limit = 10,
    $filter = false,
    $include_duplicates => false,
    $optimize_fetch => false,
    $cache = false
) {
    if (is_array($id)) extract($id, EXTR_IF_EXISTS);

    /* ... */
}

Calling it the old way still works perfectly fine as long as the first parameter isn’t normally supposed to be an array:

<?php
my_function(1, 0, 10, false, false, false, true);

But imagine how helpful that is when browsing this code 6 months later. Now, compare that with calling it the new way:

<?php
my_function(array('id' => 1, 'cache' => true));

Obviously, the function can have a lot more arguments, and this approach makes a lot more sense when it does.

It’d be great if PHP at least supported a compact or automatic array-literal syntax so we could avoid array(...) everywhere, but the developers really don’t like that idea.

This same hack/trick has been used in perl for ages… but thank fully we may get named parameters in perl 6, personally I prefer to use this technique in larger projects which makes the code more self explanatory. I hate reading code like this:

sub my_sub_routine($$$$){
    my first_param = @_[0];
    my second_param = @_[1];
    my third_param = @_[2];
    my fourth_param = @_[3];
}

I fill bad every time I have to write things like this...

« Previous   
Next »