Tuesday, December 18, 2007

Working code is worth its weight in gold.

Write your tests.
Write your code.
Update your diagrams.
Done.

See the mention of copious reams of documentation here?
No?
That's because there really is no need to write them.
Why?
Because there is no point in spending hours of programmer time trying to write a document that will never be read.

Class diagrams are useful to quickly illustrate the architecture to newcomers but that's all the additional documentation you should need to explain how things work.

If your code is written well - i.e. well laid out classes with suitably short, well-named functions that do just one thing - the tests and the working code will be sufficient to easily explain what it does and how it does it.

It should be like looking up the word "dictionary" in a dictionary. It's functional - in giving the definition - and it also explains what it is.

Monday, December 10, 2007

How to find a career you love

I while back I posted that to be successful you should be in a job you love.

And it's good to see that Steven Covey (of The 7 Habits of Highly Effective People fame) agrees with me!

He says:
Discovering your dream job involves asking yourself these basic questions over time :
(1) What do you really love to do?
(2) What do you do well?
(3) What should you do so that you tap into your true voice?
(4) What does the world need?


So far, his blog is definitely worth a read.

Tuesday, December 04, 2007

C++ Programming Tips

Inserting into a sorted std::vector




MyVec.push_back(MyInt)
if (MyVec.size() > 1)
{
std::inplace_merge(
MyVec.begin(),
MyVec.begin() + (MyVec.size() - 2),
MyVec.End());
}


This won't be the fastest way of performing an insert, but it will probably be the smallest amount of code. For the fastest way, look at finding with a binary search, then inserting.

Disclaimer: If you are going to be inserting many things into the middle of a vector, you probably shouldn't be using a vector. A list would be more suited.

Constructor variable initialisation order


This is a subtle C++ism that I forgot about and caught me out today.

When initialising items in a constructor's initialisation list, the order of initialisation is dependant on the order the variables appear in the class definition, not the initialisation list.

An example will help:

class MyClass
{
MyClass();

int a;
int b;
int c;
};

MyClass::MyClass() :
b(0), c(0), a(0)
{
}

In the above example, a, will be initialised first followed by b, then c.