POB Global Competition Thread [Joke Thread NOT SERIOUS!]
Specter Phoenix

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.

Onewing
bool missingParen=true;
#define IAMNOTMISSING  }
int main() {

  if(missingParen) {
  IAMNOTMISSING

  return 0;
}

Dario ff
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 );

Quote:

[bamccaig@sephiroth ~]$ cat your_file
This was a triumph.
I'm making a note here. HUGE SUCCESS.[bamccaig@sephiroth ~]$

Quote:

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. 8-)

jmasterx
#SelectExpand
1#include <sstream> 2#include <vector> 3#include <map> 4#define whilst while 5#define end_of_whilst } 6bool _donethecode = 0; 7int cmpvle = (int)_donethecode; 8int* num1 = new int(43); 9std::vector<std::map<bool,std::string> > m_hlwld; 10int main() 11{ 12 if (cmpvle) 13 whilst ( cmpvle ) 14 { 15 cmpvle++; 16 end_of_whilst; 17 18 return !cmpvle / *num1; 19}

Dario ff

Some of those names sounds like something Microsoft would do for the Win32 API. :P

Arthur Kalliokoski
#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;
}

Dizzy Egg

#SelectExpand
1 2const int BE_POSITIVE = 1; 3const int BE_NEGATIVE = 2; 4const int GOOD_NEWS = 1; 5const int BAD_NEWS = 2; 6 7 8int main() 9{ 10 int Specter_Phoenix_Response = GetSpecterReply(GOOD_NEWS); 11} 12 13int GetSpecterReply(int News) 14{ 15 if(News == BAD_NEWS){ 16 return(BE_NEGATIVE); 17 } 18 else{ 19 return(BE_NEGATIVE); 20 } 21}

Tobias Dammers

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 :P

verthex

Obviously, the language of choice for this is PHP.

Is there a really important reason why PHP uses all those dollar signs?

Tobias Dammers
verthex said:

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.

verthex

Thanks for the explanation Tobias, I'd have to say that language is mind numbingly ugly!

Tobias Dammers

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)

van_houtte

klaxxzgamemakre ftw

Thomas Fjellstrom

just like owning a knife is not an excuse for stabbing people.

WHAT???!?!!! You mean I've been doing it wrong this entire time??

Tobias Dammers

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".

Dario ff

{"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"}tumblr_llkdcdAMCT1qd6bglo1_500.jpg

Arthur Kalliokoski

stabbity stabbity stab is its own excuse.

Neil Walker
#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

weapon_S
#SelectExpand
1#define SINGLETON(x,y,z) class Singleton##x##y { \ 2 static #x _instance;\ 3 Singleton##x##y();\ 4 public:\ 5 static #x& contents(){\ 6 return _instance;\ 7 }\ 8} #y;\ 9#x Singleton##x##y::_instance = #z; 10 11#define EVER ;; 12 13SINGLETON(int, a, 21) 14SINGLETON(char, b, 21) 15 16int main(void){ 17 for(int age =0; age < a.contents(); age++) 18 do_alcohol(false)EVER 19 for(EVER) 20 dont_use_globals()EVER 21 return b.contents(); 22}

Elias

