Some time ago I had a short episode of working for a Polish branch of a Germany based software company. In this entry (and probably a few following) I’m going to share with you a couple of WTF moments, so if you’re in for a few good laughs, read on! There is also part II of this story.

Monday

The first day started quite normal: I was introduced by the company manager to all 7 programmers, divided in two teams. I was assigned to the smaller, 3 people team. My first task was to build a computer for myself from parts scattered around the company: the box was here, the harddisk there and the monitor had to be taken “temporarily” from one of the servers.

After my computer was up and running, my teammates engaged in a fierce quarrel about which distribution of Linux I should install on my box. As I learned each of them was running a different one and in the second team the situation was looking similar. I chose Ubuntu because the guy sitting next to me (who was assigned as my “mentor”) was using it and he had the install CD ready.

Then the other guys started to remind him that he had several problems with this distribution (some related to work and some completely unrelated but that seemed irrelevant to them) and he fought back arguing that they had also trouble with their distros and it was at least as bad as his own if not worse. From this argument I understood that they had continuous problems with running their app on their systems (as in “it works on my box, why doesn’t it work on yours?”) and spent quite a lot of time trying to fix them. It also seemed that each of them used their own set of incompatible tools and scripts which they developed or configured individually.

Don’t get me wrong: I’m not trying to prove that they were completely stupid. It was just the opposite: they were smart, friendly, helpful and fun to talk with. We spend a lot of time talking about their hobbies, cars, games, movies, music and books. But at the same time I started to get a feeling that they were completely amateurish in their work.

To the end of first day I managed to get Ubuntu running, installed Eclipse and some other tools and checked out the project from the SVN. In the meantime, my mentor gave me a talk about the architecture of their system which seemed awfully complicated to me but I decided to keep my comments to myself at least until I get to see and understand the code. The system was written in Python and its main purpose was to process requests from the web app and issue queries to many different vendors, gather the results and send them back to the web app. He also told me that they had a big problem with the system being much too heavy and slow.

Tuesday

Next day I started browsing the source and felt my heart sinking like, well, something that is sinking really fast. So fast it’s going to fall into pieces when it smacks into the bottom of the sea. I hoped that their system would be elegant and beautiful just because of being written in Python. Instead it looked like if someone was trying create Python’s equivalent of worst PHP anti-patterns. Most of the classes were several thousand lines long and contained code dealing with everything for one vendor. Each of those behemoths sported methods of at least 200 lines long but 500 wasn’t rare at all.

After taking a closer look I noticed that most of the code was carefully copied/pasted from one place to another. Each of those methods processed one kind of request from start to end: initialized database connection with hardcoded username and password, constructed and issued the query, processed and formatted the results, caught exceptions and so on. I regret not running any metrics on this steaming pile of excrements but my guess was that after the duplicated code would be properly refactored into separate methods, it would be 3 to 4 times smaller. Do I have to add that the system wasn’t stained with a single line of test code?

I started asking the guys about those problems and their answers shocked me even more. The conversation ran something like this:

Me: Why don’t you guys use separate functions to avoid all this code duplication?

Them: Don’t you know that functions induce time overhead? Calling them and returning just takes too much time.

Me: AFAIK this overhead is negligible in most cases. Have you run some profiler to see if calling functions is really a bottleneck here?

Them: Of course we have. But you see this Python profiler is really stupid. It didn’t tell us anything useful.

I had a hard time believing this but not being an expert in Python profiling myself I decided to leave this path for now and concentrate on other aspects:

Me: But don’t you think that this copied/pasted code looks like a mess?

Them: Not at all. You have all the code right before your eyes. You don’t have to go looking for a function definition to see what it does.

Me: What if the duplicated code contained some bug? Don’t you think fixing it would be a problem?

Them: How can this be a problem when Eclipse has search&replace function?

That’s it for part one, but stay tuned! There is part II of this story.