Grab the feed

School is a twelve-year jail sentence where bad habits are the only curriculum truly learned.

John Taylor Gatto

Recent comments

Some lessons from building Drupal 6 themes

After a few Drupal 6 projects where I had to create themes from scratch, including my recently released Woodpig theme for Ventanazul I've learned a lot and decided to gather some tips I'm sure will help you, my fellow Drupalist, when turning your next design into a functional Drupal managed site. Sounds good? Let's dive into the powerful Drupal 6 theme API.

Emacs or Vim as a programming editor (part 3)

This is the final installment in a three parts series about Emacs and Vim as programming editors. I've discussed Emacs in the first part and Vim in the second one. Let's see now which one I choose as my favorite tool for editing source code, and frankly everything else.

Emacs or Vim as a programming editor (part 2)

This is the second of a three parts series about Emacs and Vim as programming editors. I've briefly reviewed Emacs in the first part and now will talk about Vim.

Emacs or Vim as a programming editor

emacs vim

Yes, I know there are plenty of Vim and Emacs comparisons out there but I wanted to throw my own and focus on the use of both editors as programming tools.

Some publications mention a holy war between users of Vim and Emacs but I don't think war is the right word and refuse to even comment about the holy part. War is something that stupid people do. We, good programmers, are not stupid. Period.

Emacs and Vim are powerful editors for powerful users (and you're one of those aren't you?), useful tools that allow us writing and modifying code faster. Both can be used as word processors, I do all of my writing with Vim, including this article and my next book. Emacs goes even further providing an environment for doing much more than just editing text.

Programming tools and languages are very subjetive choices. Some get used to a set of tools and stick to them, even if new or better options appear. I prefer being open, if there's some alternative that could make me work faster and better I spend some time learning about it, and by some time I mean anything from a few hours to some weeks. It's a logical investment in useful knowledge.

I've written this three parts article to help you in making the right decision about the right editor. It's a very important one, specially if you spend eight or more hours a day swimming in code. My focus will be on productivity for programmers.

In this first part I'll talk about Emacs, the second installment will be focused on Vim and I'll conclude the series with some ideas on which editor I think you should choose for your programming tasks. All of this, of course, based on my own experience so your mileage may vary.

If you are already a Vim or Emacs user, I don't intend to change your mind but taking a look at the other side and comparing won't hurt, you may even get a little inspiration. If you don't use either yet and consider yourself a smart programmer this may be the time to give one of these guys a try.

When did you learn to program and in which language?

It's Saturday morning and I started the day reading another chapter of Introduction to Algorithms (Cormen, Leiserson, Rivest y Stein), a must read for every programmer no matter which your favorite language is.

And while I tested some Python code I tried to remember when I started to program and in which language. It was 24 years ago, in 1984, I was twelve and my first computer, a PC XT (Intel 8088, 4.77 MHz) had less than six months at home.

The language was Basic, first as BASICA and later as GW-Basic running on DOS 3.2.

And you? When did you learn to program and in which language?

Quotes causing problem with Python and simplejson

Python logoMy little Django and Facebook project needed to do some JSON processing, time for using simplejson then.

My application will receive a string of JSON and transform it to a dictionary, pretty simple. Let's run a test first, starting with the Python shell, or better yet, iPython, and importing the module:

import simplejson

Now let's define a string using JSON notation and pass it to simplejson:

band = "{'name': 'Mando Diao', 'genre': 'rock and roll', 'bid': 19383}"
json = simplejson.loads(band)

And we get a ValueError exception. Let's try using simple quotes for enclosing the whole string and double quotes for the JSON keys and values:

band = '{"name": "Mando Diao", "genre": "rock and roll", "bid": 19383}'
json = simplejson.loads(band)

And there you go, no error now:

print json
{u'genre': u'rock and roll', u'bid': 19383, u'name': u'Mando Diao'}

I find a little strange that this problem happens as I've been using either type of quotes for most of my Python coding. Had you noticed this problem? I've checked simplejson's documentation and could not find anything related to this.

One last word, the new Python 2.6 includes a json module, which is a refactored simplejson. Neat.

Some hints about overriding themes in Drupal 6

There's a lot to read and absorb on the new Drupal 6 but the good news is that if you've spent a while hacking version 5 you will need just a few days to get up to date.

One of my favorite changes is on theming. Now every module can provide its own .tpl.php files. To override them you just need to copy them to your theme directory and start hacking around.

Why I Decided To Use FSFS Over Berkeley DB With Subversion

