Software metrics (PHP focused) part 1

Managing a software project with various programmers and around 10 contributions per day is a complex thing.
How can we measure the quality of every single contribution?
How can control the work of the programmers?

First stop: Lines of code

The easiest thing to measure in a project is the source lines of code it has. For example, the main project we are developing at work has ~30k lines (k=1000). That is, 24k of pure code and 7k of comments (and I’m counting only pure PHP OO code, without HTML, CSS or javascript).

Is this that simple to count? No, it’s not. The main problem is that programming is brain work, where creativity, skills to solve problems, and smartness are put in play. It’s like writing a novel: can you say that one novel is better than other just counting the pages it has? Can you say a Boeing 717 is worse than a 747 because it weights less? As the Wikipedia’s article says, only this metric can be useful when comparing 2 projects with different order of magnitude. However, the ratio comments per lines of code (in my case 1 comment every 4 lines) usually is a good index of quality.

Second stop: Average lines per day

Calculating the average lines of code per day can be tricky as well. At my job, a senior developer usually does ~50 lines per day, but a junior programmer does ~130 lines. Is that much? Well, having a look at some metrics about a similar project, phpMyAdmin, in Ohloh (a website with metrics for open source soft), and doing some maths, it’s suggestion is just 17 lines per day! On the other hand, if you google for “lines of code per day” you will get really wide values, from tops of 1k (using code generators: tricking) to normal less-than-100 values. Moreover, the deviation from this average value is actually huge: one day I can do 2 lines, other day I can do 200.

Senior does 50 lines, junior 130… is the senior one a slacker? Of course is not… usually the code from the senior one is better: less prone to errors, more adaptable, more concrete function’s names, more elegant, and does more things in less lines. The more the better? Actually the less code needed to solve a problem, the better. About this topic, I recommend reading the article : Code is your enemy!.

Tools? We use phploc for counting lines of code, and phpcpd for detecting cases of duplicated code. Both tools are developed by Sebastian Bergmann, the author of PHPUnit (the most popular testing framework for PHP).

Next, in part 2 of this post, I’ll be speaking about other metrics, like code coverage, cyclomatic complexity and some interesting ratios based on software package metrics.

Games against professional players

Just to keep track of the games I’ve played against professional players…

· Wang Runan, Chinese 8p
2004-2005 Winter, BCN’s Chinese restaurant, simultaneous (3 people), 9 stones, I was 7 kyu
B+2.5, I did some bad yose moves

· Park Sohyun, Korean 2p
2009-Jul-23, La Pedra Go club, simultaneous (6 people), 5 stones, I was 2 kyu
W+R, I made too many careless moves

· Lee Minjin, Korean 5p
2009-Jul-26, my home at Font Florida, casual game, 5 stones, I was 2 kyu
W+15.5, I made some over-defensive moves
(also I played a 9×9 game, 2009-Jul-26, Casteldefells’ beach, even, B+R)

· Nishimoto Kinya, Japanese 3p
2009-Aug-23, Sepúlveda’s Go seminar, tournament game (winner deciding match), 5 stones, I was 2 kyu
W+R, I abandoned some important stones

Holidays

Which one is better?
a) Use all (or most) of your free days in a row. You totally disconnect from work issues, but when you come back your’ll have a flood in your mail inbox.
b) Use them little by little, so do small breaks during the year. You don’t totally forget about work things, but you recover some energy several times.

Basically the thing depends on how many days do you need to reach a real disconnect status. And this also depends on what are you going to do during holidays: if your holidays include a lot of activities, you don’t need a lot of time to remove any track of work from your mind, but if you’re going to spend your time at home or next to your office, you’ll sure need more days.

Then, the key is to find the average amount of days you need to disconnect, and do as many breaks as you can with this length… if your employee lets you so.

The incest paradox, revisited

“You have 2 parents. You have 4 grand-parents. You have 8 grand-grand-parents. In each step you go back in time, the number of your ancestors is doubled.

Imagine 3 generations per century. You go back in time 30 generations (1 millennium), and the number of ancestors you had around year 1000 AC is 2^30 = 1073 millions. But wait, the estimated Earth population in year 1000 is just 320 millions! How can it be possible? The only possible explanation is that people committed incest and/or had multiple relations in that time.”

This was one of my posts in my first blog, in 2004. Pretty funny idea, but intriguing!

However, I didn’t realize, at that time, that you can apply the same idea to the future: if a baby will be born around year 3100, his nowadays ancestors should be 2^33 = 8589 millions, more than the current world population (6700 millions). So we are currently committing incest and having multiple relations!

Data extracted from Wikipedia’s Word population article.

With 2 pros at home