This made me write a game using only globals.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_primitives.h> 3#include <allegro5/allegro_color.h> 4#include <math.h> 5 6ALLEGRO_DISPLAY *d; 7ALLEGRO_EVENT_QUEUE *q; 8ALLEGRO_EVENT e; 9ALLEGRO_TIMER *t; 10ALLEGRO_COLOR c; 11bool k[ALLEGRO_KEY_MAX]; 12int w = 30; 13int h = 38; 14int s = 16; 15int a, b, g; 16double p = ALLEGRO_PI, f; 17bool r; 18int x, y, px, py, kx, ky, sx, sy; 19int gx[4], gy[4], dx[4], dy[4]; 20char n[] = 21" " 22" " 23" " 24" " 25" ############################ " 26" #............##............# " 27" #.####.#####.##.#####.####.# " 28" #.# #.# #.##.# #.# #.# " 29" #.####.#####.##.#####.####.# " 30" #..........................# " 31" #.####.##.########.##.####.# " 32" #.####.##.########.##.####.# " 33" #......##....##....##......# " 34" ######.##### ## #####.###### " 35" #.##### ## #####.# " 36" #.## [] ##.# " 37" #.## ### ### ##.# " 38" ######.## #~~~~~~# ##.###### " 39" . #[][][]# . " 40" ######.## #~~~~~~# ##.###### " 41" #.## ######## ##.# " 42" #.## ##.# " 43" #.## ######## ##.# " 44" ######.## ######## ##.###### " 45" #............##............# " 46" #.####.#####.##.#####.####.# " 47" #.####.#####.##.#####.####.# " 48" #...##.......().......##...# " 49" ###.##.##.########.##.##.### " 50" ###.##.##.########.##.##.### " 51" #......##....##....##......# " 52" #.##########.##.##########.# " 53" #.##########.##.##########.# " 54" #..........................# " 55" ############################ " 56" " 57" " 58" "; 59char *m; 60#define P(x) (((x) - 1) * s) 61#define Q(x) (1 + (x) / s) 62#define M(x, y) m[(y) * w + (x)] 63 64int main() { 65 srand(time(NULL)); 66 al_init(); 67 al_install_keyboard(); 68 al_init_primitives_addon(); 69 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 70 al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST); 71 d = al_create_display((w - 2) * s, (h - 2) * s); 72 al_set_window_title(d, "Bambam and the Globals"); 73 q = al_create_event_queue(); 74 t = al_create_timer(1.0 / 60); 75 al_register_event_source(q, al_get_keyboard_event_source()); 76 al_register_event_source(q, al_get_timer_event_source(t)); 77 al_register_event_source(q, al_get_display_event_source(d)); 78 al_start_timer(t); 79 m = malloc(strlen(n) + 1); 80 restart: 81 strcpy(m, n); 82 b = 0; 83 y = 1; 84 starty: 85 x = 1; 86 startx: 87 if (M(x, y) != '(') goto noparenthesis; 88 px = P(x) + s; 89 py = P(y) + s / 2; 90 noparenthesis: 91 if (M(x, y) != '[') goto nobracket; 92 gx[b] = P(x) + s; 93 gy[b] = P(y) + s / 2; 94 if (b == 0) goto notfirst; 95 sx = gx[0]; 96 sy = gy[0]; 97 notfirst: 98 b++; 99 nobracket: 100 x++; 101 if (x < w - 1) goto startx; 102 y++; 103 if (y < h - 1) goto starty; 104 mainloop: 105 if (!r || !al_is_event_queue_empty(q)) goto dontdraw; 106 al_clear_to_color(al_color_name("black")); 107 b = 7; 108 loopdrawhighlight: 109 c = al_color_name("blue"); 110 if (b == 1) c = al_color_name("wheat"); 111 y = 1; 112 loopdrawy: 113 x = 1; 114 loopdrawx: 115 if (M(x, y) != '.') goto nodot; 116 al_draw_filled_rectangle( 117 P(x) + s * 0.4, 118 P(y) + s * 0.4, 119 P(x) + s * 0.6, 120 P(y) + s * 0.6, 121 al_color_name("peachpuff")); 122 nodot: 123 if (M(x, y) != '#') goto nohash; 124 a = 1 * (M(x + 0, y - 1) == '#') + 125 2 * (M(x + 1, y - 1) == '#') + 126 4 * (M(x + 1, y + 0) == '#') + 127 8 * (M(x + 1, y + 1) == '#') + 128 16 * (M(x + 0, y + 1) == '#') + 129 32 * (M(x - 1, y + 1) == '#') + 130 64 * (M(x - 1, y + 0) == '#') + 131 128 * (M(x - 1, y - 1) == '#'); 132 133 if (a == 64) 134 al_draw_line(P(x), P(y) + s / 2, P(x) + s, 135 P(y) + s / 2, c, b); 136 else if (a == 4) 137 al_draw_line(P(x), P(y) + s / 2, P(x) + s, 138 P(y) + s / 2, c, b); 139 140 141 else if ((a & 85) == 5) 142 al_draw_arc(P(x) + s, P(y), 143 s / 2, p / 2, p / 2, c, b); 144 else if ((a & 85) == 20) 145 al_draw_arc(P(x) + s, P(y) + s, 146 s / 2, p, p / 2, c, b); 147 else if ((a & 85) == 65) 148 al_draw_arc(P(x), P(y), 149 s / 2, 0, p / 2, c, b); 150 else if ((a & 85) == 80) 151 al_draw_arc(P(x), P(y) + s, 152 s / 2, p * 1.5, p / 2, c, b); 153 154 else if ((a & 7) == 5) 155 al_draw_arc(P(x) + s, P(y), 156 s / 2, p / 2, p / 2, c, b); 157 else if ((a & 28) == 20) 158 al_draw_arc(P(x) + s, P(y) + s, 159 s / 2, p, p / 2, c, b); 160 else if ((a & 193) == 65) 161 al_draw_arc(P(x), P(y), 162 s / 2, 0, p / 2, c, b); 163 else if ((a & 112) == 80) 164 al_draw_arc(P(x), P(y) + s, 165 s / 2, p * 1.5, p / 2, c, b); 166 167 else if ((a & 17) == 17) 168 al_draw_line(P(x) + s / 2, P(y), P(x) + s / 2, 169 P(y) + s, c, b); 170 171 else if ((a & 68) == 68) 172 al_draw_line(P(x), P(y) + s / 2, P(x) + s, 173 P(y) + s / 2, c, b); 174 nohash: 175 x++; 176 if (x < w - 1) goto loopdrawx; 177 y++; 178 if (y < h - 1) goto loopdrawy; 179 b -= 6; 180 if (b > 0) goto loopdrawhighlight; 181 182 b = 0; 183 looptwice: 184 al_draw_filled_pieslice(px + b * (w - 2) * s, py, s, 185 f + p * 0.25 * fabs(sin(2 * p * (g % 60) / 60.0)), 186 p * 2 - p * 0.5 * fabs(sin(2 * p * (g % 60) / 60.0)), 187 al_color_name("yellow")); 188 b++; 189 if (b < 2) goto looptwice; 190 b = 0; 191 loopdrawghosts: 192 193 if (b == 0) c = al_color_name("red"); 194 if (b == 1) c = al_color_name("cyan"); 195 if (b == 2) c = al_color_name("pink"); 196 if (b == 3) c = al_color_name("orange"); 197 x = gx[b]; 198 y = gy[b]; 199 al_draw_filled_pieslice(x, y, s, p * 0.6, p * 1.8, c); 200 al_draw_filled_triangle(x, y, x - s, y, x - s, y + s, c); 201 al_draw_filled_triangle(x, y, x + s, y, x + s, y + s, c); 202 al_draw_filled_rectangle(x - s * 0.5, y, 203 x + s * 0.5, y + s * 0.5, c); 204 al_draw_filled_circle(x - s * 0.5, y, s * 0.25, 205 al_color_name("white")); 206 al_draw_filled_circle(x + s * 0.5, y, s * 0.25, 207 al_color_name("white")); 208 209 b++; 210 if (b < 4) goto loopdrawghosts; 211 212 al_flip_display(); 213 g++; 214 r = false; 215 216 dontdraw: 217 al_wait_for_event(q, &e); 218 if (e.type == ALLEGRO_EVENT_DISPLAY_CLOSE) goto done; 219 if (e.type != ALLEGRO_EVENT_TIMER) goto nottimer; 220 if (k[ALLEGRO_KEY_ESCAPE]) goto done; 221 if (k[ALLEGRO_KEY_LEFT]) {kx = -1; ky = 0; f = p;} 222 if (k[ALLEGRO_KEY_RIGHT]) {kx = 1; ky = 0; f = 0;} 223 if (k[ALLEGRO_KEY_UP]) {kx = 0; ky = -1; f = p * 1.5;} 224 if (k[ALLEGRO_KEY_DOWN]) {kx = 0; ky = 1; f = p * 0.5;} 225 226 if (M(Q(px + kx * s / 2), Q(py + ky * s / 2)) == '#') goto cango; 227 px += kx; 228 py += ky; 229 if (px < -s) px += (w - 2) * s; 230 if (px > (w - 3) * s) px -= (w - 2) * s; 231 if (M(Q(px + kx * s), Q(py + ky * s)) == '.') 232 M(Q(px + kx * s), Q(py + ky * s)) = ' '; 233 cango: 234 235 b = 0; 236 loopghosts: 237 x = gx[b] - px; 238 y = gy[b] - py; 239 if (x * x + y * y < s * s * 2 * 2) goto restart; 240 if (dx[b] == 0 && dy[b] == 0) dx[b] = (rand() % 2) * 2 - 1; 241 242 if (M(Q(gx[b]), Q(gy[b])) != '~') goto noteleport; 243 gx[b] = sx; 244 gy[b] = sy; 245 dy[b] = 0; 246 noteleport: 247 248 if (M(Q(gx[b] + dx[b] * s / 2), Q(gy[b] + dy[b] * s / 2)) == '#') 249 goto ghostwall; 250 gx[b] += dx[b]; 251 gy[b] += dy[b]; 252 goto ghostmoved; 253 ghostwall: 254 if (dx[b] == 0) goto nodx; 255 dx[b] = 0; 256 dy[b] = (rand() % 2) * 2 - 1; 257 goto ghostmoved; 258 nodx: 259 dy[b] = 0; 260 dx[b] = (rand() % 2) * 2 - 1; 261 ghostmoved: 262 b++; 263 if (b < 4) goto loopghosts; 264 265 r = true; 266 goto mainloop; 267 nottimer: 268 if (e.type == ALLEGRO_EVENT_KEY_DOWN) k[e.keyboard.keycode] = true; 269 if (e.type == ALLEGRO_EVENT_KEY_UP) k[e.keyboard.keycode] = false; 270 271 goto mainloop; 272 done: 273 free(m); 274 al_uninstall_system(); 275}

