Happiness and motivation

It’s 7 month since I joined the ubxd crowd and I think it has been the most productive 7 month in my life. I asked my self why. What drives me, challenges or motivates me ?

I think that you have already heard about companies like Zappos, Goretex, Ikea…. These companies are trying to create best work environment that motivate people to work harder with enthusiasm and happiness. What they are doing for this? Is that they don’t separate directors from “normal” employees? They have really great company culture and they motivate people to be creative.

You are maybe asking how do they motivate people to be creative? Do they offer bigger salaries or bonuses? The answer is not exactly.

There is scientific study that proves that money is motivational but only to the certain level (and for a certain type of job). This level is different for everybody. It’s a level where person feel comfortable and don’t has to think about salary all the time. If the employees reach this level you are unable motivate them by increasing salary so you have to find another motivation factor which is happiness.

Happiness in company

I believe in fun and feeling of satisfaction in the work. I’m expecting that the company that I’m working for, to try to offer this kind of environment or the company culture, if you wish.

Every company is different and there is a saying that company culture reflects the personality of the founder. To be honest I’m not sure if you can apply this in big companies, but it certainly works in medium and small companies.

Just look at the randomly selected startup. Firstly, who is in the company? It is the founder. As company grows he hires people with a similar personality because he needs to communicate with them and it’s better to sit every day in same office with somebody who you like than somebody who drives you crazy.

You can look at the Zappos or Hash rocket. First they find somebody who is good for the job position and then they chat with him and make sure that he fit in to the company as a person.

Agile + Rails + Ubxd => Happiness

One part of the Agile Manifesto says “Our highest priority is to satisfy the customer through early and continuous delivery of valuable software.” Satisfy => to make happy. So yes Agile helps us make our customers happy. But a happy customer is only one part of equation. There are also programmers (like me), and we deserve to be happy too, so we work with Ruby on Rails which help us a lot. So those two things packaged by Unboxed’s company culture (with great people around me) make me happy and productive.

What makes you productive and happy?

Ckeditor with Amazon S3 and paperclip.

I was working on project recently, where I had to use CKeditor with paperclip and amazon s3 as the storage. This all is running on Heroku. The solution is really easy. You have the paperclip in you model…

I was working on project recently, where I had to use CKeditor with paperclip and amazon s3 as the storage. This all is running on Heroku. The solution is really easy. You have the paperclip in you model

has_attached_file :avatar,
 :styles => { :big => "180x180#", :medium => "140x140#" },
 :storage => :s3,
 :s3_credentials => "#{Rails.root}/config/s3.yml",
 :path => ":attachment/:id/:style.:extension",
 :url => ":s3_domain_url"
And you have something like this in the picture.rb and attachment_file.rb (app/model/ckeditor/)
has_attached_file :data,
     :url => "/ckeditor_assets/attachments/:id/:filename",
     :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"

So solution is obvious now:

has_attached_file :data, :styles => { :big => "180x180#", :medium => "140x140#"},
 :storage => :s3,
 :s3_credentials => "#{Rails.root}/config/s3.yml",
 :path => ":attachment/:id/:style.:extension",
 :url => ":s3_domain_url"

That’s it.

Pair programming with your mind

My last post was about pair programming. Recently I start working on a small project where I can’t pair with anyone. So I started thinking “what could I use from pairing even When I’m not ? “.

My first thought was to act as if I was, so I would have to act as 2 different people. I should change my t-shirt and wear a hat or just put on glasses and change my hairstyle every time I change from one persona to another, but this could look really strange and potentially have detrimental consequences.

Another thought was, “Hey what are the advantages of pair programming which don’t depend on the other person directly” ? The answer is a better understanding of code, cleaner code and faster development. But how exactly would I achieve this? Let’s find out!

Better understanding of code

Better understanding of code is based on the fact that you explain your implementation to your partner. You can still do this, and very often you are actually doing it without noticing.

If you are speaking or just mumbling to yourself out loud then your brain is using different parts then if you were just “thinking” about the problem. So if you ask yourself out loud “Why doesn’t this work?” or “Ok this points to that if the value is….” then it is same as if you were speaking to someone else. Even if you ask yourself “What would Mr X do?”. Than you force yourself to look at the problem from a different perspective it would also help you.

Faster development

In pair programming you usually switch between each other for short time periods or small problems. This could be easy implemented and the answer is sprint. Pick small timeframe (10 minutes) in which you can implement some functionality. Then you set your watch or phone or some tools that you can download and start. You will see that you are trying to finish your code in the time limit (including your tests of course ;-) ) which will speed up your programming.

Cleaner code

Cleaner code is basically only about you, and because nobody is watching, you tend to not care that much about sanity of your code.

When I start programming in Ruby my friend who taught was really strict about code sanity. Every time when I paired with him, he would point out every small thing e.g. end of the line, space between operators etc.. So I was forced to care. Since then even when I’m not pairing I always make sure my code is clean enough to satisfy his sanity check. So imagine somebody who’s got your respect and is really anal about clean code. Try to not disappoint him.

These three rules will help you in your “virtual pair programming”. If you have another technique feel free to leave a comment!

7 reasons why pair program

I was wondering why lot of people still don’t want to pair program. So I wrote down my most important reasons why you should pair program. Btw if you don’t know what is pair programming, here is explanation.

I was wondering why lot of people still don’t want to pair program. So I wrote down my most important reasons why you should pair program. Btw if you don’t know what is pair programming, here is explanation.

Faster learning – if you pair program with more experienced developer you will learn more faster than you would learn alone.

Faster development – Even thought sometimes pair programming may be slower (pair senior / junior), in general it’s faster. Two people working on same issue have different ideas how to solve the problem or they can suggest better and faster solutions.

