27 agosto 2008

Google 404

@ 27 agosto 2008 a las 11:44 :: Archivado en: Internet, Computers

I gotta say, I had thought this before. Google provides a new way to enhance 404 pages. If our visitors get a not found error, we can give them some alternatives using a simple Google snippet. This code provides the closest match (for the URL) and other things to try such as search into the site. This is useful information designed to help them find the information the users need.

You can read more about it on the Official Google Webmaster Blog.


30 julio 2008

Closed for holidays

@ 30 julio 2008 a las 17:14 :: Archivado en: Personal

Closed for holidays. I’ll be in Japan until 15th August. I think I deserve a rest. Up until then, have a lovely summer.


29 julio 2008

Multiple Constructors in PHP

@ 29 julio 2008 a las 21:02 :: Archivado en: Computers

As you probably know, it’s possible to have multiple constructors in Java. They need to have the same name as the class, and they can only be distinguished by the number and type of arguments. In PHP5, you can only have one constructor. You can define it using the reserved word __construct. If the __construct function doesn’t exist, PHP5 will search for the old-style constructor function (by the name of the class). So if we cannot have multiple constructors, how could we create objects with different initial conditions? It’s not a big deal. There’s a pattern called Factory Method, which defines virtual constructors using static methods. Let’s see an example:

class Person { private $name; private $email; public static function withName($name) { $person = new Person(); $person->name = $name; return $person; } public static function withEmail($email) { $person = new Person(); $person->email = $email; return $person; } public static function fullPerson($name, $email) { $person = new Person(); $person->name = $name; $person->email = $email; return $person; } }

We have a class called Person which contains 2 private attributes: name and email. It also has 3 static methods: withName, withEmail and fullPerson. These methods will behave like constructors.

So if we want to create a Person object just with the name value, we can do it using the following statement:

$person = Person::withName('Example');
27 julio 2008

7 tips to write intelligible code

@ 27 julio 2008 a las 12:52 :: Archivado en: Computers

Writing intelligible code helps to increase the productivity of a developing team, even if you are an independent worker. Why is it so important to write intelligible code? How can it improve the productivity of my team? A messed up code could delay your partners understanding, or it could create a barrier for new developers. Even trying to understand your own code could be a real challenge as well. Here are 7 tips of how to make more intelligible PHP code (coding style tips):

75-85 characters per line: Each line must contains approximately 75-85 characters. If a line exceeds more than 85 characters, consider splitting the line into multiple lines. It will be helpful for code readability. You can see a great post on this topic in Paul Jones’ blog. He talks about why this limitation is not really arbitrary, and he puts some brilliant examples such as this one:

Bad

list($foo, $bar, $baz) = array(Zim::getVal('foo'), Dib::getVal('bar'), Gir::getVal('baz', Gir::DOOM));

Good

$foo = Zim::getVal('foo'); $bar = Dib::getVal('bar'); $baz = Gir::getVal('baz', Gir::DOOM); Assignment statements: Assignment statements ought be aligned for better readability. Let’s see an example:

Bad

$example = 'string_value'; $anotherExample = 42; $exampleInst = new ExampleClass();

Good

$example = 'string_value'; $anotherExample = 42; $exampleInst = new ExampleClass(); 4-spaces block indentation: Use an indent of 4 spaces with no tabs. It helps to avoid problems with diffs, patches and SVN history. It helps the readability as well. Usually tabs are 8 spaces length, which means a 5th-block indent starts 40 spaces from the left border (nearly to 50% of a code line).
{block1} {block2} {block3} ... Control & conditional structures: These statements must have one space between the control keyword (if, else, for, while, …) and the opening parenthesis, to distinguish them from function calls (which obviously don’t have a space). It’s nice to always use curly braces because they help to decreases the likelihood of logic errors.

if ($display === 1) { while ($obj->next()) { echo $obj->toString(); } } Class and function/methods declarations: Class and function/methods declarations have their opening brace on a new line.

class Foo { private $_obj; public function __construct($obj) { $this->_obj = $obj; } } Comma-space between items of a list: When we list some items, it’s nice to separate them clearly with a comma followed by a space.

BAD

$example = array(Foo::get('key',2),$value,true);

GOOD