9x9 at the beachSometimes live gets interesting.

After a lot of weeks working hard (even 11,5 hours per day) to release our new product at work, I was destroyed. And by chance I got the unique opportunity of hosting 2 Korean professional baduk (Go) players. They where just the fresh air I needed!

Lee Minjin (5p, 25 y.o.) and Park Sohyun (2p, 21 y.o.) arrived to Barcelona on a summer sunny Tuesday, and stayed for a week. I met them on Thursday, when our local Go teacher, Lluís Oh, organized some simultaneous games. I played against Sohyun, but I made so many mistakes… my mind was too tired from work. I resigned.

Despite they are professional players, they are “normal” girls, down-to-earth, funny but incredible smart. And pretty, I should add. I thought they were not interested in speaking about “work” (Go) all the time, because they were on holidays. But I placed a Go board in a visible place of the house, just in case. I was going to host them just for 2 days, but when they saw the hammock on my terrace, they changed their minds and asked for a longer stay… how could I say “no”?

The amount of anecdotes is endless:
– After the simultaneous games, we went to a tapas bar. Somebody brought a Go board and a game between two locals started. At one point, one of the players started to ask for help: he didn’t remember a joseki, and didn’t want to leave a bad impression to Minjin, who was next to us looking at the game.
– Playing at home on DragonGoServer, they had a look at my moves… how can I play with 2 pros looking at me?! In one game I started a weird joseki, and my opponent wrote “take care, now I have a joseki book”. My answer was: “YOU take care, I have 2 pros at home”.
– One evening they were too tired, and decided to stay at home. I went out to meet some friends, and when I came back home… what a surprise! they were playing with my board, without asking me for permission, haha. They were playing a friendly match, and Sohyun decided to let Minjin start a big ko, despite it looked like she was winning by a little. A couples of ko threats generated another big ko in other part of the board. And I was there, standing up, speechless, like a statue watching the seasons. They reviewed the game at lightning speed, moving the stones on the board, as if they were born for this (actually that’s true).
– We went to the beach one evening, and I took with me a magnetic board. Minjin found my way to convert the 19×19 board to a 9×9 one interesting (I just have a piece of paper as frame), and offered me a game. An even game. And, after a ko, I won! Of course it was not a serious game for her, and I used a lot of thinking time, but hey! who can say “I’ve beaten a pro at 9×9″? ^___^ Later she told me I could be 7 dan pro, hehe. The register of the game.
– At night she took revenge on the normal board. 5 stones of handicap. It was a really interesting game. Playing with a pro is always an incredible experience, but playing in your own home, relaxed and calm, has NO price. I loved the way of her moves, so calm and relaxed. She didn’t clearly threat any of my groups; subtle but firm. I lost by 15 points. Here you have the register of the game and some of her comments. “Don’t be afraid” she told me… as if I could be careless against a pro.
– I asked them about their “job”. Despite they love playing baduk (Go), it’s a stressing way to pay the bills. Their income depends on their results in tournaments, and there is a lot of pressure. It sounds like a “normal” job to me.

For some days, my house was full of jokes and an incredible good mood. They filled up the house and my soul. The experience was huge, but the emptiness they left in my house was even more huge. The echo of the room drills my heart. The average level of my lonely house went down again to European 2 kyu. I should go to Korea soon!

The pictures!

The fractal plant

The fractal leaves

I would really know which plant is this one. Small, with a tubular trunk, and with surprising fractal leaves.

I considered it a weed, and was going to remove it from my celery pot. Until I realized such beautiful leaves evolution. In the picture each leaf generation is displayed. In each “floor” of the trunk you find 2 new leaves with evolved form. Moreover it seems that in the last generation the fractal pattern blow up, losing the simple shape and creating some complex one.

Nature, I can’t beat you!

It reminds me the L-systems shapes created in Inkscape. Actually there is a lot of real L-system generation applied to plants. For example, the work of the “Biological Modeling and Visualization research group” at the University of Calgary.

Looking for quality content in the web 2.0

How can we induce users to participate more in our website?
For sure a lot of people have this question in their minds. Since the arrival of the Web 2.0 the value of a web is based on its users and the content they create. The more quantity and quality of the user’s created content, the more value of the website.

The first step is to simplify the UI as much as possible, to help users overcome their laziness and participate. The state of art includes clever AJAX tools, browser plugins, and desktop applications. In some websites they go one step further, and reward somehow the most valuable users, like the stackoverflow.com’s badges (a website for programmers), where you get medals for doing things (like “silver medal for good answer”: voted up 25 times).

