Divergent Whys

Why – waste my time – when someone else will – and it’s not my responsibility – or my problem – when I have better things to do – and it won’t make a difference anyway?

Why – not take the time – Because I can – even if it’s not my responsibility – or my problem – even if I have other things to do – because I could make a difference?

Just something that came to me after listening to Seth Godin’s great book, Linchpin.

Time (benchmark) your commands

Perhaps unexpected, the time command, doesn’t actually give you the system time (use date for that). What it is does is “time” how long something takes to run (so a different use of the word time).

So for example, let’s say you are doing a mysql import, you can prepend it with time to find how long it took to run:

$ time mysql -u user -p db < import_file.sql

real 1m0.377s
user 0m0.637s
sys 0m0.126s

A quick and useful benchmark, even if it only lets you know how long you have to go make a coffee 🙂

That’s nice, but we never use it

Not the words you want to hear from the users of your product! It happens when you build more than you need to, when you don’t stick to simple, and improve incrementally based on real world feedback. Don’t rely on your initial design about what you should build. Designs are created in a vacuum, they are a best guess on how to build the thing you are going to build. What they really do, is document the original idea for something.

Don’t get me wrong, designs are very important, but the problem is it is very difficult to determine exactly what it is that will make your product useful, until it has actually shipped. Who’s to say all that time you spent on that feature will pay off before you ship? It may be completely ignored because people don’t like it, or just don’t have a need for it.

So next time you’re creating something, keep to the absolute essence, the very core of the product idea and deliver just that. After you ship, you’ll have no shortage of ideas about what you need to put in next. In fact, you’ll need to vet them just to shorten the list!

Memorability in Programming

I’ve mentioned previously that a key skill in software development is the ability to keep a program (or large parts of it) in your head. It lets you see how things work together, build on the code, and troubleshoot problems in a systematic way.

The human memory work works well with associations. You remember the alphabet in order – try recalling it backwards and you’ll see what I mean. It’s not just the letters, it is how they are associated with each other that you recall. Also, the more associations you can form, the less unique things you need to remember. This is why mnemonics (e.g. Roy G Biv for colors in the rainbow) work so well. You are basically creating pathways to a whole stack information through a key.

In terms of programming,  memorability is great. It allows you to make logical associations about the code. That is, until the associations start breaking down due to poor exceptions. Things like finding that “usually a reference to a user is singular, except in this class where it is plural”. That’s why consistency is king in programming. The more consistent you are, the easier it is to follow your program.

Commenting, is handy, but just as useful are techniques that bring about consistency such as your naming convention. When done correctly, It leads to moments like, “Ah, this variable is called xyz so it must be derived from class abc. Nice!” Conversely, one of the most frustrating situations is when you make an assumption about the code that should hold up based on the convention, only to find it doesn’t apply in this particular situation (lack of consistency).

So seeing as programmers mainly read code to understand it (and not write it), I think the ability write code that is easy to remember (and therefore easy to follow and understand) is just as important as any other software development skill.

Auto-number Rows in MySQL

The following SQL snippet is a really simple example of how to add an “id” field that is auto-numbered based on the number of rows returned by a query in MySQL.

select
    @id:=@id+1 as id,
    u.*
from
    (select @id := 1000) id,
    mysql.user u

This takes the data in the users table in MySQL and adds a column to the start called “id” which starts at 1000 and increments for each row (1001, 1002, 1003 … n).

Handy for creating things like id fields in inserts etc.

CodeIgniter Default Controller Routing

In CodeIgniter you use application/config/routes.php to set up the default controller for routing (the controller that automatically takes over when one isn’t specified) for example:

$route['default_controller'] = "user";

This is a good start, but the URL still needs to specify the controller when accessing functions outside of index. For example the URL needs to be: http://localhost/user/login instead of simply http://localhost/login to get to the user login function.

I haven’t come across an elegant fix for this. Things like using the $route[’(:any)’] parameter tends to break other controllers.

But what you can do is simply create a route for every matching function in your default controller. E.g.:

$route['login'] = 'user/login';
$route['logout'] = 'user/logout';

One caveat is if you have a function that matches another controller name you’ll need to change either the function name or the conflicting controller name.

Productivity Tools

After many years of searching for a good productivity tool, here’s a summary of what I’ve learned:

In the past few years, I have found 5 major contenders (yes there are many, many more options).-

At this point, I’ve settled on Wunderlist based on the following:

  • It’s simple to use (Wunderkit and Asana are fine, but they are more complicated, and do more things than I need or want).
  • It works on multiple platforms. In particular both Mac and iPhone. It is also usable on the iPhone – easy to view and add tasks as required.
  • It can schedule tasks. This is hugely beneficial as I have lists of tasks, and filter down what I need to do by scheduling things to do “today”.
  • It syncs to the cloud. Mostly important so every device you use it up to date.
  • It categorises tasks into lists. Actually, sub-lists would be nice, but this is good enough for now. A lot of people don’t like Wunderlist as they feel they have to have sub-lists. But do you really? They could be coming soon anyway, but I just hope the people at Wunderlist keep the product as simple as possible.

Really I find the following to be the key elements to using a productivity tool well:

  • It is your sole method of task capture and it eliminates all other ways through convenience and ease of use.
  • It is easy to access where ever and whenever required (largely helped by having it available on an iPhone or smartphone).
  • It is reviewed regularly (daily checks and weekly reviews). This takes discipline and has little to do with the productivity tool. However any tool that can make this process simpler is always going to better.

So there you have. Of course, you need to find your own productivity system and tool. Results will vary, but these may be some options to consider. As always, time is better spent “doing” than “planning” with such systems. Once you have something in place, give it a decent go (months) before chopping and changing. Otherwise you’ll find yourself in an infinite productivity tool loop.