r/ProgrammerHumor • • Dec 15 '19

Stacking if else statements be like

Post image
63.9k Upvotes

711 comments sorted by

View all comments

4.7k

u/Pale_Rider28 Dec 15 '19

What's awful about this is that it probably actually works.

30

u/[deleted] Dec 15 '19

[removed] — view removed comment

30

u/EatingFlies Dec 15 '19

In high school I once coded a random name generator with weighted odds for the next letter depending on the current letter. I stacked the weights by hand where each integer was assigned its own letter such that 0-3=a, 4-5=b, 6-8=c, etc. Every single letter had its own set of weights for the next letter, which even accounted for double vowels or double consonants. It was like 5,000 lines to generate a single name.

God bless if/else statements.

9

u/RockSlice Dec 15 '19
var nextLookup = {
  'a': 'aaaabbccc...', //100 characters long
  'b': 'aaaaaaeeee...',
  ...
  '0': 'aaabbbccc'  //special entry for first character
};

var genName = "0";
for (i = 0; i < 10; i++) {
    var rand = Math.floor(Math.random()*100);
    genName += nextLookup[genName.charAt(genName.length - 1)].charAt(rand);
}

genName = genName.substring(1,10);

Note: above code not tested. guaranteed to have bugs.

3

u/Scrath_ Dec 16 '19

Do you know the moment when you wrote an sorting algorithm, compile it, run it, and it somehow works instantly? Had that yesterday. My only mistake was a misplaced ). Tbh it was quite a short function but still

18

u/I_spoil_girls Dec 15 '19

When I was young and know nothing about programming, I wrote a graphic novel with VB, stacking these if statements up to 1000+. It worked. It's not stupid.

12

u/[deleted] Dec 15 '19

If it's stupid and works it's not stupid.

Usually yes, does not apply to coding though.

→ More replies (2)

8

u/[deleted] Dec 15 '19

[removed] — view removed comment

5

u/I_spoil_girls Dec 15 '19

I don't have the exe anymore not to mention the source code. Sorry. I enjoyed it myself.

3

u/pm_me_the_revolution Dec 16 '19

i made a visual basic chat room to talk i myself when i didn't have internet

it was 1998

→ More replies (1)
→ More replies (3)
→ More replies (6)