Learn new things – It doesn’t matter if you pair with skilled or beginner developer. Every person thinks differently so you will learn new techniques or just different approaches on how to solve the problem.

Better understanding of code – If you pair program you have to explain what are you writing and why. That will help you think more about problems and their solutions.

Cleaner code – Pair programming usually forces you to write cleaner code, because you are watched and you don’t want to look like bad programmer, do you?

Bus factor – Pair programming help you increase the number of people that could be “hit by a bus” without affecting productivity, ie more people have knowledge of code base. (Bus factor explanation)

Eyes will rest – Yes this is good reason too. If you pair program you usually don’t stare at the monitor for long intervals (which help you eyes), because you have discussions with your co-worker, about the issue, that you are solving.

So are you finally convinced to pair program ?

How to tag SVN branch on the server from Git repository

Image the following situation:

You are using SVN on the server and to deploy on the server you have to TAG release. You are using Git on your local machine and you have following commits.

Image the following situation:

You are using SVN on the server and to deploy on the server you have to TAG release. You are using Git on your local machine and you have following commits:

Task is to create the SVN branch from first red dot and than add the another commit marked with the black dot.

Git version

To do that in Git  is what you would expect:

reset the master to last commit that you need (red),

1: git reset --hard SHA_code

than create and switch to new branch

2,3: git checkout -b name_of_the_branch

and cherry-pick the commit/s.

4: git cherry-pick -x SHA_code

Git SVN version

Reset master to red dot

1: git reset --hard SHA_code

create and switch to new branch

2: git svn branch name_of_the_branch (this create branch on the server)
3: git checkout -b local/name_of_the_branch name_of_the_branch

and cherry-pick the commit/s.

4: git cherry-pick -x SHA_code

and push changes on the server

5: git svn dcommit

to tag this branch on svn type

6: git svn tag tag_name

Note: if you did not checkout the branch in proper way (svn way – step 2) you will tag the master branch

Fix your broken window!

As a programmer working with other programmers, I’m usually contributing to an already existing code base and basically just adding new functions or extending their functionality and because I’m person who could be influenced by others opinions, I also could be influenced by others code and code formatting.

For a moment try to remember what your code looks like if you are writing brand new project and how, after a couple of weeks, this code is still nice and shiny even if you are working with 2 other programmers. Now back to reality where you working at old project where is lots of ugly code. Do you think that project start with ugly code? No, usually it doesn’t. So what changed that nice code to ugly one? Why even if all of programmers are good and writing nice code does, this happened? The reason is what’s called the broken windows theory.

Broken windows theory as the name suggests is about broken windows(not the MS Windows though). Imagine a street with nice houses and white fences. One day, somebody brakes the window of one of the houses. After few days, nobody has fixed the window because the house is empty, even though it looks very nice. One of your’s neighbours kids then brokes another window and because there is already one broken, nobody cares that much and time goes by. After couple of months the house has a broken fence, a couple of windows and garbage all around it. Soon this ugly house will affect the behaviour of your neighbours as the surrounding area deteriorates. You may start to care about cleaning sidewalk, but by then, the whole street has started getting ugly and uglier.

This story represent exactly what happen to you brand new nice code if somebody brakes the window and nobody fixes it.

So behave to your code as a good neighbour and try to leave your code in cleaner state than was before your changes, the whole area will be nicer as a result.

I’m not working

Yes that’s right, despite the fact that I’m employed by Unboxed I’m not working anymore. I’m going to work every day, programming some stuff but it’s not work for me anymore. Really.

I have had this feeling since I start working with Rails and this feeling became stronger when I came to London and joined Unboxed. I had heard about Agile and Scrum and I had tried to practise TDD and BDD before, but it’s really different here and now.

I joined the real world of Agile. I was so excited (and scared) when I had my first standup and my first retrospective. I’m still excited, because everyday is different. One day we have to do standup without our Product Owner (PO) because he is stuck at the tube. On another day, I was alone since everyone else was on holiday. Is it still a standup if only one developer and the PO are present? I think that it is, because the important thing is that I can tell him what is going on and another day of excitement can start.

Of course there are days when I’m tired, but you can be tired even after sitting on the beach with a Mojito in one hand and great book in the other. At the end of a tiring day at the office I look back and discover that I’m tired because I experienced so many new and interesting things.

So what am I actually doing if I’m not working? I’m a little bit scared that I might be dreaming. I’m scared I will wake up in my cubicle with PHP code (without tests) on my screen and without any slight hint of Agile or Scrum and Waterfall knocking on my door. So please don’t wake me; I like it as it is!

Proper error messages on rails

In order to have proper validation error messages on the web page I want to specify what the message will look like. Problem is that if you set validation message in your Person model like this:

validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :message => ‘invalid e-mail address’

you get on you page error message like this:

1 error prohibited this person from being saved

There were problems with the following fields:

‘Email invalid e-mail address’

but customer wants something more human like., for example:

Oh dear there were problem

That doesn’t look like a valid e-mail address. Please try again.

I found a solution and here is how to do that. First we change the Header error message and delete the submessage.

In your view where you are displaying errors use proper options for error_messages_for

error_messages_for(:person, :header_message => “Oh dear there were problem”, :message => “”)

Than the interesting part, error messages are in this format [attribute_name, message] but we need only the message part so without any hacking or parsing we can specify format of the message directly:

validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :message => :”email.format”

The part :”email.format” says that you have specified message text at your i18n file (usually config/locale/en.yml) .

en:
  activerecord:
    errors:
      full_messages:
        email:
          format: "That doesn't look like a valid e-mail address. Please try again."

And that’s it :) Feel free to comment.