Yes this is a 'tease/joke' thread. I was reading the Santa Hack thread and saw Bamccaig remark a time or two that he hated globals. Since he knows I like him and has offered advice and help when he didn't have to, I couldn't resist this gag thread. Yes I know this isn't really a competition and will have no winner, but figured Bamccaig would at least find some humor in it (or not). Matthew is free to lock it if he feels so inclined of course.
-----------------------------------------------
Introducing the POB (P*ss Off Bamccaig) Global Competition Thread
Rules are simple, don't have to have working code. Just paste code that has globals declared.
I'll start:
#include <iostream> bool PISS_OFF_BAMCCAIG = 1; int main() { return 0; }
-----------------------------------------------
Sorry bamccaig, couldn't resist.
bool missingParen=true; #define IAMNOTMISSING } int main() { if(missingParen) { IAMNOTMISSING return 0; }
int x = getX(); if(somethingIsTrue(x)){ doSomethingAboutIt(x); } for(int i=0; i<getLength(); i++){ doSomethingForEach(getItem(i)); } Object foo = getFoo(); if(somethingElseEntirelyIsTrue(foo)){ doSomethingAboutThat(foo); }else{ doSomethingAboutThat(foo + 5); doSomethingDifferently(foo); }
doSomething ( 5 );
[bamccaig@sephiroth ~]$ cat your_file
This was a triumph.
I'm making a note here. HUGE SUCCESS.[bamccaig@sephiroth ~]$
People that drive too fast through intersections and have to skip across 3 lanes to make a corner in their huge-ass PoS pickup trucks, people that cut corners in the road and cut you off, and people that drive down the middle of the fucking road instead of just wearing down the snow on both sides...
int temp1=0; float temp2=3; double temp3_f=2;
All stolen from content he wrote. I just pirated his pet peeves.
Some of those names sounds like something Microsoft would do for the Win32 API.
#include <stdio.h> char drink[] = "Pepsi"; char attribute[] = "Nectar of the Godz"; int zero = 0; int main(void) { printf("%s is the %s\n",drink,attribute); return zero; }
Obviously, the language of choice for this is PHP.
<?php for ($i = 0; $i < mt_rand(); ++$) { $varname = sprintf("variable%d", $i); $$varname = md5(mt_rand() . "and a bottle of rum"); define($varname, $i); } function add($a, $b) { $varname_a = 'variable' . $a; $varname_b = 'variable' . $b; global $$varname_a, $$varname_b, $$$varname_a, $$$varname_b; return $$$varname_a + $$$varname_b; }
Might even actually work for some cases. And it's secure, because it uses a salt
Obviously, the language of choice for this is PHP.
Is there a really important reason why PHP uses all those dollar signs?
Is there a really important reason why PHP uses all those dollar signs?
It's the syntax. $x is a variable; $$x is a variable variable. Normally you don't use these, but the feature is there. What it does is evaluate the original (single-dollared) variable as a string, and use it as a variable name. So if you have this:
$a = 'foobar'; $x = 'a'; print($$x);
...it will print "foobar" - $x is 'a', so $$x resolves to $a.
Variable variables are loosely comparable to pointers in C, only that you use strings to point to variables instead of binary pointer values (and that memory management is taken care of by the language).
The C++ equivalent of the above would be:
string a = "foobar"; string* x = &a; cout << *x;
Only that PHP uses strings to reference variables, so you can construct variable references by name, as strings.
Thanks for the explanation Tobias, I'd have to say that language is mind numbingly ugly!
Only if you make it so. PHP has enormous potential for writing hideous code, but that's no excuse for actually doing it, just like owning a knife is not an excuse for stabbing people. (Cue "guns kill people" debate)
klaxxzgamemakre ftw
just like owning a knife is not an excuse for stabbing people.
WHAT???!?!!! You mean I've been doing it wrong this entire time??
WHAT???!?!!! You mean I've been doing it wrong this entire time??
No, certainly not. You just need a better excuse than "I own a knife". For example, you might say, "He looked at me funny", or "I needed something he has, but he wouldn't give it to me", or simply "God told me to do it".
{"name":"tumblr_llkdcdAMCT1qd6bglo1_500.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/4\/34acc490fb6ff9c7137313e71535dc56.jpg","w":366,"h":601,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/4\/34acc490fb6ff9c7137313e71535dc56"}
stabbity stabbity stab is its own excuse.
#define RET int #define NAME main() #define GAME {dosomething() #define STARTAWESOMEGAME RET NAME GAME #define ENDAWESOMEGAME return 0;} #define AWESOMEGAME 0; struct GAMESTATE {int a;bool b;} AWESOME_GAMESTATE; class UnrequiredSingleton; void dosomething(); STARTAWESOMEGAME; ENDAWESOMEGAME
This made me write a game using only globals.
I think it would have been much better if you used more gotos.
I think it would have been much better if you used more gotos.
I edited it. Better?
Blocks are evil.
if (true) { foo(); bar(); } else { bar(); foo(); }
The following is more readable:
if (false) goto a; foo(); bar(); goto b; a: bar(); foo(); b:
The following is more readable:
Amazingly so, I edited it again. Someone reading my original version would have had no idea what's going on - now with the labels it all is much clearer.
Yeah, the labels are like self documenting code. There's really no need for comments when you code properly like that.
And it removes the need for ugly indentation. Everything lines up very nicely.
{"name":"2010-12-02-Mystery-of-Ghost-Beach-3.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/1\/d1fc89340ec06b39e84f2243fe0ed97a.png","w":982,"h":399,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/1\/d1fc89340ec06b39e84f2243fe0ed97a"}
Dario ff: Nice Zsasz picture.
Arthur Kalliokoski: heh that made me laugh a little .
Matthew: I was worried you would be mad at this and consider it trolling or breaking the forums rules .
I was too lazy to do any better..
It looks like a plausible entry to the obfuscated C contest. OTOH, I'm drunk again.
Hear, hear!
Hear, hear!
Are you appreciating the contest or drunkenness?
Amazingly so, I edited it again
I think you should rename the labels to be in German.
I think you should rename the labels to be in German.
Nah. Variable names (and comments) should be in English. Always. So that's where I draw the line. Even in a joke thread.
Of course in PHP even the compiler itself will tell you things like Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM for something as simple as having a colon in the wrong place so I guess it doesn't matter there
There are just so many Good Ideas and Bad Ideas here in this thread right now.
Mabmab's actually true celebrity. Surprising to know.
Celebrity only on A.cc .