I've had enough dealing with permission errors and corrupted database issues in the Subversion repository I use in one of my development servers. Most problems came from using the default Berkeley database as my repository store so I decided to move to FSFS.

Even if the Subversion book has a section explaining how to setup users and permissions and create wrapper scripts to use the correct umask, I didn't feel safe running a repository store that even the Subversion development team perceives as very sensible to interruptions.

Some advantages of FSFS over Berkeley database include:

  • Can be used from a read only mount and doesn't depend on umask settings
  • It's platform independent
  • Repository size is slightly smaller
  • It can be used on network filesystems
  • Quite insensitive to interruptions

So, I've created a new repository specifying FSFS. You just need to add the --fs-type fsfs parameter, like this:

$ svnadmin create --fs-type fsfs /path/to/repos

I'd recommend not wasting your time with Berkeley database for your Subversion setup, just go for FSFS and you'll be cool.

More about Subversion and how I use it on all my web projects coming soon.

Open Source Applications For Database Modelling

Are there any open source applications to model my database? Many developers have asked me that question quite often lately.

When coding Drupal modules having a good picture of the database model can help a lot to write the right queries, well, actually this applies to any programming project that uses a database with more than a few tables.

Even if there are many commercial applications, many of them quite stable and complete, I think their prices are way too much for most developers, specially for open source developers like most of us Drupal dudes. Want numbers? I got numbers: CA Erwin Data Modeler costs US$ 3995. With that much dough I'd prefer to complete my list of gadgets I want for 2007 and add another laptop with Linux to my arsenal.

So, what are the options to model your database with an open source tool?

Some years ago I found DBDesigner 4 and used it in a few projects to model on MySQL, the only RDBMS it handles. I was quite happy to know that MySQL had taken over the product to relaunch it as MySQL Workbench, however, MySQL has focused on other tools and Workbench progress has been slow. I've recently read in their forum that they were almost finished with other tasks and would return to work with MySQL Workbench. Good to know.

DBDesigner 4 is still available and is a good choice if all you need is MySQL support. The installation is a little difficult in Ubuntu, although I didn't have any trouble with Fedora..

And what happens if, like me, you also need to model PostgreSQL databases? The only application I found for that some months ago was Mogwai ER-Designer, which works with MySQL, PostgreSQL, Oracle and a few other commercial RDBMS. Mogwai ER-Designer is written in Java, so it runs in most operating systems with a JVM.

Unfortunately Mogwai's interface still needs some work and creating models is not too user friendly, even when they correctly use domain dictionaries. I also think development progress is going a little slow.

What I'm using now, and recommend, is Power*Architect, which, like Mogwai, is a Java application and works with PostgreSQL, Mysql, Oracle and others.

I think PowerArchitect has a better interface than Mogwai, creating models and generating SQL is quite easy and takes just a few clicks. PowerArchitect has been declared open source just a few months ago, way to go guys!, and there are still many features to add and improve (like support for native auto increment fields in both MySQL and PostgreSQL) but it seems the development team is right on track and version 1.0 is coming.

So there you have it, there's still hope and we'll be seeing more mature database modelling tools in the open source arena soon.

Oh, and if you know of any other let us know.

Update September 19: Sean just told me that native types auto_increment in MySQL and serial in PostgreSQL are supported in the latest versions of Power*Architect.

Programming Facebook Applications in a DSL Based Server

I recently posted a few ideas on the opportunities for web developers in Facebook.

I decided to use DynDNS for creating a host name for my local DSL connected Ubuntu box, it's easier editing and making changes that way instead of using the other servers I have in a couple of data centers. I used the hostname as a callback url for a Facebook test application. Facebook saw my host and the application worked as expected.

A couple of hours later I disconnected from the Net to take a break, when I got back received a new IP address from my ISP's DHCP server and DynDNS updated my host information to point to the new IP. Unfortunately now Facebook can't find my callback url anymore. I tried editing settings and changed the host name to the new public IP address to discard, still no luck and I'm getting this error:

The URL http://xx.xx.xx.xx/facebook/application-name/ did not respond.

There are still a few kinks Facebook and the makers of application-name are trying to iron out. We appreciate your patience as we try to fix these issues. Your problem has been logged - if it persists, please come back in a few days. Thanks!

Is Facebook caching my older IP address? That was my first thought but even putting the actual public IP of my box in the callback url didn't work.

Is this a temporal glitch in the Facebook Platform or am I missing something else?

I'll keep testing but if you have any ideas I'd love to know.

Fixed: I'm an idiot! I forgot changing the IP address of my database server, also in my local box. Now everything's working again.