taronĀ 

I think it would have been much better if you used more gotos.

Elias
taronĀ  said:

I think it would have been much better if you used more gotos.

I edited it. Better?

Matthew Leverton

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:

Elias

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.

Matthew Leverton

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.

Thomas Fjellstrom

stabbity stabbity stab is its own excuse.

video

Arthur Kalliokoski

{"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"}2010-12-02-Mystery-of-Ghost-Beach-3.png

Specter Phoenix

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 :o.

bamccaig

>:(

#SelectExpand
1#define FAIR_DICE_ROLL a(ss&q)const{return false;} 2#define DEITY (ss&)const; 3#define EXIT p<<q<<" "<<u_f(t_s(M8().a(q)))<<"."<<e;return 0;} 4#define DEITY_LABEL b M8 5#define GOTO public:b a 6#include <iostream> 7#define LOAD typedef int i;typedef string s;typedef const s ss; 8#define DATA i main(i argc, c argv[]){o&(*e)(o&)=endl;o&p=cout;s q("Did I win?"); 9#include <string> 10#define TRANSFORM s t_s(b value){return value?"yes":"no"?"maybe":"file not found";}s u_f(ss&value){s t=value;if(t.length()>0){t[0]+='A'-'a';}return t;} 11#define BOOT typedef bool b;using namespace std;typedef char * c;typedef ostream o; 12#define BEGIN class M8{ 13#define END }; 14 15BOOT; 16LOAD; 17BEGIN 18 GOTO DEITY; 19END; 20DEITY_LABEL:: 21 FAIR_DICE_ROLL; 22 TRANSFORM; 23 DATA; 24 EXIT;

I was too lazy to do any better.. :-/

Arthur Kalliokoski

It looks like a plausible entry to the obfuscated C contest. OTOH, I'm drunk again.

bamccaig

Hear, hear!

Arthur Kalliokoski
bamccaig said:

Hear, hear!

Are you appreciating the contest or drunkenness?

Neil Walker
Elias said:

Amazingly so, I edited it again

I think you should rename the labels to be in German.

Elias

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 :P

Emanresu

There are just so many Good Ideas and Bad Ideas here in this thread right now.

http://www.youtube.com/watch?v=f8PhzrmBgMI

type568

Mabmab's actually true celebrity. Surprising to know.

Specter Phoenix

Celebrity only on A.cc ;).

Thread #609316. Printed from Allegro.cc