Comma Abuse

Found this old C++ source file in my scratch directory, apparently from last September. I don’t even remember¬†writing¬†this, but it’s written using my idioms. If I did write it, rest assured it was primarily for amusement purposes (abusement purposes?) only.

#include <iostream>
using namespace std;

int fibonacci(int x) {
    int a=0, b=1, temp;
    while(x?(--x,temp=a,a=b,b=temp+b):0);
    return a;
}

int main() {
    int i = 0;
    while(i<10&&(cout<<"fib("<<i<<")="<<fibonacci(i)<<'n',++i));
}

Yeah. That was terrible. Terrible awesome. But looking back, I’m realizing that some of the comma abuse is superfluous:

int fibonacci(int x){
    int a=0, b=1;
    while(x?(--x,a=((b=a+b)-a)):0);
    return a;
}

Don’t let anyone check in code like this, ever.

Leave a comment

Your email address will not be published. Required fields are marked *