Development

How do you know good code?

One of the great challenges of PHP is that it’s so easy to learn, that just about anyone can learn it with not too much of an effort. While this is great for the number of PHP developers, it also seems to have the effect, that there is a huge number of bad examples of code out there. How do you then know good code? In my book there are a few signs, which you could judge from – and they may even apply broader than just php-code.

Caching & WebApplications

One of the funny observations as a web developer: It’s amazing how many people consider caching bad by definition. If you know what you’re doing, caching is an amazingly powerful tool, which can provide cheap and efficient scaling to those who know how to use it.

Know when it’s okay to cache

If thousands of people see the same non-personal frontpage of your website - do you then do the 20+ database queries to build a fresh one for each visitor or do you just refresh a cacheable version from time to time?

Tip a friend - not so simple

Many online sites such as news-sites and other content providers often have a “tip a friend” option. With this you can mail a friend and tell them about an interesting piece of content you’ve found. The Idea seems quite simple, and everyone should have the tip-option, wright? - no, wrong. While it may offer a convenience for some, it has several backsides.

First if you - or your email provider - has implemented anti-spam techniques such as SPF-records, the “tipping mail” will not be sent through the authorized list of mail-servers and thus have a larger likelihood of being labeled as spam. Your mail be sent, but you don’t know if it will arrive in your friends mailbox.

Mysql metadata

If you’re a developer and use mysql, I’m sure you’re aware that it’s a database and it quite good at storing data, but one of the neat things about Mysql (and most other databases) is also their ability to provide meta-data on the contents of the database.

Most people know how to use the meta-data queries in the commandline, but if you want you can also use them in your (php/perl/some-other- ) language. Here is a quick guide to some of them.

Backups, Wordpress & GMail

Backups seem to be a constant pain for just about everyone. It’s something we know we should do, but somehow never get around to actually doing. Since switching to Wordpress on this site, things have been different though.

One of my many installed wordpress Plugins is the Wordpress Backup plugin. It runs once a day and makes a complete backup of my wordpress database (with all these precious posts) and sends it in a mail to my Gmail-account.

kUbuntu 7.10

Just a few days before leaving for South Africa, the latest version af Ubuntu was released. I really didn’t have the nerve to try and upgrade before my vacation, but today was the day.

Ubuntu is an operating system – like windows – but based upon (Debian) Linux. It can probably do everything you need – and it’s free. With the packaging done to Linux by the Ubuntu team(s), it’s a complete user-friendly and easy to use alternative for most computer users, and it has worked pretty well for me for the quite some time.

Should you use sql specific statements?

It seems there are two camps when it comes to SQL and how to do database optimizations - the “generic camp” and “the specialist camp”. While I don’t consider myself an extremist, I am absolutely in the specialist camp and this little post is an explanation of why.

SQL is a generic database langauge . There are a few different standards in use (the language has progressed over time), but the core of the SQL language is pretty much the standard in most databases. It’s probably also standard - in any database - that the SQL standard has been extended with database-specific extensions which provides optimizations, functions or other options not available in the SQL standard.

CodeZoo

I just discovered O’Reilly CodeZoo today. What a cool idea – ”Find good code, use it quickly”. The net is just littered with bad code samples and finding a place where a high quality standard is set might be a great idea. Only problem is that the (probably) two most used languages on the net - PHP and Perl - aren’t allowed in (so far). Too bad, while good Perl code can be found, it’s hardly impossible to find any quality PHP code samples anywhere.

IP address conversion with Perl

With Perl you can do many interesting transformations of IP-numbers. Below is two small examples allowing conversions from “IP quad” (xxx.xxx.xxx.xxx) format to a single decimal and back. The decimal format may be more convenient and efficient to store in a database.

  sub ip2dec ($) {
    return unpack N => pack CCCC => split /\\./ => shift;
  }

  sub dec2ip ($) {
    return join '.' => map { ($\_\[0\] >> 8\*(3-$\_)) % 256 } 0 .. 3;
  }

In CPAN you can find many modules aimed at using and manipulating IP-addressees.

The case against tags

To every modern web 2.0 site offering tagging seems to be an absolute requirement. While I may agree, that tagging in some cases may offer some improvements in content navigation over many other points, I do think it’s been too abused in way to may cases.

Tags on sites such as Flickr and Del.icio.us are absolutely fantastic. They offer some cross navigation options, which would probably be near impossible, if not for the tags. I often find my self exploring links though del.icio.us, since the content stored there generally seem to be of a muh high quality than a simple Google search on a common term.