Tuesday, 12 March 2013

OCD and programming

I never really thought of myself as somebody with OCD. If you read the Wikipedia article you'll see it's a pretty serious mental state. I'm not calling it a disease. It's as bad as it could be and much as it's neglected. In my case I always thought it's just the massive time I'm having privately with my brain. Like two bohemian lovers.

I guess the first signs appeared the very first time I have memories from. I remember as a 5 - 6 year old kid was watching the door and tiles for long times - and I was thinking what would be the best angle to turn the door in order to make the perfect angle with the tiles. There were good and bad doors. Bad doors couldn't make it right. The worst doors could almost make it right, but their shadow ruined everything. Just to give one more hint - it's also important to check if the ratio of the tile edges - the part under the bottom of the door and the rest - they make a fifty fifty or even better a golden ratio.

You may ask why all the fuzz? It's about the environment and justice. You want everything to have an equal share of the global transformation. It took me ages to accept you can build unsymmetrical constructions from Lego. I had quite a lot, and all had the unsymmetrical way of creation - I was so mad. It feels like it wouldn't survive the first night in my room.

Many of you probably heard about OCD from Rain Man. It's a brilliant masterpiece. However Raymond's story is a bit more serious. I've heard about other families from friends where child custody was revoked due to the mental state of a parent.

I also have many friends presenting light symptoms of OCD. And I think in general that's a nice little habit. In general it doesn't harm you. You feel a bit frustrated when a layout is messed up - or even worse, "almost" perfect. I have huge problems with art. I can be stressed out by the tiniest detail on a painting. I guess that's why it's so outstanding when a piece of art seems to be complete and great. Usually OCD people highly appreciate balance over.

All right, it's not that romantic all the time. I remember when I was using Adobe Reader on Windows. The app had a pointing hand icon where the bottom part wasn't closed. So I was trying to fit that on all the circular fonts, like U, O, H or R - just to make it stable. I guess on OS-X it's even worse. It has a really handy zoom feature. Since I'm on a mac I use it to make all artificial alignments pixel perfect. Trust me it's a magical relief when 2 floating windows are on the same height, or some lines from different panels can be connected perfectly. I even have problem with the world famous OS-X font pixel hinting algorithm. You know, black is not black, it's a bit red, it's a black and a bit blue. And seeing those extra edge pixels can make life so hard.

If you don't have OCD then this might give you a little view on what's happening in some folks' head. And the best - these issues we see are everywhere and every time. Mixing it with a little ADD and years are running by so quickly you won't even notice.

But then I realized I can use it in my work. That tendency to aim balance let's you to find deviation much sooner. I'm quite sensitive to code quality and coding conventions. Typos and bad naming conventions are also really easy to spot. I started following a special naming convention - an important rule is to prioritize the grouping elements in the name. You know in function and variable names you have prefixes, subjects, objects, verbs and nouns and many semantical items. When you're using a IDE or Vim or grep - and you're doing file lookup you'll find things faster - simply because it's better sorted.

It might be only me, but I guess OCD helps when you refactor code as well. Keeping the balance also plays an important role in transformation. So eventually you accomplish a complete change and more likely you won't leave anything out.

I think it's also pretty obvious that OCD doesn't let you to miss any function header comment block, right separation of logical elements through files and many many useful coding practices.

I'm wondering what other mental issues could affect on your code quality. Probably depression could help you in your singleton skills or memory problems supporting you in using talkative code.


I'm super interested if you know you have strange habits and would share some stories.



  1. iamZoltanVaradi12 March 2013 at 14:37

    Totally agree. If my code is working but i know a function should be in an other class, or i could have used regression at some point and i didn't it frustrates me. After a few hours top i end up fixing it. Only because it messes up the zen in my code.
    Loved the article :)

  2. Thank you very much Zoli :) You're very right about having the zen feeling. Probably there should be an OCD fix button in the IDE just to fix the problem that doesn't let you sleep.

  3. Now it all makes sense... This is why I always approve all your code commits and you always send mine back because I've missed full stops! It's a good habit to have. Maybe I can learn to be a bit more OCD about the code I write!

    1. Hi Ed, actually my full-stop sensitivity comes from Moshe Weitzman (http://drupal.org/user/23) He reviewed my code couple of times and warned me about that. And of course for many other things as well. I guess the next level would be a CHX review :)

  4. We were sitting in a big rounded room during DT2011. Some 20+ people were reviewing one's code on the big screen and three of us were discussing something completely different. Neither of the two topics were easy to understand. I had a glimpse (for at most one second) on the big screen while listening to one of my own mates, then I had the sudden urge to stop him just to be able to shout out to the guy whose code was shown: hey, you have missed a full stop on your 3rd line, a space on your 10th and were calling Field API in a wrong way (missing argument) on 15th.

    Do I have OCD? If yes, then it means I'm in the same club with you, and I'm using this "skill" in my work, too. ;)