Richard Hart

Something @ Somewhere • Kent, UK

  • I was doing some reading on usability stuff and thought I’d check out our homepage. Pretending that I know nothing about what we do and then reading all the text on the front page, I asked myself: How does a user use us? Is it an online service or is this a marketing site for a manual service that we provide via phone/email whatever? After reading it a couple of times, there is no way of ever knowing. Yes, there is the take a tour, but that’s already one click away from the homepage, and most people don’t scroll or go a level deeper then the homepage unless they already know what they are looking at is of interest to them. One can argue that the front page is a “teaser”, or a hook to gain a persons interest, but looking at the studies done, people don’t browse like that. The hook is not “Could this be of interest to me? I should find out more” but “This is of interest to me. Show me more.”

  • If you’re still using phpMyAdmin to admin your remote database, then you’re doing it wrong. Don’t expose your database to the outside world like this, instead use a SSH tunnel. In your terminal simply create the tunnel:

      ssh -fNg -L 8888:127.0.0.1:3306 {your_username}@{yourdomain.com}

    Then in your MySQL interface of choice just connect to 127.0.0.1 port 8888 and voila, you’ll be connected to your remote database.

    Apps like Querious even let you setup the connection internally without having to tunnel through in Terminal.

  • The Law of Demeter, or Principle of Least Knowledge is a fairly simple design pattern, which, simply put means that an object should only talk to it’s immediate “friends”

    The law states that a method M of and object O may only invoke the methods of the following kind:

    1. a method on O itself
    2. any parameters passed to M
    3. any objects instantiated within M
    4. any direct components of O

    The classic example coined by David Bock used a Paperboy (one object) delivering a paper, then extracting money from a Customer’s (another object) Wallet (and another):

     class Paperboy
        def get_payment(customer)
          self.money += customer.wallet.take_out(10)
        end
      end

    In the “real world” the Paperboy would ask the customer for the money who would then take it out for them, rather then the Paperboy reaching into the customer’s back pocket and getting it for themself.

    Really we want something as follows:

      class Paperboy
        def get_payment(customer)
          self.money += customer.get_payment(10)
        end
      end
    
      class Customer
        def get_payment(amount)
          wallet.take_out(10)
        end
      end

    This may all seem trivial and a waste of time, but what happens if some Customers want to pay by cheque? Those decisions should have an impact on the Paperboy, otherwise we end up with:

     class Paperboy
        def get_payment(customer)
          if customer.pay_by_cash?
            self.money += customer.wallet.take_out(10)
          elsif customer.pay_by_cheque?
            self.money += customer.cheque_book.write_cheque(10)
          end
        end
      end

    Where as it makes more sense for the change to be contained within the Customer:

    class Paperboy
        def get_payment(customer)
          self.money += customer.get_payment(10)
        end
      end
    
      class Customer
        def get_payment(amount)
          if pay_by_cash?
            wallet.take_out(10)
          elsif pay_by_cheque?
            cheque_book.write_cheque(10)
          end
        end
      end

    So what does this have to do with Rails and the delegate method? The delegate method adds a quick and simple way of following the Law of Demeter without having to do very much at all.

      class Order
        belongs_to :customer
      end
    
      class Customer
        has_many :orders
        has_one :credit_card
        has_one :bank_account
    
        def payment_method
          if pay_by_card?
            credit_card
          elsif pay_by_account?
            bank_account
          end
        end
      end
    
      class CreditCard
        belongs_to :customer
      end
    
      class BankAccount
        belongs_to :customer
      end

    This setup means to get an Order’s payment we would have to say:

     @order.customer.payment_method.withdraw(amount)

    But if we simply change our objects as such:

      class Order
        belongs_to :customer
        delegate :withdraw_payment, :to => :customer
      end
    
      class Customer
        has_many :orders
        has_one :credit_card
        has_one :bank_account
    
        def withdraw_payment(amount)
          if pay_by_card?
            credit_card.withdraw(amount)
          elsif pay_by_account?
            bank_account.withdraw(amount)
          end
        end
      end

    Now all we have to say is:

    @order.withdraw_payment(amount)

    So at any time, the details of how a payment  is to be decided can be contained with the Customer. This is of course a simplistic example, but hopefully explains how you chould be using this handy feature.

  • I’ve finally done it. After months and months of on-off usage of Vim, I’m now finally using it 100% of the time. It’s been a long and hard road getting here, but let me tell you, it’s been well worth it. I now feel like I absolutely fly through my code. I’ve read many a time, people saying that watching someone using Vim is like watching something mystical, and I can see why. Looking at how I edit code in Vim now, makes me feel clumsy when I think back to using other editors like TextMate. Don’t get me wrong, TextMate is a wonderful editor, but there is just something about the speed and finesse of editing in Vim which I have just fallen in love with.

    I wrote about trying MacVim before and how I just felt it lacked the spit and polish that TextMate does. But now, I can’t remember why I originally felt that way. There’s a simple elegance to the Vim, yet with this awesome power available to you. Switching wasn’t easy in the slightest. I would load Vim up for an hour, tinker around, get frustrated and go back to Textmate. Then a month later I’d try again, learn a new command, last two hours and go back to TextMate. A few more months and hours turned into a full day, then the full day turned into a couple of days, and then I never looked back.

    One of the keys to hitting the ground running is having a good config. I originally used jferris‘s vimfiles but moved to scrooloose’s files not long ago. It practically has every plugin you could ever need to make life in Vim sublime.

    Some other handy references I’ve used along the way have been vimtutor, the Vim Recipies Cookbook, the Vim Tips Wiki. To aid my own memory of useful commands I’ve even started my own Vim tumblr.

  • My gym started a new dry triathlon challenge and I thought I’d give it a go. I swear I have never dug so deep in my entire life. I’ve always read about people wanting to throw up and I’ve never felt like that until after completing my round. I’ve never felt so dead or exhausted.

    It’s been a real eye opener though. I had always thought I gave it 100% when I went to the gym and now I can kind of see why I never really get anywhere with my training. There’s no real point to this point, other then to just say, no matter how hard you think you’re going, you can always go harder. I just hope I never forget the experience.

  • Skype on OSX


    There’s just something about the way Skype looks on OSX that really bugs me. I can’t tell what it is, but the UI just feels really intrusive. Then again, it’s probably not supposed to be kept visible like I do with my contact list in Adium, which has a brilliant transparent and borderless option.

  • When I restalled all my gems on Snow Leopard, vlad refused to find any of the tasks I had defined in my deploy.rb. I thought this was a SL issue but turned out a week before it’s release Vlad had been updated to version 2 which used a new plugin system. Looking for vlad rake tasks returned an error:

     >> rake -T vlad
      Could not load vlad: no such file to load -- vlad/git

    To solve the problem just required an install of the new vlad-git gem.

     >> sudo gem install vlad-git

    Now all my tasks were appearing properly. Vlad 2 always brought around a few changes in it’s deploy.rb and use. Here is my deploy.rb for reference:

     set :application, "yourdomain"
      set :domain, "yourdomain@yourdomain.com"
    
      set :user, "yourdomain"
      set :repository, "git@github.com:youraccount/yourdomain.git"
    
      task :staging do
        set :revision, "origin/staging"
        set :deploy_to, "/opt/yourdomain.staging/"  
      end   
    
      task :production do
        set :revision, "origin/master"
        set :deploy_to, "/opt/yourdomain/"  
      end
    
      namespace :vlad do
    
        desc "Pull from git, run migrations, then (re)start the app server"
        task :migrate_deploy => [:update, :migrate, :start_app]
        
        desc "Pull from git then (re)start the app server"
        task :deploy => [:update, :start_app]
        
        desc 'Restart Passenger'
        remote_task :restart do
          puts "Touching: #{deploy_to}current/tmp/restart.txt"
          run "touch #{deploy_to}/current/tmp/restart.txt"
        end
      
      end

    Now invoking Vlad for my staging environment works as such:

    >> rake staging vlad:deploy

  • My new cards from moo arrived.

  • I was recently asked why I don’t comment my code. It’s a fair enough question. There was a time when commenting your code was the done thing. I was once a great believer in commenting code as much as possible and would bash those that didn’t, but now I vary rarely comment my code at all. In my current project of over 1,500 LOC, there are only a handful of comments. Many people will argue this is irresponsible. Well how is anyone supposed to pick up and understand my code, if it’s not commented?

    The code should comment itself.

    That just sounds silly. It’s like saying a car should drive itself. But it can be done. A lot of this change of heart about comments has come from my commitment to becoming a better developer and spending countless hours reading about the practice of great development, which is something I’ve written about in the past. I’m a big believer that most of the time if you need to comment a piece of code, then it’s either bad code or too complicated. Of course that’s not true 100% of the time, but for the other 99% it really is. There are cases where things need to be explained and especially warned of, but a lot of the time, commenting is just an easy escape from having to do “proper” coding. It took me years and years to get a basic understanding of proper OO and I’ve still got a long way to go to reaching Journeyman levels of understanding, but I would always create large objects with huge and complex methods, when really what I needed were more concise classes with more responsibility for what they should be able to do. It’s not object orientated when you’re focus is on the method and not the class.

    A simple example of commented code:

      # Feed the fish.
      def check_food(food)
         # Check if Fish has eaten more then 5 hours ago.
         if self.last_meal_time < 5.hours.ago
           return "Not hungry"
         # Check if the Fish eats this food.
         elsif !self.edible_foods.contains?(food)
           return "Can't eat that!"
         # Make sure the fish isn't being underfed.
         elsif food.amount <  fish_feeding_amount(self.type)
           return "Not enough food."
         # Make sure the fish isn't being over fed.
         elsif food.amount > fish_feeding_amount(self.type)
           return "Too much food."
         end
         # Eat food.
         self.eat(food)
      end

    Most comments can be done away with. If we split out functionality into more concise bits, then just reading the code should explain what’s happening better:

      def feed(food)
        return "Not Hungry" if self.recently_eaten?
        return "Can't eat that!" if self.does_not_eat?(food)     
        return "Not Enough food" if self.not_enough_food?(food)
        return "Too much food" if !self.too_much_food?(food)
        self.eat(food)
      end

    This isn’t a great example as once again the validation of whether the food can/will be eaten should move into it’s own method or class ever. If we’re follow Uncle Bob’s SOLID principles, the above examples breaks the OCP (Open Closed Principle) where entities should be open to extension and closed to modification. If more validation rules were needed, then that would require the code to be modified.

  • Spotify


    I admit. When I was first told about Spotify, I dismissed it as my experience with most web based players had been pretty poor. Most of the time I couldn’t find what I really wanted to listen to and when I finally did the quality was too poor to be enjoyable.

    Now I’ve been using Spotify now for a few days and I’m tempted to actually go as far as to say I’m impressed. The only thing stopping me from giving it a full 10 out of 10 is the fact that it doesn’t have anything by two of my favourite bands Tool and A Perfect Circle. I already have those albums as mp3s, so no big loss. The big plus is I’ve already listened to a number of tracks and albums legally that I would have otherwise pirated. I’ve paid the £9.99 for premium access, which gives me ad-free listening (they are annoying) and a higher bit-rate music. To be able to listen to that much music for that much a month, is extremely worth it. For the price of a single album, I can now browse and try out as many different artists and albums as I like.

    Another nice feature is the radio. I’ve spent some time just listening to random music and come across some really good stuff I would have otherwise never heard. My only gripe though is the lack of a “World Music” or “Classical” option. Sometimes when working I find that foreign music is pleasant to listen to while not being distracting. I raised an issue in Spotify’s GetSatisfaction page, so who knows, perhaps the feature will turn up someday soon. If you haven’t checked out Spotify already, I highly recommend you do so. Oh, but if you’re not in Sweden, Norway, Finland, the UK, France or Spain, sorry, you’ll just have to find another service. For you Americans, consider this minor payback for not giving us Hulu.

  • I suffered some pretty poor service when I returned to JEM Ltd to have the faulty valve fixed. I won’t go into details but here are what I think are ways of offering good customer service:

    Apologise

    Whether or not a customer’s complaint is valid and even not your fault. Just say sorry and try to understand where the customer is coming from. At rather then just being told “We’re really sorry, we’ll do our best to help.” they tried to wriggle out of having anything to do with the problem. Although a short term win for them, I’ll never be returning and will be making sure I make it known to anyone I can to never go there. Any short term loss involved with rectifying my problem would be repaid through repeat business and word of mouth about the quality of service. Washing your hands of a customer’s problems is not a recipe for success.

    Listen

    When a customer is angry, don’t point it out, you’ll only make them more angry. Saying things like “Before you get angry” or “If you’ll just calm down” will only infuriate them more. I’m not normally one to get angry and wasn’t at the time, but wow, did this push me over the edge. People get angry when they fell like they aren’t being listened to. Shouting is a way of making yourself heard. So if a customer is shouting at you, double your efforts to listen to them. As corny as it is, God gave us two ears and one mouth for a reason.

  • I first picked up the Productive Programmer a few months back and after flicking through it I initially thought a lot of it wasn’t relevant and didn’t bother reading it. As I had been playing around with Vim (again!) and thinking about the whole idea of being more productive, I felt compelled to pick it up once more and actually read it. After learning a few new OSX tricks within the first few pages, I was hooked. Admittedly I skipped over any Microsoft related content, but overall the book is full of real productivity gems, and ever since I’ve been on a quest to increase my day to day effectiveness when it comes to using my computer.

    My first port of call was sitting down and learning to use LaunchBar properly. I still have a long way to go, but more and more I’m using it to find and open files, as well as small things like quickly playing music and using the extremely handy clipboard history. I’ve stripped my dock of all apps except those that are running. The reason being that there is no need for me to use it as a launcher when I can use LaunchBar to start any app I need, without even having to use the mouse. I’d totally hide it from my screen, but somehow that feels “anti-Mac”.

    Secondly I customised my terminal to be more “friendly” and learned some advanced command line techniques courtesy of the Peepcode screencast on the subject. Now I have a load of aliases as well as custom functions which culminate commands I frequently run in conjunction with each other.

    I also spent some time learning more general shortcuts as well as trying out some other apps to help in my quest for computing Zen. One is Desktopple, which hides apps which have been in-active for a certain period of time and another is TextExpander, which allows you to create small snippet shortcuts, for example, typing r@ now automatically expands to become richard[at]ur-ban.com. Very nifty.

    To try and become more effective overall in my life I’m really trying to knuckle down and keep a track of everything I need to do using Things. As with any todo app, you get out, what you put in. If you don’t really make an effort to use it and dump stuff into it, you’ll never really get anything out and never get anything done. I would have prefered to continue using The Hit List as I have a registration for it, but it would seem the iPhone app is still nowhere in sight. So for now, Things is what it’s going to have to be. I’m also now making more use of Evernote. I regularly email notes to myself and had totally overlooked the fact that I could just email them straight to my Evernote account. So now, any thoughts or ideas I have appear straight in my account thanks to the power of Email. I’ve also installed The Habit Factor on my iPhone to keep a track of my goals. It’s a simple app which lets you set a number of goals and habits, which you can then tick off each day, hopefully leading you to form good habits over time.

  • New Office


    Out with the old and in with the new.

  • As you may (or may not) have noticed. I’m back to the old WordPress version of my blog. I spent a lot of time moving over everything to Jekyll. Mainly for the “performance” increase of having to just serve static files generated by the Jekyll engine, but it ended up being at the cost of me never posting anything. After migrating I soon felt like small random snippets where beneath the category of “articles” that I had created and not being able to see and view posts instantly made me completely shy away from bothering to write anything.

    So WordPress is back and maybe I’ll post more from time to time. Even though things here are mostly quiet, my tumblr and twitter see a lot of daily action.

  • Microsoft recently started their new ad campaign where seemingly normal people try to buy a new computer. They’re given a budget and if they find one that fills their requirements, they can keep it.

    The first advert follows Lauren with a budget of $1000. She wants a laptop that’s fast, has a comfortable keyboard and a 17” screen. On her quest for a laptop she visits the Apple store and comes out saying they are over her budget and that she’s just not cool enough to be a Mac person. She has no trouble finding a suitable laptop in regular electronics store and ends up purchasing a HP Pavilion. The second advert follows Giampaolo with a slightly bigger budget of $1500. He wants a laptop that’s portable, has good battery life and power. Once again there is a poke at Apple. This time they are more about aesthetics rather then power and that he doesn’t want to be paying for a brand. And once again he ends up with a HP Pavilion (Oh, HP, that’ll be the brand you just paid for then).

    My problem with the adverts isn’t the poke at Apple, but rather they are promoting a non-message. If I’m going out to buy a new computer and I don’t want a Mac or want a Mac but don’t want to save for it, I have no choice but to buy a PC. I can’t see them swaying the people who have made the choice to switch and have the money ready to buy a Mac. So who are these adverts aimed at? There’s no competition in the sub $1500-$2000 range, so is it even worth doing at all. Honda make ads to stand out amongst Toyota, Ford etc. They don’t make adverts in the hope that they’ll stop people that are thinking of splashing out on an expensive sports car, and sway them to settle for a Civic instead. This and the previous ”I’m a PC” series of adverts just end up legitimising Apple’s presence. Apple is a tiny dog biting at the heels of a giant, yet Microsoft feel like they need to gear their entire consumer TV advertising campaign to take them on. The campaign may well be just insurance for Microsoft. How many heads would roll if they decided to ignore Apple completely, or not even bother advertising to consumers, and then their market share tanked. Perhaps it’s better to appear to do something, then to not do anything at all. On the other hand though, could all that money be better spent doing something else.

    All of which leads me onto what I would do if I was Microsoft. Simply, I would advertise Windows 7 and IE8. I’d give people hope once again in Microsoft products (Hopefully the products would match the hype). But I’d ram it down people’s throats day and night. “Forget what you thought about Vista, Windows 7 is coming”. “Experience the web like you’ve never done before. IE8 has arrived”. That sort of stuff.

    Perhaps that’s what I find so alluring about the “Apple way”. When you see them in use, you feel like you’re being taken to a time and place beyond the normal preconceptions of how technology works. Microsoft used to have that. Microsoft used to ask “Where do you want to go today?”, with the promise of taking you there, no matter how far fetched your dreams were. Now they just state “Your potential. Our passion.”, which leaves you with the sinking feeling that really over the years a massive void has grown between us and them.