Tuesday, May 17, 2011

Shorty's Shebeen and #breaktherules

Last weekend was a busy one. So busy that what should normally be two blog posts is going to have to be one. Last Friday I went to the Franschhoek Literary Festival, which was awesome. I got to see and hear a lot of my favourite South African authors as well as plenty that I hadn't read yet but seemed very cool. Unfortunately given the nature of time and space I couldn't go to all the events but the ones I did get to see were great. As brief example some of the people talking that I saw were, Lauren Buekes, Sarah Lotz, Zakes Mda, Justice Malala, Antony Altbeke, Karabo Kgoleng, Imraan Coovadia, Shubnum Khan, Sifiso Mzobe, Mike Nicol and many others.

I also used the event to sort of go public-ish with Shorty's Shebeen, the South African Short Stories site I've been working on with Jeff Webster. So I guess you guys should all check Shorty's out. The idea (as I have written to so many authors to explain) is:
  • Give RSA writers the thing that writers crave most, an audience.
  • Encourage what we see as a potentially massively creative period in South African literature.
  • Maybe get a publishing deal for some of the stories on the site, a Shorty's Shebeen compendium or something, which could act as a spring board for unpublished writers.
  • Get some awesome stories.
The awesome design was done by Jeff and I did the mildly OK backend. If there are any literary orient Techies out there that would like to contribute you can check out the code on Github. But it would be way cooler if you put up some stories and read a few that are already up. You can get a whole bunch more info in the about section of the site, so I won't waste your time repeating it here.

The other thing that happened over the weekend was #breaktherules. #breaktherules was an event organised by @jbrownbridge ,@marcog with a little input and help from yours truly. The idea of the event was to connect computer science students with local startups to do internships. The principle goal being to give students a chance to get some real world exposure in really interesting companies and to give the startups some exposure to up and coming developers. The event was one hell of a success, everyone had a great time and a lot of eyes were opened. Most of the students had no idea there were so many cool things going on in Cape Town, and honestly I don't think the companies knew there were so many good developers in training.

As a highlight Quirk used the event to launch their QuirkLabs incubator, which promises to be really interesting and is the cumulation of a lot of hard work on their part. 

So thats the weekend highlights.


Monday, May 2, 2011

All there is to know about Osama Bin Laden


All There Is To Know About Adolph Eichmann Osama Bin Laden

EYES                    Medium
HAIR                    Medium
WEIGHT                  Medium
HEIGHT                  Medium
DISTINGUISHING FEATURES None
NUMBER OF FINGERS       Ten
NUMBER OF TOES          Ten
INTELLIGENCE            Medium

What did you expect?
Talons?
Oversize Incisors?
Green saliva?
Madness?

(Poem by Leonard Cohen)

Lest we forget.

Watching the world wake up


I'm sitting here at my little metal cafĂ© table in my flat, looking out my window. It's 7:37 and I have been sitting here sipping tea for about an hour just watching the world wake up and unfold. I had forgotten how peaceful the early morning is. It's been so long since I saw one. It's a time of day I have always loved, even if it is one I am rarely awake for. I have always enjoyed the slow metamorphosis that unfolds. 

It starts as the dead of night, quiet. All of the revelry has been sedated, all of the shop lights are off and the clubs are closed. The streets are completely empty. The only movement is the occasional flicker of the yellow street lights. The first signs of morning are dually the faint glow on the horizon signalling the slow advance of the sun and the sluggish movements of the first delivery trucks doing their pre-dawn rounds. The slow meander of the trucks seems to made even slower in the pre-dawn haze, as if the light itself is viscous and the minimal traffic has to push through it, as if through the ether. 

The first taxi's signal the start of the human activity. One taxi, maybe two go by, still sedately. There aren't any people on the roads yet, so there are no shouts, no aggressive competition. With no other cars to avoid or out manoeuvre even the taxi's seem peaceful. The few passengers that disembark move quickly out of sight, into their stores to set things up for the coming days.

It's at this point where the light is becoming strong enough to over power the street lights, but they will stay on for another few minutes. This leaves an image of a world on the cusp of transition. The lights appear as the last guardians of the peace of night from the impending chaos of the day. 

I can see the first cars now, proper cars, private vehicles. The side walks are still empty though, save for the occasional ex-taxi passenger. It's going to be a cloudy day, the clouds have blocked the glare of the sunrise leaving the landscape tinged with a blue-grey hue. I think it'll be a calm day. The city seems to have absorbed the weather, settling into its rhythm. But it will slowly speed up, just like the clouds will slowly burn off.

