Little jQuery.extend gotcha

jQuery.extend() is a very powerful function for merging two objects or for extending jQuery with custom plugins.

There is but one little gotcha to think about: as in most function calls the order of parameters matters 🙂

Following two fragments of code yields different objects

var a = {
  aa : '1'
  , bb : '2'
  , cc : '3'

var b = {
  aa : '11'
  , bb : '22'
  , dd: 3

var result_a = $.extend({}, true, a, b);
var result_b = $.extend({}, true, b, a);

The result will be this:

Notice that I use $.extend({}, true, a, b) instead of $.extend(a, b). The first parameter (which is optional) is the target which should receive merged properties. If none is given than the first object is extended automatically.

So, is the world really faster?

Every now and then I hear people complaining that the world is now much faster than it used to be in time of our grandparents. But is it really so? Did people complain about that very fact in their time? Another common complain is that parents now have less time for their children or their partners. I don’t agree with this. I think that generally we work less now, don’t we have 8 hours long work day? Problem is that we have now too many options to choose from. It is difficult to choose and be happy with your choice, when choosing one option means saying no to all other tempting options. We have twitter and facebook statutes, google reader, rss.. and so on and so on. The amount of information is so overwhelming, that we always miss something. We just can’t catch up on it all. Therefore the world seems so fast. It’s not that much about the progress and innovation pace but about the number of small choices and distractions you face every day.  So why not just slow down and enjoy simple (offline!) things?

As a programmer I tend to follow what’s going on in the industry. I love learning new stuff. So I read about new technologies, I try them, dream about using them. And I often feel kind of guilty that I can’t learn them all. I always feel quite behind. Incapable of following. I guess that lot of people have similar problem of trying to do too much.

After reading that sleep is more important then food I decided to try to slow down and really sleep more. Yes, it does help :). I don’ t always manage to get those recommended 8 hours per day, but when I do, I can tell the difference. I just focus much better when I am fully rested (surprise:) ).  One of the requirements to get more sleep and feel better is to drop something off. Make more free time for yourself. Then your world will be slower again as it should be.

Environment and productivity

What kind of environment is best for work? Do you work in such? When I worked for IBM I was confined in a cubicle in a big open-space.  It was an experience I don’t want to go through again. The environment was “noisy by default”, there was a continuous sound-spam of chatting people. It was really difficult to concentrate and be productive.  The only way how to avoid it was to put on headphones and listen to some music.  But still I was disturbed by IM notifications and other crap.

Now I work in a small office in a team of five people and I am totally happy.  Most of the time nobody talks and if then it is mostly work related.  There is often silence, the only thing you hear is fingers tipping the keyboard.  I guess I sound quite nerdy, but I really like it this way. I believe this is the only way how to be really productive. Talk little, avoid being disturbed (if possible) and focus on the task at hand.  Then take a break, read some short article, have a cup of tea, or a little walk in the office.  That helps. If I deliver nice code, I am happy. If I don’t then I don’t like myself. Really.  I am far from being a perfectionist, but I like good work. I find it satisfactory 🙂

What helps me focus and create something is good music.  I can not play any musical instrument but I am an enthusiastic listener. I am particularly fond of jazz music. I know it may sound as a contradiction because jazz is often difficult to listen to, but it helps me to write code. Jazz is so full of energy and surprising ideas, that it lifts me up. It inspires me.  I love Pat Metheny for example. Listen here. Is it beautiful?

So .. this is the kind of music I listen to when I code. Or when I need to get new ideas. Or just to sit back and relax 🙂

What kind of music do prefer to listen to when you work? Or do you prefer silence?