Saturday 28 March 2009

A Poem on Metaprograms

Compiler, Compiler, Burning Bright,
In the template struct of night.
What immortal metaprogram,
Can frame thy fearful factorial.
In what template struct enum,
Inductive definition looms.
From the general to the specific,
The blessed base case blooms.

Example

The classic example of TML is the factorial function, i.e. fact(n)= if n is zero ret 1 else return n* factorial(n-1).

template <int N>
struct Factorial { enum { value = N * Factorial<N - 1>::value }; };

template <>
struct Factorial<0> { enum { value = 1 }; };

To print factorial values, do something like the following: int x = Factorial<4>::value; // == 24.

There are TWO parts to Template Metaprogramming, template definition and template instantiation.

Analysis

Compile-time versus execution-time tradeoff: longer to compiler, faster to execute!

Libraries

Boost MPL can be used in MSVC. Here's a tutorial.

TML is generally Turing-complete, any computation expressible by a computer program can be expressed by a template metaprogram.

Thursday 26 March 2009

ACE libraries

The ACE libraries (ADAPTIVE communication environment) comprise an OO framework that implements a bunch of concurrent design patterns. Read this article on wrapper facades. They are used in ACE.

Should you wish to use POSIX threads in Windows you can. The pthreads-win32 project DLL does just that.

Monday 23 March 2009

deque better than vector?

MSVC is more STL-friendly now. It can help us resolve questions like, is deque better than vector?

C++ strongman Herb Sutter helps us find the answer.

Ever wonder how associative containers like maps are implemented? The standard implementation is to use a self-balancing binary search tree, such as Sedgewick's red-black trees. Red-black trees are trees where each node is either red or black and the root node is black (in most definitions). The tree has the property of being "roughly balanced" - formerly defined this says that

longest path(RL) <= 2*shortest_path(RL)

(<= reads "less than or equal to" or "cannot exceed", RL == root_to_leaf). in that tree.

Tree traversals are important in computer science (preorder, inorder, postorder). These should be known forwards, backwards and back-to-front.

Saturday 21 March 2009

Swedish Financial Supervisory Authority grants banking license to Online Game

grant_banking_license( swedishSupervisoryAuthority, entropiaUniverse ).
developer( entropiaUniverse, mindark ).
currency( entropiaUniverse, projectEntropiaDollars ).

Virtual banks need to be regulated in case they become a vehicle for money laundering. Some countries (e.g. China) are also looking at virtual worlds as a potential source of tax revenues.

The Virtual Worlds conference (now Engage! Expo) is a forum for discussing innovations in virtual worlds, such as entropia universe.

Customization in Vista

Hmm. ..customizing Vista requires rewiring your brain if you have been used to WinXP for a while.

If you want to change the desktop background you need to:

Click Start, click on control panel (on the transparent section RHS) then find Personalization. Here you can change: Desktop Background, Screen Saver, Theme. Is it possible to take customization one step further and create a new Windows theme? A commercial product called Vista Style Builder has been written by Andreas Verhoeven, a programmer in Rotterdam. Andreas has done good work cracking the internal format of .msstyles files. Various styles can be found at skinbase.org.

Thursday 19 March 2009

Monday 9 March 2009

Business of Software 2009

Joel Spolsky: "The business people have no hope of learning the technology, it's just too much. The hill is too steep to climb that hill. But that means for a software company to succeed the people at the top, I believe, have to be software people, they really have to be the technologists, but they also have to have business skills, so they're just going to have to learn them". More here.