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.