VeryBello Is The New Italia.it

In the beginning (2007) there was Italia.it, a promotional website commissioned by the Italian government. Its main goal should have been attracting foreign tourists. The current version is not so bad, compared to the first one, but there are still some things that don't work.

I'm not referring to technical details (except the carousel that changes image too fast on my browser - and carousels are known to be an usability issue even at an average speed). The biggest marketing issue I see here is the fact that the site has been localized only in the major European languages. For example, Chinese, Russian and Arabic (three languages spoken by many tourists that visit Italy nowadays) are missing.

Back to the present. During last weekend, the Italian government presented a brand new site, named VeryBello!, with, more or less, the same purpose of the other. The bad news is that it's even worse.

Slow, not accessible, localized in Italian only, not to mention the name. Besides, in the first version of the top picture, a part of Italy was missing. I hope that no one in the world will judge Italian web designers and programmers basing on the quality of those institutional websites.

But, over all, I hope that nobody judges the whole Italy by the job of few people and the inability of its government to tell if that job is well done.

Double Facepalm

When You Must Write Unreadable Code

Punch card from a typical Fortran program.
Code was quite unreadable in the old days
Well, if you know me or read this blog since some time, you should know that I consider code readability even more important than correctness. This is because a bug-free code does not exist, thus, soon or later someone will have to fix it in the smallest time possible.

Nevertheless there are at least two situations where is needed that your code is difficult to understand.

You Want To Be Indispensable

It may be because you are a contractor and you want that for the company is easier to ask changes to you instead of try to manage them internally. Or, if you are an employee, you may be afraid that someone else can take your position, and the company can decide to fire you.

No matter the reason, writing unreadable and poorly commented programs is a good way to make the understanding of your code really hard and time consuming for everyone, except you. With these premises, the company best choice is to don't give your code to anyone else.

You Hate Your Colleagues

This is a sort of revenge. Do your mates have a better salary than you, bombastic titles in their business cards, and the boss always praises them? The only way you can punish them is by forcing them to understand your terrible code.

This can be done in a large scale by including a refactoring session each time you add a new feature or fix a bug in an understandable file. Of course, your main goal is to mess things.

They have to feel the pain each time they are requested to change something you touched.

Drawbacks

There aren't many, just a couple. First: your colleagues may hate you and consider you a bad programmer. If you are writing unreadable code just to annoy them, this should not bother you too much.

Second: the code will be difficult to understand for you too. So, after a couple of months it will be painful for you too to manage you own code. If you are an hourly contractor, this can be a good thing since every change will take longer.

Conclusions

I personally don't see any other reason to write poorly readable code. And also the above two are quite questionable. Always remember that with a good VCS is easy to detect who introduced the mess in the code and, at some point, someone may decide that is better to restart a project from scratch instead of having only one developer able to manage it.

RTFMC

RTFM by xkcd
If you don't know, the acronym RTFM means "Read The Friendly Manual". And this is exactly what I've done several months ago, when I've used a third party library. I've made a simple test program and everything seemed to work just fine.

This week, I've used that library for work and I've started to see some strange behaviors in my app. The output of the old test program was still correct, but the same code in a bigger application caused wrong values being shown and some crashes.

It took me hours to understand where the problem was. And, can you guess?, I found it only after reading the friendly manual carefully. It was clearly written that some returned data were references to members of a structure.

What I was trying to do was to access them after the structure was freed. The simple test program seemed to work fine just because it was too short, so the memory just freed was not overwritten by anything else.

Lesson learned: it's not enough to read the manual; you have to read it carefully. Or, if you prefer an acronym: RTFMC.


Image from xkcd licensed under a Creative Commons Attribution-NonCommercial 2.5 License.

How To Recover Deleted Git Commits

