Thursday, September 25, 2008

Good excuses NOT to use version control

Recent post from made me laugh. 'No version control' execuse. I have to reveal my stupid experience for this. It was my first year in career. I developed a replacement of production data feeder. It had a significant improvement, and I was sure it will make other people's life easier. But, suddenly, an accident happened. At that time, neither did I version control, nor backed up a source. The fact that first year professional doesn't know version control system should not be a good execuse, but I didn't know that.

My intention was to clean up test data like this:

$ rm -fr $PRJ_HOME/data

But, actual command was issued like this:

$ rm -fr $PRJ_HOME/ data

With just an extra space, I screw up the $PRJ_HOME. Fortunately, I had spare partition with enough disk space. I dumped /dev/sdaN to a single file. It was too big to open in vim, so chopped in pieces, and went through ugly binary format searching for my piece of code. After recovering all of my sources, I learned CVS and spent a week to learn to setup and manage CVS. Now it became Subversion.

There is no execuse, no good reason not to use VCS(Version Control System).
I can think of one. Temporary project only, which will create noisy commits on main VCS. However, even though the project is temporary, building on my own subversion tree locally and stuff into it before going to main VCS is not a bad idea.

Tuesday, September 23, 2008

Emacs, company-mode

I ran into a company-mode. This is a new completion style, and I like it. I recommend to watch its demo screencast.

company-expand-common function will take your TAB key away. I rebound it to [C-tab].
Very useful and good looking.

Monday, September 22, 2008

Chaining condition

I was reading a python code and discovered this useful feature.

if LOWER < x < UPPER


I have expressed this "if LOWER < x and x < UPPER" until I discovered chaining expression like this.
Perl and Ruby didn't accept chaining expression. C and C++ will not work because, (let's see the parsing)

1. C replaces expression with result of evaluation. Therefore, '1 < x < 10' expression will be '( (1 < x) < 10 )' and it will be evaluated to non-zero for any x.

2. C++ also replaces expression, but it knows boolean (true/false). Therefore, '1 < x < 10' expression will be either 'true < 10' or 'false < 10'. Since C++ is strong-typed language, this expression requires support of additional function like "boolean operator<(bool&, int&)". If it is supported, it should also support "boolean operator<(int&, bool&)". Now, int is not the only comparable. Beginning with float and double, signed/unsigned char, etc. It gets ugly very easily. Another approach will be replace true to (int)1 and false to (int)0 so that it can leverage existing framework. Anyway, end result is not related to the result of '1 < x < 10'

3. Due to this nature, supporting this expression in dynamic language isn't simple problem. For example of '( (1 < x) < 10)' case, inner expr can be any type based on 'what x is', the interpreter should be able to handle this fine.

Anyway, "1 < x < 10" is more elegant than " (1 < x) and (x < 10)".