In general, the worse case scenario when searching through a data set is when the datum being searched for doesn’t exist. In this case, the complete data storage needs to be searched before it’s possible to conclude that the datum cannot be found. If only there was a way to eliminate the need to perform unnecessary searches when we know the data won’t be found. Fortunately, there is a data structure that allows you to do just that. This data structure is knows as a “Bloom Filter”.
Continue reading “Bloom Filters”
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode? They will have you believe that Unicode requires you to use a WCHAR (wide) character type and that Unicode cannot be represented by a CHAR (narrow) character type. In fact, both of these statements are completely and utterly false. Microsoft has misled you in the most egregious way. Continue reading “When is Unicode not Unicode? When Microsoft gets involved!”
There seems to be some fundamental misunderstanding about the function prototype for the “main” function in C and C++. More specifically what type this function should return. I see so many programmers use void as the return type. People, I’m sorry to tell you but that’s just plain wrong! Continue reading “C / C++ main function prototypes”
When deciding whether to catch the exception, especially one thrown during construction, ask yourself a very simple question, if you do catch it can you still leave the class in a usable state? If the answer is yes, then by all means catch it, deal with it and allow construction to continue. If the answer is no then do not catch it! Why? Simple! if you catch and swallow it, how is the code that was attempting to construct your class to know that the class is unusable (or, at least only partially constructed)? Continue reading “C++ Catching exceptions in constructors”
You’re implementing a beautiful class. It’s just wonderful – the most perfect code you’ve ever written, except… for some reason it keeps crashing and you don’t know why. You’ve debugged the code and discovered it happens when your class goes out of scope and needs to throw an exception from the destructor. Tested in isolation, this works fine but integrated into the main code base it causes a crash. You know there are exception handlers that should deal with this and yet it still crashes. This doesn’t make sense. Why is the crashing? Continue reading “C++ Throwing exceptions from destructors”
In C++ all arguments are passed to functions by value. In other words, a copy of the value is taken and that is what the function has to work with. If you want to modify the original value you must either pass a pointer or reference to the original value you wish to modify. Of course, even the pointer or reference are still passed by value. Pointers and references are just another C++ type and when they are passed around you do so by value. Continue reading “C++ Passing by value vs. passing by reference”
C is Not C++!!!
A superset of nothing useful
I often hear those who really should know better giving the advice that before you learn to code in C++ you should first learn to code in C. At face value this would seem like reasonable advice; after all C++ is a superset of C and so by learning C you’ll be learning some of C++. Unfortunately, this advice overlooks some fundamental but very important differences between C and C++ that may very well damage the learning curve of the student. Continue reading “Should I learn C before learning C++? Answer – NO!”