Tuesday, January 27, 2015

Program Like A Pro

Today I have decided to program like a pro and implement a "One function to do everything" class that acts as an entry point into any program I will ever make again. I call it, the 'Jerk API'. How does this work? Well, let me tell you.

First and foremost, let us look at the greatest operator overload to exist:

operator()

Why? Why is this awesome? I will continue after we look at the greatest return type ever created:

void*

"Whoa!" You may be saying. I agree, it is "Whoa" worthy. The best return type is now combined with the ultimate operator to exist:

void* operator()

Do you see where this is goin? If so, you should keep on reading. Because the ultimate function that should only ever be implemented in every API, SDK, software package, library, so on and so forth is as follows:

void* operator(...);

Yes, the ultimate function. It is the one ring of programming, the Filet Mignon, the Mt. Everest, just simply the best!

For those of you who are not familiar with this sort of epic programming, let us look more closed at the void* return type. Firstly, what is void? It means nothing, or no type. How awesome is that! We don't need to worry about what we return because it doesn't care. Making it a pointer allows us to actually return a pointer to something that somebody else has to worry about casting to the right object. We can return whatever we want, when we want, and however we choose so.

Now let us take a look at the best parameter argument in existence as well, the vararg (...). This allows us to accept any number of arguments without telling the mewling babe of a programmer who uses our library/API/etc. the types of the arguments or even a description. A true interface that only the pros can handle.

union AnyKindOfParam{  float _float;  int _int;  char _char;  unsigned long long _ulonglong;  unsigned char _uchar;  double _double;  void* _anything_you_want_dear; };   class Jerk{ public:  Jerk(){   }   ~Jerk(){   }   void* operator()(int theFirstParam, char* the_second_param[], float something_that_may_be_time){   return new Jerk();  }    void* operator()(double you_cant_do_this, unsigned long long yes_i_can){   char buff[1024];   return buff;  }   void* operator()(AnyKindOfParam chaos){   Jerk method;   return method(chaos._double, chaos._ulonglong);  }   void* operator()(...){   int* i = new int;   *i = 0;   return i;  } };  int main(int argc, char* argv[]){  Jerk random_methods;   Jerk* no_way = (Jerk*)random_methods(0, argv, 0.000000000000000001f);  void* why = random_methods(0.5, 100);   return *(int*)random_methods(7, 8, "what", 23443.0f, random_methods, "we just put in varargs that returns a null pointer and we casted it to an int pointer, then dereferenced, we better have some awesome documentation!", 0x96, (char)7); }With that being said, let me give a great example of all the fun we can have! I even included unions for this example (probably just as awesome of a argument as the varargs). (I would click it to see all of the glory)


Well, isn't that just great? I concur. Anyways, if you want to be a pro programmer, always remember, your classes need only one method.

void* operator()(...);

ENJOY!

No comments:

Post a Comment