I hear my alarm clock go off, it is time for me to wake up. It is time for the day to begin. 

Monday, April 25, 2011

The Jolly Exclusive Whisky Society Website

The gentlemen of the The Jolly Exclusive Whisky Society have commissioned a website. It can be seen here at http://www.whiskysociety.co.za

Friday, March 18, 2011

dumb_ptr, a smart_ptr conversion class in C++ (only for programmers)

Everyone reading this who is not a programmer, 
STOP READING NOW!!
Seriously this post will make no sense to you, do something you will enjoy like going swimming. For those who are programmers this may interest you.

I have been using a lot of different boost smart pointers lately, as well as normal pointers. I have noticed that as you develop you tend to realise that you have to switch pointer types and memory management mechanism because you overlooks some circular dependency or some othe small annoying thing. When this happens and you change your pointer type you have to either go and change a whole bunch of you method signatures to take the new pointer type, or at each call site you have to convert between pointer types. You also have a problem if you have the same function but want it to take multiple pointer types.

I was wondering if there already existed a generic way to deal with this, i.e. write methods that are agnostic of the pointer type you pass to it?
The obvious answer is write all your simple methods (methods that don't manipulate ownership of the pointer and don't return it to anything) to take raw pointers (T*) or references (T&) as parameters. But this still means that you have to write code at each call site to extract the raw pointer, and if you change the type of smart pointers you are using then you have to change code at every call site. That's a hassle, I like to avoid hassles.

You could also overload your methods for different pointer types, but thats a huge waste of time and makes the more code difficult to read. Another way is to use a template style solution with some type inference, but this would cause some significant bloat in the compiled code and is likely to start throwing strange unsolvable template errors.

My idea was to write a new class any_ptr<T> with conversion constructors from all the major pointer types, say, T*, shared_ptr<T>, auto_ptr<T>, scoped_ptr<T>  and weak_ptr<T>and then have it expose the * and -> operators. In this way it could be used in any function that does not return the pointer outside of the function and could be called with any combination of common pointer types.

The class ended up being really simple, here it is:

template<typename T>
class dumb_ptr {
 public:
  dumb_ptr(const dumb_ptr<T> & dm_ptr) : raw_ptr(dm_ptr.raw_ptr) { }  
  dumb_ptr(T* raw_ptr) : raw_ptr(raw_ptr) { }  
  dumb_ptr(const boost::shared_ptr<T> & sh_ptr) : raw_ptr(sh_ptr.get()) { }  
  dumb_ptr(const boost::weak_ptr<T> & wk_ptr) : raw_ptr(wk_ptr.lock().get()) { }  
  dumb_ptr(const boost::scoped_ptr<T> & sc_ptr) : raw_ptr(sc_ptr.get()) { }  
  dumb_ptr(const std::auto_ptr<T> & au_ptr) : raw_ptr(au_ptr.get()) { }  
  T& operator*() { return *raw_ptr; }
  T * operator->() { return raw_ptr; }
  operator T*() { return raw_ptr; }
 private:
  dumb_ptr() { } 
  dumb_ptr<T> operator=(const dumb_ptr<T> & x) { }
  T* raw_ptr;
};

It can convert from the common smart pointers automatically and can be treated as a raw T* pointer, further it can be converted automatically to a T*. The default constructor and the assignment operator (=) have been hidden to deter people from using it for anything other than function arguments. When used as a function argument the following can be done.

void some_fn(dumb_ptr<A> ptr) {
  B = ptr->b;
  A a = *ptr;
  A* raw = ptr;
  ptr==raw;
  ptr+1;
}

Which is pretty much everything you would want to do with a pointer. It has the exact same semantics as a raw pointer T*. But now it can be used with any smart pointer as the parameter without having to repeat the conversion code (.get,.lock) at each call site. Also if you change your smart pointers you don't have to go around fixing each call site.

So I think this is a pretty neat solution. The idea and most of the content for this post come from a Stackoverflow question I asked, where I presented this idea and asked if anyone saw any major problems with it. The answering parties didn't think much of it, but I think they missed the point (No offence intended) . The point is that it should be less of a hassle to program, even in languages like C++.

Well that's it, I hope someone finds it useful