But what about the quality of the content?
If you help users to add content, that doesn’t mean you will have a great content, just a lot of content. In some cases you can finish with a website flooded by low quality content (read “Facebook”). This is not a bad thing per se, as happens on quite a lot of TV channels: despite their low quality, people continue watching them. But seems that specific (or thematic) websites have better quality than generic websites (this also works on TV channels). Just compare the ratio interesting-content / total-content in Flickr vs. Facebook : of course you can find some bad pictures on Flickr, but meanwhile you can find tons of uninteresting content on Facebook. On Flickr you are somehow induced to publish only good pictures, on Facebook you are just tempted to publish a lot.

So, the balance between quantity vs. quality rules the net as it does in other places. The thing is, as website creator, find the most profitable ratio (regarding personal satisfaction and/or monetary ROI).

Lately I’ve been thinking about resurrecting an old pet project, a website for creating and playing games. Is that specific group (the gamers) enough to pay the bills or just to pay some caprices? Is the “create game” part too specific, or just what I need to make the difference? How could I work effectively on this project while keeping my day job?… too sunny to think!

Focus on week basis

Sometime ago I decided to arrange my free time during the week (mostly evenings) with my hobbies and things to learn. I set each week day with an activity, like Monday for climbing, Tuesday for composing, etc… It doesn’t really work. The problem is that you have to wait a full week to do the activity again, so you lose the focus. And if you miss the day for some external reason, the problem is worse. Moreover, this method only allow you to have 7 different things to do, and if you change one, you have to remember the change…

So I had an idea: a single subject for each full week. On Sundays, in a relaxed way, I can decide the subject for the new week. And it’s not a problem if one day I can’t do it, because the idea is to try to focus on that subject as many days as you can, during that week. For example, this week subject is “Learn Blender“… so far so good, despite I’ve just spend 2 hours fixing a bug in this website (that is, something not-related to Blender).

For the future, some examples of subjects I have in mind:
– Refresh my C++ programming, maybe take part in a contest, or read some open source code (i.e. Inkscape code).
– Compose 8 songs, based on the I Ching’s 8 trigrams.
– Explore all the menus of Inkscape.
– Do something with my first bought domain, www.novelda.org.
– Help a friend to create a website for displaying Hex game records.

The book of Self-Sufficiency

Self-SufficiencyIn my last Amazon parcel I got the book with the largest name I know: “The New Complete Book of Self-Sufficiency: The Classic Guide for Realists and Dreamers“. It’s really amusing! It shows you all kind of farm related techniques, from sowing plants to building gates, from butchering a cow to installing wind mills. Moreover the illustrations are beautiful and useful at the same time. But the most interesting part for me, apart from the plant related stuff, is the lessons of philosophy that it contains. Let me quote some pseudo-random sentences:

(about sowing tomatoes)

The most luxurious tomatoes I ever saw growing were on the overspill of a sewage works, which leads one to think that it would be better to eat the seed before we plant it.

(about grapes)

I grew ninety outdoor vines there and got plenty of grapes. The pheasants ate all grapes but I ate all pheasants, so that was all right.

(his dry toilet)

The flush toilet is one of the greatest sins of modern man. (…) It is a remarkably expensive way to pollute fresh drinking water, while at the same time wasting the very nutrients that are essential to maintain fertility in the soil. One pull of the lever and the waste becomes somebody else’s problem.

(about clothes)

(During the 1992 Rio Earth Summit) we saw the citizens’ groups from all over the planet wearing ethnic clothing, or cheap T-shirts and shorts, whilst the government delegations and the like wore smart suits and ties. Of course they could only do this in their own artificial world of air-conditioned hotels, cars, and conference centres. Out in the tropical heat of Brazil, the suit and tie are about as sensible as wearing an Aran sweater in a sauna. The suit and tie have, of course, become the uniform of the merchants of greed.

Some of our modern behaviours are totally against nature. But the worst part is that people don’t realize it, or think that doing ecological stuff is totally uncomfortable. If you have never travelled to a poor country, or to a out-of-civilization place, you will never understand how difficult and costly are some things that you consume or directly spoil in your urban life. Anyway, if speaking about modern life is just too boring for you, at least do this: plant a tree, and look at it everyday… this will change your mind.

Weekly senses exercise

Reading a so so article about brain improvement and the excellent book “The Man Who Mistook His Wife for a Hat“, I mixed up some ideas, until arrived to this one: try to focus on only one sense each day of the week. Of course you always have all senses in “active” mode, but the idea is to spend some minutes feeling “twice” with one of them, noticing the details it gives you: patterns, contrasts, sensations, etc.

Mon – Propioception
Tue – Touch
Wed – Balance
Thu – Vision
Fri – Smell
Sat – Taste
Sun – Hearing

Isn’t this a good idea?