Recently I heard from my friend, Egor Ermakov, about octopress and jekyll.
I really liked the idea of maintaining my blog with git and writing posts in any text editor i want so i decided to move my blog (which i didn’t use that much in the past years) to octopress.

I found the HPSTR theme port for octopress and tried to get it to work but i failed miserably. Therefore i decided to use jekyll instead. Jekyll worked just fine so that’s what it’s gonna be.

Importing posts from wordpress was a major PITA though. The importers are just dumping whatever you had in your blog. In my case it was a bunch of HTML.. so I had to manually (well, almost. ended up writing a simple perl script) update all my blog posts to make them look good again.

Anyway, hopefully this move will encourage me to start blogging again.

Cheers.

This was meant to be a post with lots of text. But as it was started over a year ago and never finished, I’m just posting a quick summary below:

C++ try/catch:

  • Cons/Pros - no finally… but also no real need for it as we will see later with RAII
  • Pros - can catch exceptions on different levels
  • Pros - can catch different exceptions at same level
    and revert to ALL if needed (catch(…) )
  • Cons - when catching ALL (…) the actual type of the exception is lost
  • Cons - no standard way to get a stacktrace (call-chain, backtrace)

C++ RAII:

  • Cons - a lot of extra code (same class code. template won’t help because the class is minimal anyway)
  • Cons - has a stupid, poor-describing name
  • Pros - flat structure, no hierarchy like with try/catch blocks
  • Pros - the exception safety code is in the library/functions, not on the user-code side

Java try/catch:

Can’t rely on finalize (java destructor). finalize() will be called before object is garbage collected but no one guarantees the exact time.

  • Cons - if you have more than one level of nested try/catch it will become an unreadable mess soon
  • Pros - has a finally block which allows for less code duplication
  • Pros - can catch different types of errors on different levels
  • Read this from Egor’s blog
  • Cons - exceptions are not chained if thrown from finally. finally always overrides everything (hidden exception)
  • Pros - stacktrace is builtin

D try/catch/finally:

  • Pros (compared to java) - return statements cannot be in finally
  • Pros - exception thrown first will be primary, the rest will be on the chain.
    including exceptions thrown from finally (no hiding of exceptions)
  • Other cons/pros are same as for Java

D scopes:

Scope doesn’t catch exceptions. It merely reacts to exceptions instead

  • Cons - moves exception handling onto the user of the functions/library. not the library itself as with raii
  • Pros - flat structure. no hierarchy of scopes
  • Pros - can define scopes for different types: exit (finally),
    failure (catch) and success (!catch)

Cheers.

Often in applications we develop we need random values.
We need random floats, we need random integers, sometimes we even need random items from a predefined list.

However, we also want the ability to easily swap between random values and a static value and vice versa.
But wouldn’t it be handy to treat random values and static values in the same way?

In my open source game engine, x2d, I faced this exact problem.
I wanted to give the game developer the ability to generate a random value of any type, anytime, anywhere in code as well as thru configuration (separate story).
The “randomness”, however, should be completely hidden from the end user - why would he need to bother with these low-level details?

The foundation for the randomness is kindly provided by Boost.Random.
That is because boost is already used in x2d anyways, so why not?
It should be easy enough to rewrite the template with any other implementation though.

After 3 months of work and 2 weeks of approval process, TapMania.org 0.4.0 is released to the AppStore!

This new release features support for all resolutions.. iPads, iPhones, iPods. Everything. Including all retina displays too.
Also it has support for hardware controls via iCade and iControlPad.. and of course GameCenter.

There are 14 songs to play out of the box including several original songs by my mate Vospi.

Check it out on itunes.

Cheers.

Really?! Part 4?

I have been looking at C++’s new standard a little.. there is a neat feature called Variadic templates in C++11.

I thought it would be a good candidate to rewrite my callbacks “lib” (now it sounds even funnier than before) in a much better, readable and preprocessor-independent way.
The end result is SO small that I actually embed it all in this post:

 1 template<typename Signature> class objc_callback;
 2 
 3 template<typename R, typename... Ts>
 4 class objc_callback<R(Ts...)>
 5 {
 6 public:
 7     typedef R (*func)(id, SEL, Ts...);
 8 
 9     objc_callback(SEL sel, id obj)
10     : sel_(sel)
11     , obj_(obj)
12     , fun_((func)[obj methodForSelector:sel])
13     {
14     }
15 
16     inline R operator ()(Ts... vs)
17     {
18         return fun_(obj_, sel_, vs...);
19     }
20 
21 private:
22     SEL sel_;
23     id obj_;
24     func fun_;
25 };

That’s all! Now you can do all the cool stuff:

 1 // use boost::function
 2 boost::function<void()> fn =
 3   objc_callback<void()>(@selector(simpleCallback), self);
 4 
 5 // or boost::signals
 6 boost::signal<void()> sig;
 7 sig.connect(
 8   objc_callback<void()>(@selector(signalCallback), self) );
 9 
10 // or use auto
11 auto upd =
12   objc_callback<void(float)>(@selector(update:), self);
13 
14 // just invoke the callbacks
15 fn();
16 upd(now() - last_update);
17 
18 // and signal
19 sig();

Cheers.