Thursday, November 18, 2010

2nd Semester ST Project

The main intention I had when setting up this blog was to share coding related stuff and other content that would be deemed boring and too tech-y for my other blog. The following post is about an accomplishment of mine that I'm very happy about, and this seems like the perfect place to share it.

Software Technology was my favourite subject during my (recently concluded) second semester at SLIIT. We were blessed with a wonderful lecturer and assistant lecturer and this, combined with my love for code, resulted in one of the most enjoyable learning experiences I've ever had in my life, comparable to that time during A/Ls that we learned about sub-atomic particles and nuclear energy, or the time in 8th grade which I started my first website on Yahoo! Geocities. (RIP)

So, at the end of the semester, we had to do an assignment based on the stuff we learned. It was done in C++, in Visual Studio, this neat little Windows Forms Application. But all that Microsoft goodness came at a price, and our simple application was 1.8 megabytes large. Another drawback was that it wasn't portable, meaning poor old me couldn't compile it in my GNU/Linux machine.

So after we finished our semester, and began our two month long vacation, I reimplemented the program in C. I simplified the problem that we were given (it would otherwise need an insane amount of coding, which I - a lone programmer without the incentive of assignment marks - would find difficult to do), but also switched the data structure we used to store the records from a linked list to a binary tree. The advantages of using a binary tree would be  that searching and inserting would be pretty fast. I also did use a post order deletion method to ensure that every record on the tree was deleted before exiting the program, so as to ensure that there were no memory leaks.

My original idea for the C program was to implement it in GTK+ (a cross platform widget toolkit, itself written in C), but I settled for the command line in the end because I had no experience with GTK (and very little experience with C itself) and the learning curve could've been too steep to handle. But I did what I could do, and I finished up with this, a working system that does what does. :) And in the process, I learned how to use malloc and got a new found sense of respect for the 'new' feature in C++ which makes memory allocation so much easier.

So this concludes this long, boring and pointless ramble about a piece of code that doesn't really do much at all. But it is released under the GNU general public licence, not because the free software foundation needs crapware like mine, but because it feels so right to give back to the community that has given us so much, including (but not limited to) the OS that I'm using (GNU), the kernel (Linux), the distro (Ubuntu), the web browser (Firefox) as well as the compiler (GCC) and the text editor (gedit) that I used to create the program. Long live software freedom! :)

1 comment: