Archive for October, 2010

PHP: How to generate URLs in your webapps

Sunday, October 31st, 2010

With SEO becoming more and important, it is critical that you produce the exact same URL from the same piece of content everywhere.  Furthermore, the URL structure is often decided upon only after you’ve started development. Our experiences from the last few years have led me to believe that the ultimate method for generating the proper URLs time and time again is to use a separate function for each different URL  in th following pattern:

function my_url($data_object, $context=array()){
  return root_url(    
           "my_url_page/".$context['category']['name']
           ."/".$data_object['seo_slug']
          );
}

This has the following advantages:

  • If you decide you need different fields from your data object to generate the URL, you only need to change it in one place
  • If you need extra context information,  it is easy to search where you call this function
  • One place to check if you are properly urlencoding everything
  • Avoids generating multiple urls for the same page

Because we also want it to be easy to remember, we put them together into an object:

class My_URL{
  function root($str=""){ return "/".$str; }
  function my($data_object, $context=array()){
    return $this->root(    
                    "my_url_page/".$context['category']['name']
                    ."/".$data_object['seo_slug']
                   );
  }
}
function urls(){ return new My_URL(); }

$myurl = urls()->my($data_object, array('category'=>$category) );

To  make it a bit more fancy and less work,  you can create a bit of magic for common cases:

class My_URL{
   // ... same as above. Plus: ...
   function __call($method,$args){
     $url = $this->root($method);
     if(sizeof($args)>0) $url.="?id=".urlencode($args[0]['id']);
     return $url;
   }
}

You can make it as fancy as you want, for example in some projects we have one big __call function that uses a configuration file to determine the urls based on the method name and data objects. Furthermore you can use functions to normalize urls like upper/lowercase conversion and anything else that will help you generating better and more consistent URLs.

Todo lists : Do and Don’t

Friday, October 22nd, 2010

Every time I’m unhappy about my progress I resort to Todo lists. Basically there are two types:  personal  and per-project.  Often a per-project todo list is implemented as a bug or issue tracking system.   These are very useful to keep everyone on the same page and not forget about things that do need to happen.  There is not a single reason why you should be using some sort of system to keep track of the future of your project.

The personal todo list is another thing (Gmail has a very nice and easy to edit one. )   Although they seem essential for a task-oriented approach to time-management,  I found there are many mistakes you can make.

The first and most important one is to let them grow:  You start enthusiastically with the first day, write down your tasks for that day and complete them.  However, not all days work out as well,  so  you will not always complete your tasks.  And here comes the danger of a todo list:  you tend to put the tasks you did not complete onto the next day.  So after a while your list gets full of tasks that you keep shifting forward.

The other danger is to put tasks on it that are not really tasks.  E.g.  ‘finish project X’.    That’s not something you can do now ‘right now’.  It’s something that has an undefined start, duration and ending. No wonder that it’s impossible to cross anything off for days. And nothing makes you feel worse than having a todo list and not crossing anything off.

The final problem is  adding tasks that are not for  today.  Often you have stuff that you need to do that feels convenient to put on your todo list. However,  if you are like me, you have a lot of these ideas and after a while it becomes more like an e-mail inbox up till the point that it seems impossible to finish everything.

So, learning from these mistakes I have decided that the best solution is to keep the Todo Today on paper and make a new one every morning. Furthermore the unfinished tasks from yesterday can not be at the top of your new day. Having it on paper will  encourage to not just re-edit yesterday’s list.

Focus

Thursday, October 21st, 2010

Just as I’m busy improving my time management skills I came across  a nice book that touches a lot of the subjects I wrote about (and plan to write about n the near future). An interesting thing I got out of it is the use of rituals to get focused.   As I usually don’t have a problem staying focused once I really get started. So I will definitely try to incorporate that in my life.

The book has a free (and hassle free) PDF version as well, so I highly recommend it as well as the blog I found it on: zenhabbits.net.

Being Busy

Wednesday, October 20th, 2010

I have seen many other programmers with this behaviour and I do it to:  making yourself busy.  I’m sure you will recognize one or more of these:

  • Checking your e-mail more often than you get important new mail
  • Visiting news sites more than once or twice a day
  • Refreshing Adsense stats more often than they update
  • Twitter (It’s almost unavoidable to check the updates frequently)
  • Going through a fixed set of websites without really paying attention to the content (just checking if there are any updates)
  • Watching a news channel on tv, more than 10 minutes

All of this comes down to two thing:  feeling busy  and the need for something ‘new’.  You can tell yourself that these are things that do need to happen, which makes it much harder to stop doing them that often.  Furthermore,  if you stop doing one of them it is just replaced by some other time waster.

One thing I’ve done to counter part of this behaviour is:   switch of all notifications.  Beepings, blinking windows, etc. make it almost impossible not to check stuff way too often.

The other thing I am trying to do, is to consider the alternatives: What could I be doing instead?   To force myself to be more aware of this, I decided to leave the computer immediately when I find myself clicking back and forth.  Now there is time to evaluate:

Why am I doing this?
If it’s because I don’t want to do a certain task, what is holding me back?   If there is not enough information: go get it.  If you don’t know the solution:  sit down (away from the screen) and think about it.  The Pomodoro Technique I wrote about can help some times to commit to actually doing the task. Especially regarding sitting down to think about the task (with 100% focus) as part of the task itself might make a difference to you as well.