$example = array(Foo::get('key', 2), $value, true); Use constants properly: If we have a method which returns some status codes, it’s nice to use literal constants. Having descriptive constants helps to make better intelligible code. For example:

BAD

class Foo { public static function getStatus() { $res = 0; if (!self::isValid()) { $res = 1; } ... if ($res === 0 && self::isRepeated()) { $res = 2; } return $res; } }

GOOD

class Foo { const STATUS_SUCCESS = 0; const STATUS_FAILURE = 1; const STATUS_REPEATED = 2; public static function getStatus() { $res = self::STATUS_SUCCESS; if (!self::isValid()) { $res = self::STATUS_FAILURE; } ... if ($res === self::STATUS_SUCCESS && self::isRepeated()) { $res = self::STATUS_REPEATED; } return $res; } }

These tips are just some coding style tips. If we really want to write intelligible code, we would keep in mind many more things like to use software patterns, to make use of well established software practises, …


23 julio 2008

Has Google acquired Digg?

@ 23 julio 2008 a las 10:58 :: Archivado en: Internet, Bussiness 2.0

Has Google acquired Digg for 200 millions dollars? Michael Arrington has written a post on TechCrunch saying that both companies have reached an agreement for around 200 millions dollars. The popular social bookmarking site would become part of Google News property.


19 junio 2008

HDR time-lapse

@ 19 junio 2008 a las 18:22 :: Archivado en: Video, Photography

This is a High Dynamic Range time-lapse from Goblins State Park in Utah (USA). It is very nice



19 junio 2008

Simplemente tú

@ 19 junio 2008 a las 08:38 :: Archivado en: Personal

Te voy a escribir lo más bonito que he escrito en mi vida, porque simplemente eres lo más bonito que me ha pasado. Desde aquella noche en que me besaste, no ha habido ningún día en el que no haya pensado en ti. Eres mi pasado, mi presente y mi futuro, te llevo en mi mente y corazón a todas partes.

Pienso en ti cuando estoy triste y cuando estoy feliz, cuando me siento arropado y cuando me siento solo, cuando río y cuando lloro, cuando gano y cuando pierdo, tú siempre estás ahí. Eres la estrella que me guía, mi razón de ser, el motivo por el cual merece la pena vivir.

Cuando no estoy contigo me siento perdido, necesito tu presencia. Echo de menos los pequeños detalles que me das cada día; el latido de tu corazón, los abrazos de media noche, el aliento de tu boca cuando me besas cada mañana, el brillo de tus ojos verdes, cuando me dices I love you baby, tu dorada melena al caer el sol, tu bella sonrisa, y es que echo de menos hasta el aire que respiras. Aunque tal vez no puedas enteder todas estas palabras, no te preocupes cariño, que yo te las explico con el lenguaje de mis besos.


06 junio 2008

PHE08 y Cámara Abierta 2.0: El lugar del Internauta

@ 06 junio 2008 a las 09:25 :: Archivado en: Photography


05 junio 2008

Plurk, your life on the line

@ 05 junio 2008 a las 13:37 :: Archivado en: Internet

Plurk is a new microblogging based application. It lets to publish from texts (140 characters) to multimedia files such as pictures and videos. The most revolutionary feature that Plurk brings to us is the original timeline. When you take up using it, it can be a bit confusing, but you can get used quickly. I like how the system let the user knows new updates as well. I think Plurk could be a nice alternative to Twitter, but I have some questions:

Why don’t they make a search engine for users? When you start using Plurk, it’s complicated to find friends Why don’t they let upload ours own files directly onto the system?

You can follow me on http://plurk.com/user/alfonsojimenez


06 mayo 2008

Amarok: Project Neon

@ 06 mayo 2008 a las 20:27 :: Archivado en: Computers

Ladies and gentlemen, the doors are opened on the Neon project. Neon is no more than a new service by Amarok, which offers nightly builds to the users who want to try the lastest available version. It should be noted that is not a stable version, but it’s intended to be used by everyone who wants to help find bugs or to join development for Amarok.

If you are using Kubuntu Hardy Heron and you are interested on installing it, just add this line to /etc/apt/source.list and install the amarok-nightly package:

deb http://ppa.launchpad.net/project-neon/ubuntu hardy main

More information | Official Amarok site