Archive for February 2011
28
Don’t reassign that cat’s gender! Consts in C++
No comments · Posted by James Ravenscroft in Tutorials
Its been a while since I worked with C++ (a few months at least) and even when I did use the language, I was looking at it from a Java developer's perspective rather than trying to understand what the language is all about. My Computer Science lectures on C++ and different programming paradigms has really opened my eyes as to how C++ should be used (separately and in different ways to Java).
The first lesson I've been learning is about 'Constness', that is, declaring things that don't change constant in your programs to ensure that the compiler tells you when you try to change them and thus, iron out silly bugs. An example of this is as follows:
You may define a cat class in your program. Logically, you would never wish to change the gender of a cat, So the cat's gender could be declared a constant:
cat.h:
class Cat{
...
private:
const bool isMale;
...
}
cat.cpp:
Cat::Cat(bool male) : isMale(male){
...
}
Now, you want to see if two cats have the same gender, but you put in a typo:
Cat::canBreed(Cat otherCat){
if(this->isMale = otherCat->getIsMale()){
return false;
}
}

Sad kitteh is sad: "Why you trying to reassign mah gender?"
You wanted to compare the gender of the two cats, but instead, you are trying to assign the gender of Cat A to the gender of Cat B. Luckily, the C++ compiler will help you out here.
Since you declared isMale as a const, this typo will be singled out as a mistake and the compiler will tell you that you are trying to do something wrong: this is a good thing!
So what about mutables? These are a slightly more difficult concept to grasp, but essentially they are only to be used when the object does not logically change, but must change in practice. For example: For loading an image just in time, rather than keeping it in memory (the image 'object' remains the same, but the image data buffer itself changes at the last minute). I stumbled across this article on mutables, and I couldn't have put it better myself.
So that's all for the first in my series of exciting C++ adventures, No cats were psychologically or physically damaged in the making of this article.
14
Android and ADM
No comments · Posted by James Ravenscroft in Development Work, Fun and Play, University
The last few weeks have been incredibly busy with a huge number of activities going on, including revision for exams and Work Week. Now that I finally have some free time, I decided to have a quick look into the development of Android applications using my Scroll. I noticed that there is currently a lack of JDownloader-esque apps for Android and when I'm up on the uni campus with only my Android, I'd like to be able to download stuff on masse using the University's stupidly fast connection. For these reasons, ADM was born
ADM (pronounced 'Adam') or Android Download Manager, is going to be a fully fledged download core system complete with link parser/checker functionality and a file hosting crawler that searches places like Rapidshare and Hotfile for relevant downloads that may interest the user. I may also build in un-rar functionality too. I've started working on it and have some early designs and stuff, but nothing too exciting.
I'll post more info when I have something exciting to show you. Unfortunately, my WordPress Script seems to hate me and is not letting me upload images or anything at the moment!
adm · android · Development Work · download · downloading · java · jdownloader · manager · xml
4
Coding Week
No comments · Posted by James Ravenscroft in Development Work, Industriousness, University
This week has been one of the most intense weeks of my University career so far! I've had so very much to do in so little time and as I write, I'm basically falling asleep.
As part of our degree this year, we had to write a small Java application for organising car shares in and around the university town using a PostgreSQL database. We've been maintaining the code in Subversion and running lots of JUnit tests on it to make sure everything works nicely. As part of the project, I've learned a lot of stuff, especially on Postgres databases and Java, but also on how to work with and manage a team during a large IT project.
I was dreading this week at first, but it's actually been really cool and I've made some really good new friends and learned a lot of new things. If working for IBM is anything like this week, I'm sure it'll be a hoot!
dev · ibm · java · junit · postgres · programming · sql · subversion · svn · week · work