Can I do something else that is at least more useful?
If you don’t have the energy to work on the task at hand, maybe there is something else you do feel like.  Getting done anything is better than failing to do anything while trying to do the most important task.  I especially suggest:

  • Study something that will give you some inspiration (maybe some development / time management / marketing techniques)
  • Writing a blog post (Even if I don’t feel like coding anything at all, this often works)
  • Walk the dog ( It needs to happen some time, so better when you are not in the middle of being productive)

Can I do something more fun?
If things really aren’t going (you know those days) consider if there is anything more fun to do.  It might be better to just take the day of and really do something fun.  (Ok, I know… this isn’t an option for most with a regular job)

If all else fails, even staring out of the window might be a better spending of your time.

Disclaimer:  I haven’t really put all of this into practice yet, so more will probably follow.

Getting Things Done: The Pomodoro Way

Sunday, October 17th, 2010

A few days ago I wrote about procrastination and by coincidence I came across an article about changing your working method to embrace the interruptions, instead of trying to find long stretches of concentration (‘the zone’). It is a nice read, however, more importantly in the comment section I came across something that really appealed to me: The Pomodoro Technique.   I had seen it before, but it didn’t jump out to me at that time.

The basic idea is:  work for 25 minutes on a single task, with a timer ticking back the time left  and then take a break. This is augmented by a few other important steps, such as: noting down your distractions, evaluate them only after the 25 minutes are up and crossing of the completed intervals per task.

As I don’t have a proper timer yet, I looked for a software one, that works under Ubuntu as well  and came across:  Focus Booster.   It makes the ticking sound and also very nicely automatically starts your 5 minute break timer after time is up.

I just started using it, so I’ve only done a few of these ‘Pomodoro’ intervals, but I feel very confident that this will actually work as it makes you very aware of the distractions you need to avoid/delay  and the time you have available.  Starting the timer gives a feel of commitment about doing something NOW instead of  in a few minutes. Furthermore, having a timer tick back, give you back a bit of that deadline stress that makes you feel productive, without the disadvantages of real deadlines. And, not unimportant: it feels good to cross of real productive time.

Linux on the Desktop: Eventual Success

Wednesday, October 13th, 2010

I wrote about trying out Linux (Ubuntu) on the desktop before.  That attempt failed in getting my video card drivers to work properly.  However a few months later,  I got my windows PC infected with a virus ( just by passing by on a website)  and decided that was it.   I installed Ubuntu on my laptop (Dell D630) and have been using it every day since.

My hardware was very well supported,  I had no problems whatsoever, so that was a good start.    Furthermore, it provides me with an environment similar to our webservers and I have most of the tools I used:  jEdit, Photoshop 6.0 (using wine), skype, Firefox, TweetDeck and an SSH client.

There are still a few things though:

- It actually feels slower than Windows, especially Firefox (probably more optimization as gone into the Windows version as it is more wide-spread)
- Keyboard shortcuts are not very well standardized, so I find myself using the mouse  way to often
- There are some GUI things I’d like to be much simpler (like  enabling/disabling an external monitor)

All together I’m quite happy I made the switch.  I tried it many times before over the last 14 years ( I have a book and disks from 1996), but only now it has really became a viable alternative.

Deadlines Are Killing

Wednesday, October 13th, 2010

My whole life I’ve been trained in sticking to deadlines.  School and University is nothing but doing a reasonable amount of work  for an event fixed in time (tests,  reports to hand in, etc)  Which, if you are anything like me,  means  procrastinating until the exact moment it can’t wait any longer an then work very hard.    Procrastination is rewarded:   it gives you more free time  and good results, so by the time  you get to your graduation, it has been perfected to find exactly the minimum amount of time needed to still get good results.

However, this skill gets you nowhere on real projects.  Projects like  your graduation or  developing a new product, where there is no fixed ending and you really want to get done as much as possible, as soon as possible.  ( I can probably make a todo list that fills the rest of my lifetime )  Of course there is the fun/interesting stuff that will never get you stuck, however every project (even the most fun ones)  have those tasks that you just need to get done. Not being able to do so in a timely manner is very frustrating.

The first obvious way to try and fix  this, is to create artificial deadlines, to get back that feel of urgency. However, deadlines that you set yourself don’t work, I’m just way to much aware how arbitrary they are.

Furthermore, on real projects, the amount of work is not known in advance. So there is no way to determine when to start to finish ‘just in time’. On the other hand lots of stuff you delay, might take far less time than you expected.  (You actually spend more time thinking about how much time it is going to take)

Procrastination is also closely related to getting ‘into the zone’ (Read: Joel Spolsky on that topic), but to be fair,  there are also lots and lots of activity that do not require any ‘zone’ at all. So, I feel a strong urge to  ‘solve’ this productivity mystery.   One of the obvious choices is reading about the ‘getting things done’  method. However I’ve never succeeded in making it work for me:  Writing everything down in a system, makes it even more overwhelming then just managing it in my head, as my brains are a lot better capable in hiding the ‘someday/unimportant’ stuff that I come up with.

I’m still in doubt though whether this is not just your brain telling you that there is only a fixed amount of productive time and the idle time in between is just needed to solve complex problems. However, there are a few things I did find, that do help:

  • Committing to a task, by telling someone that you will do it: ‘right now’.  (Not some time in the near feature, really: NOW)
  • Do another task instead, that you feel really passionate and confident about, to get going
  • Split up your tasks into such small subtasks that it’s impossible to not finish it (So every time you do any work, you actually finish something, instead of going from   ‘busy’ to ‘still busy’)
  • Work together on a project,  you can keep each other going  ( I believe that is one of the biggest arguments in favor of pair programming)

Are you a procrastinator as well?  And what do you do about it?