Hi all,

The list being active again lately I've decided to start my own thread.

For now 9 months I've been working as a C++ developer for a software company (that's why my involvement as MusE developer has significantly dropped, after programming all day long I need to get away from my PC more than before). But the good point is that I'm learning how to produce healthier programs.

The little guy I'd like to talk about today is assert. At first I dislike to use it but I forced myself so my colleagues would think I'm a good programmer ;). Guess what? I can't ever program again without using assert, this little guy is fantastic! I use it all the time.

For instance assume you need to access pointer ptr and in the current context ptr should be pointing towards a non null instance otherwise it does make sense in the program and it could even crash it.

then you just put an assert before using the pointer. Like :

assert(ptr); //check that the pointer is non null
ptr->method(blabla); //access the methods

You can use assert for any properties you'd like to check in the course of the program, like :
assert(total_notes = added_notes - deleted_notes);

Basically I ALWAYS use assert when the program could crash (like in my example with ptr), this prevents myself from hours of debugging. Besides preventing more crashing it also just gives hint to a reviewer of the code on the assumptions that part of the code makes.

assert is part of the C++ standard so you don't need to include any header, you can use it right away.

Of course it takes resources to treat all these assert but a flag to the compiler makes it simply ignore them -DNDEBUG .

As far as I remember there is no use at all of assert in the code of MusE.
Hope my rumination would help at some point and thanks for reading it!

Cheers
Nil



Windows Live Messenger 2008 vient de sortir, entièrement personnalisable ! Téléchargez gratuitement Messenger 2008