Archive for October, 2012

30
Oct
12

Auto

I don’t think this is widely known but auto was already a keyword in C++ and also C. Prior to it’s removal in C++09 it was used as a storage duration indicator. What this means is that it tells the compiler how long the storage for the variable needs to last for. The auto keyword is the default and means that the storage is available until the end of the block in which the variable is created. The fact that this is the default behaviour for C++ and it’s infrequent use lead to it being removed from the standard. As Bjarne Stroustrup writes

Several committee members trawled through millions of lines of code finding only a handful of uses — and most of those were in test suites or appeared to be bugs

So onto the new auto. Continue reading ‘Auto’

26
Oct
12

Mutable and Data Caching

This blog post is going to be about the c++ keyword mutable, it is also going to go into using mutable for data caching. To motivate this I am going to give an example from python. If I have a class with a property which is expensive to compute I want to cache it and only recalculate it when necessary. Continue reading ‘Mutable and Data Caching’

18
Oct
12

FizzBuzz

FizzBuzz is variously; a drinking game, a maths game, a way of learning numbers in a foreign language and more importantly (for this blog) a programming kata. The principle of FizzBuzz is a counting and substitution game you count to a limit and replace some numbers with words. In the classic example you replace any number which is divisible by 3 with Fizz and any number divisible by 5 with Buzz, and any number which is divisible by both with FizzBuzz. Continue reading ‘FizzBuzz’