09 September 2013

Making code cleaner can result in a angry phone call


You have just released a update of your product. It includes more or less nothing, just a minor bug fix and cleaner code. Tomorrow it will reached 10 million smartphone users. The next day your phone is calling, one hour before it normally wakes you up. Its your boss!

I recently read a blog post by Erik Dietrich about legacy code (http://www.daedtech.com/intro-to-unit-testing-5-invading-legacy-code-in-the-name-of-testability) and how refactoring can help you to make it testable. The articel (and it’s serie) is very vell written, and as he writes in a comment he aims for novices. With this post I want to change focus from correctnes to performance.

Refactoring

In several books and blogs you can read about clean code, reduce cymclomatic complexity, duplicate code and how refactoring can help you. And that works!

If its legacy code there will most of the time be a comment saying something that it shall be done with caution and you have to write unit tests before. Thats also great!

But what you don’t read (or very rare) is that you should profile the code before and after to spot any performance differences. Why? Consider this:

What do you think happens if you refactor a code snippet, that is used in one of your most CPU intense part?

It will take longer time!

A quick person will say that he will inline that code, either by function of through compiler flag.

Well...that sound good, but are you allowed to change a compiler flag?

And if it’s already there, do you know how large functions that will be inlined? Maybe a software architecture has decided he wants to have control of what is allowed to inline for several causes. It could be: controling final binary size, debugging issues or something else.

Jumping around takes time

What happens when you have refactored a code snippet, is making a jump to another place and do something there. This jump takes time. If you need to bring some parameters to this function, you have to store them in a register. And also the return adress. This takes time. If you need variables in the refactored function, you need to allocate memory for those. This takes time. And you have to jump back when you are finnished. And this takes time.

This itself isn’t a problem, but if it’s done milions of time in a part that is already highly loaded, it can be a problem.

A angry phone call

Even if you as a developer thinks the code looks cleaner and is easier to understand, you also need to understand the harware and your customer. Here is some senarios:

  • There might be requirements about how long time a task can take.
  • There might be limitation on how much of the cpu can be used before a wathdog generates an alarm, or in worst case reboots your system.
  • There might be a customer starting asking questions why his system use more CPU load after your software update.


Learning to ride a bike is easy, the hard part is to ride in traffic jam

02 September 2013

My lifetime chance

I had my lifetime chance, but I turned it down
In the beginning of this summer I was offered a dream job, but I turned it down and I will tell you why.

What's a dream job
A dream job is something very unique, you and I have probably different ideas what that would be. What we do have in common is that it is something that we really want to have. It might not exist, or we are not aware if it does, or it exist very few of them. Probably its something that is really hard to get.
Something else that also could be said about a dream job, is that it gives something to you. It could be lot of money, a carer opportunity, working with latest technology or  something really interesting and motivating. It could also be so that it requires sacrifice from us that we are not willing to give.  

The first contact
In the beginning of the summer I was contacted by a recruitment firm and they were interested in my profile for a potential job position. This wasn't the first time I have been contacted, but I am a open person, so I always listen.  
-Wow! Is this for true? Does a such job exist?  Does they really want me?  
That was my first thoughts.  
Note: I have a good job with great colleagues and benefits, so I am not desperate looking for a new job, but I always listen if someone offering me something better. The "worst thing" that can happen is that I have to practice to market myself.
I discussed the offering with my family if I should proceed or not, mostly because it would require time away from my family and it was a international company without a office in Sweden (the purpose was to start up a business in Sweden). I decided to proceed. It sounded as a dream job and a lifetime chance. I updated my CV, mailed it to the recruitment firm and then the process started.  

The interview process
During one and a half month there were several interviews over phone and Skype, with the recruitment firm, potential manager and colleague and they all went well. Afterwards it was time for a test were my technical skills should be verified. I did really well (has I been told). It felt great and I actually started to believe that this was something for me, but also I was something for them.  
Because this company don't have any office in Sweden and I am full aware of differences in cultures, I raised some questions early, so we (I and them) could stop this process early if necessary. It would later show that the differences were not understood well enough.  
After all phone interviews and the test, it was time for the first face to face meeting in a hotel room in Copenhagen. The interview process started to reach its end. If this meeting went well it would then mostly be about formal issues if we would come to an agreement or not. I went to the meeting, it was a tuff meeting. They throw questions at me and I tried to answer them as good as I could. There were no room for rest and I was under hard pressure. In the end of the meeting there were room for me to ask questions. My focus was to be calm and answer honestly on all questions. If this job change should be successful, it must be a win-win situation.
I believe the meeting went well and I had probably proceed to the next step if it not were for something one of the interviewer said. I won't go into details but it concerns something really important in our culture and that was one of the the things I raised early during the process. This was the end.

Summary
Why am I telling you about this? When you do business with other people and they have different culture, you have to do your home work. You don't need to understand the other culture, but you must accept there is a difference, words can have different meaning and what you value in life is not necessarily the same. If you do your home work well, you will have a better chance to be successful in your business.  
About the job role, I am convinced it was perfect for me (and vice versa) and it offered lot of new challenges and possibilities. Unfortunately there was a culture collision and I felt very sad to call back and say no. I got to taste of something that could have been my dream job.
Now life consists of so much more than work achievements and I feel strong and proud of myself that I turned the offering down. Even if I didn't got this job, I have learned a lot.
  • I got to practice to market myself
  • I learned more about international interview process
  • I learned more about the importance of culture awareness
  • I learned more about another company
  • and the best part, I learned more about myself