// Richard Hart / Hates_

Archive
computing

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.

Read More

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
Read More

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.

Read More

[gist id="172116"]

Great find by andhapp.

Read More

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.

Read More

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.

Read More

I said it before and I’ll say it again. Don’t like the new Facebook? Tough shit. Suck it up.

Read More

I’m so glad that I’m not just getting started as a web developer these days. Facebook is the main example I give to people when talking to about this. It has set the standard for what and how people think a web app should behave. Move forward or backwards through photos and they are dynamically loaded without refreshing the page. Send someone a message and a modal box appears with autocomplete on the textboxes. You can browse the site, chat to friends and do all sorts of stuff without ever having to experience a page refresh. I even remember when they added AJAX to their photo albums. I mentally flipped as it made the site so much more usable. I showed it to someone going “Look! Look! There’s no page refresh.” while they just shrugged and went “I don’t see what you mean.”, D’oh… exactly! The sort of stuff no one even realises is happening. But I’m sure they’ll feel the difference if they use functionality on your site that’s similar to something Facebook does, but which requires a refresh where as Facebook doesn’t. Even I feel the pain of moving forward and backwards through photos on Flickr. After the third or fourth page refresh, I just give up.

When I got started, web stuff was so new and so simple that in hindsight it was amazing what you could get away with. You could just fly by the seat of your pants. I know I did. The first piece of web development I ever did was back in the mid nineties two days before my first interview. I wrote a Java servlet that simply took a single text parameter and queried a MySQL database using JDBC. I showed it at the interview and got a job as a web developer using Perl. I didn’t even know the Perl but still got the job. All I had to do, day-in, day-out was write HTML and scripts that responded to clicked links or submitted forms. Submit, refresh and display the result, job done, I can go home now. Creating a site wasn’t hard, almost anyone could do it and almost everyone was at the time. Life was simple and it was pretty much a level playing field. Now though, it is a totally different ball game. You’ll need good knowledge of at least a couple of languages, HTML, CSS (Yes we need it to work across all the major browsers), SQL, Javascript + a framework like jQuery + how to use AJAX.

There is just so much that you need to know that if you’re not doing this in your spare time, how are you supposed to ever compete with the kids nearly half your age who can already do this stuff with their eyes closed. Even me, who does this stuff every day as a job has to learn more and more if I even want a chance of staying relevant and employable. I love learning, so it doesn’t bother me. Programming still turns me on and it has to if you ever want to make a go of doing this for a living. Sometimes you can be in the fortunate position of working for a company that really loves this stuff, so you can learn and grow, but I suspect the majority of IT related jobs are done in companies where IT is a second thought to their overall business goal. Where managers prefer to say “no” to your ideas rather then say “ZOMG we could totally awesomely AJAX dis bitch up!!!11!”. And the learning doesn’t just stop at work related subjects. There’s a lot to be said about learning new languages and techniques totally unrelated to your work. Not only for the mental stimulus but also how they can teach you to approach a subject in a new way. I admit this is perhaps one area where I don’t spend enough time, but I’m trying. So go forth and learn. Be totally fucking awesome.

Read More

It’s been a day with Safari 4 and I’ve yet to find a reason to switch back to Firefox. With it’s new developer tools, my discovery of FoxMarks for Safari and the Delicious Library bookmarklet I’m pretty much where I was with Firefox. The only thing I am currently missing is adblocking. I’m not sure if PitHelmet currently supports Safari 4, but Glimmer Blocker looks really good. It’s interesting that it works on the network level rather then as a browser plugin.

Read More

The new mac has arrived! I haven’t had a chance to really use it (that’ll all change next week) but wow is it a nice machine. I don’t need to gush over it as everyone knows how amazing these machines are. All I’ll say is my favourite feature so far is how cool all the available multi finger gestures are, not so cool is how obvious oil from your fingers appears on the black keyboard.

Read More