Saturday, May 7, 2011

Toki Toki Syntax 8D!!! In C++.

This is some silly test I did when I was working on one of my projects...  I started playing around with how c++ class work and came up with a way to make it look sort-of like query language.  It looks something like this :D

/*
 *     Toki Toki Syntax is just a simple way to make c++ classes look
 *  like queries :D
 *
 *  So MAHAHAHAHAHAHAHAHAHAAAAA!!!! Couph Couph Couph 8D
 */
#include <iostream>

using namespace std;

class Test {
    public:
        int num;
       
        Test() : num(0) {}
       
        Test* hello() {
            cout << "Hello World" << endl;
            num++;
            return this;
        }
       
        Test* moon() {
            cout << "Hello Moon" << endl;
            num++;
            return this;
        }
       
        Test* sun() {
            cout << "Hello Sun" << endl;
            num++;
            return this;
        }
       
        Test* stars() {
            cout << "Hello Stars" << endl;
            num++;
            return this;
        }
       
        int getNum() {
            return num;
        }
};

int main() {
    cout << "Toki Toki Syntax: Simple way to make c++ look like a query language :D" << endl;
    Test t;
    // WTF Am I reading :D
    cout << "Toki Toki: " << t.hello()->moon()->sun()->stars()->getNum() << " times!!!" << endl;
   
    return 0;
}

This is just boredom on my part but I thought it was quite funny.  Who knows this design might be useful if not have laugh it helps with blood pressure 8D. What even funnier is the output from this example it looks like this.

Hello World
Hello Moon
Hello Sun
Hello Stars
Toki Toki: 4 times!!!

I thought it would be something like this though.

Toki Toki:
Hello World
Hello Moon
Hello Sun
Hello Stars
4 times!!!

Oh well figured out some strange about the way methods are launched in c++. Peace!!!

No comments:

Post a Comment