About The Contest

The first ever Olympiad of Misguided Geeks contest at Worse Than Failure (or OMGWTF for short) is a new kind of programming contest. Readers are invited to be creative with devising a calculator with the craziest code they can write. One lucky and potentially insane winner will get either a brand new MacBook Pro or comparable Sony VAIO laptop.

Navigation

Advertisements

Entry #100297: math is hard

by Kevin Vigor
This entry uses the sample GTK interface almost unmodified. All the horror
(and it's considerable) lives in CalcFunc.cpp and friends, notably mymath.h.

I decided to implement a nice extensible typesafe C++ framework of
awesomeness. Sure, there are some ugly details [1] hidden in mymath.h and
CalcFunc.cpp, but the lucky fellow who inherits this code will surely never
have to touch these files. Instead they need only modify the astonishingly
simple and clear "rules.h", which allows the programmer to express math
operations with unprecedented simplicity. For instance, to implement the
expression "2 * 3 = 6" in the calculator, one might add the following lines
to rules.h:

IS_OPERATION(Times,*)

IS_NUMBER(Two,2)
IS_NUMBER(Three,3)
IS_NUMBER(Six,6)

IS(Two, Times, Three, Six)

The framework is easily extensible to handle new operators and numbers, and
is not bound by any pesky hard-coded "logic" regarding the behaviour of
"numbers", allowing future implementers in alternate dimensions to easily
redefine the above rule to make 2 * 3 = FileNotFound. Surely such flexibility
and power justify any means!

[1] and by ugly details I mean "code that uses RTTI to generate code that
uses macros that generate template specializations and then runs it through
the compiler at runtime". But I have said too much.

Download0 Comments