In many Git tutorials it's written "never use git reset --hard". And there is a good reason: this command deletes commits, and, if you don't have pushed to a remote repository, your changes are lost (if you don't know where to find them).

A Little Story

This happened to me some year ago, when I was a Git newbie. There was a bug on a software so I created a new local branch starting from the master and started to fix it. In the meantime, a colleague of mine asked me for a quick workaround to continue his work. So I switched back to the master and added a couple of temporary commits.

After a week, the state of the repository was this:


The bug was fixed, the temporary commits could be removed and the branch merged to the master. Easy to say, easy to do, easy to mess.

My idea was to move to the master, delete the temporary commits and then merge the fix branch. Unfortunately when I run...
git reset --hard HEAD^^
...I was on the wrong branch. The good commits were gone. Panic!

Where Have They Gone?

What I've learned from this experience is that deleted commits are still there, at least until you run git gc or git prune. The problem is to find a way to bring them back. What I did at the time was to use grep to search for the commit message under the directory .git of the repository.

In this way I've discovered that in the directory .git/logs/refs/<branch-name>, in the logs are also recorded the hashes for every commit. With hashes it has been easy to checkout the second commit (going in a 'detached HEAD' state) and verify that nothing was missing.

At that point, I've created a new branch (with git checkout -b new_fix) and carefully executed the original plan, this time without surprises.
I love it when a plan comes together!
- John "Hannibal" Smith

The Long Way To Dual Boot

During the Christmas holidays I've bought a new HP laptop with Windows 8.1 preinstalled. I'm not a fan of Microsoft operating systems but my wife is not addicted to Linux like me, so I have to manage the dual boot.

First Boot With Windows 8.1

After the initial configuration, where I've disabled every automatic update procedure, I've looked around to see changes compared to Windows 8. Well, there are three main difference I've noticed:
The Start button of Windows 8.1
  1. at startup you get transported directly to the Desktop,
  2. there is a Window button in the bottom bar (see image) that opens the infamous tile screen, and
  3. while hovering the mouse of the top of applications with the new interface, a title bar with the X button appears.
Well, I've seen too much, let's start to do something serious... but, wait, who downloaded 20 MB from Internet?

Partitioning

Hard disk is 1 TB but there are some extra partitions (rescue, boot loader and an unknown one) that reduce the available space to 900 MB. My idea was to have two 250 MB partitions (Windows and Linux) and the remaining space (about 400 MB) for the data.

So I tried to shrink the 900 MB partition with the Disk Management tool provided by Microsoft but the minimum allowed size was 800 MB. Remember, I've said to myself, defrag is your friend.

The last time I've run a defragmentation tool it was several years ago on Windows XP and I remember there was a graphical ribbon that showed used and free sectors. In that diagram, fixed (i.e. unmovable) files were shown with a different color. The last version of the defrag tool doesn't have that visual hint anymore. This lack could seem irrelevant, but it would have made me save a lot of time. Let's see why.

When the defrag ended its job, I was able to resize the partition, but the smallest size was about 455 MB. Still too much. So I tried to remove the so called crapware and run the defrag again. [Honestly, compared to my previous PCs, this time the unwanted/useless preinstalled software were very few.]

No results. The minimum size for that partition was always 455 MB. I tried to remove some other programs, reboot and run defrag again but nothing. So I did a quick search on internet and I found that other guys around the world have the same issue. They solved by using this free tool. And so did I. After a couple of hours I was eventually able to resize Windows partition.

Dealing With UEFI

In the meantime, I've prepared a bootable USB pen drive with Xubuntu 14.04 64 bits. Once plugged into the laptop, I expected that the system would automatically boot from there. No way. Windows boot started immediately and there where no indication about the key to press to enter the UEFI settings. I've had to reboot at least three times and to press as many F-keys as possible before being able to enter. So, the first thing was to set the waiting time to five seconds.

Then I've reshuffled the boot sequence, saved the changes and installed Xubuntu. After few minutes it ended, I rebooted and... Windows started. Reboot again, press ESC and a boot menu appeared. Now I was able to boot Linux but I was not satisfied: I wanted Xubuntu as the default choice.

So, since Google is my best friend, I've found in which UEFI submenu I had to select the Ubuntu bootloader instead of Windows one.

Finished? Not Yet

Well, let's see if I can access Windows filesystem from Linux.


The key parts are the following:
Windows is hibernated, refused to mount.
and
Please resume and shutdown Windows fully (no hibernation or fast restarting)
The best way to resolve this issue is to disable the fast start. This function does not let Windows to shut down when you ask for it, but just hibernates it, to make next boot faster. This leaves the disk in a state that it's not safe to modify; for this reason, Linux refuses to mount it in read/write.

Conclusions

Before starting I thought it would have been more painful. It has taken more time than what should be, but fortunately I've been able to make the dual boot work properly without bothering too much.


Cover image created with Picfont.