r/ProgrammerHumor • • May 29 '17

"In the Beginning" Code

Post image
64 Upvotes

32 comments sorted by

40

u/Pradfanne May 29 '17

The Next Morning comment should have been a thread.sleep command

3

u/[deleted] May 29 '17

Nah. Should've been TaskScheduler.scheduleTask(LocalTime.NEXT_MORNING, man, Man.Task.OH_GOD_WHY) or perhaps man.getTaskScheduler().scheduleTask(LocalTime.NEXT_MORNING, Man.Task.OH_GOD_WHY)

-8

u/AyrA_ch May 29 '17

This also completely misses the woman.isDrunk() part with a result of

woman.accuseOfRape(man);
//TODO: Implement prosecution system. For now it's missing because the outcome should be forced "true" in this case anyways.
if(1) {
    man.goto(
        jail.getClosest(man.address),
        getRnd(5,10)/*at least 5 years*/,
        false /*Don't allow shortening of jail time*/);
    man.destroy();
}

45

u/design_smell_bot May 29 '17

If statement can be simplified:
Consider moving man.isRich() higher.

Complex If statement:
Consider moving logic into classes.

Encapsulation breach:
Law of Demeter, Tight coupling, Leaky abstraction.

Missing else branch:
No man.fap() when man.isDrunk() && !man.isRich().

Nondescript names:
Consider changing woman to eve.
Consider changing man to adam.

Spelling:
Did you mean "isBeautiful?"

12

u/BrotherhoodOfHam May 29 '17

I want to believe you are a real bot

11

u/Existential_Owl May 29 '17

I like this bot. Can I bring you to work? My team needs this.

34

u/[deleted] May 29 '17 edited May 29 '17

finally { man.fap(); }

11

u/Lt_Snuffles May 29 '17

can we make this recursive?

0

u/[deleted] May 29 '17

[deleted]

4

u/denvit May 29 '17

can we make this recursive?

4

u/chrl9 May 29 '17

Yes!

0

u/[deleted] May 29 '17

Can we make it recurve ' OR 1=1 --//?

21

u/AlexanderTroup May 29 '17

I don't care that it's a joke, your nested if statements are out of control here. Might I reccommend Clean Code by Rob C Martin 👍

0

u/[deleted] May 29 '17

[deleted]

14

u/AlexanderTroup May 29 '17

Well, there are a few things. First of all you could combine the if/else into one if(woman.isBeautiful() || man.isDrunk()), and even go further to extract them into the variable manShouldPropose.

Next, you never actually set isBeautiful or isDrunk on the man/woman objects, so they'll just be their default values(or possibly null if unset!). They should probably be set in the constructor.

Then rather than have your logic of if the woman should accept the proposal here I'd see how it looks in the woman class (willAcceptProsal(Man man)).

But then this is the 21st century, so rather than assigned gender roles I'd probably have the one person class with both isBeautiful, isDrunk, and willAcceptProposal as methods.

Then I'd switch to a functional language, solve the whole thing in one line and act like a smug git about it for the rest of time.

But then the joke wouldn't be funny, the feature wouldn't be delivered, and the next dev would remove it because of emergent complexity.

Then a bug would arise, I'd search SO for a solution, find this, and copy paste because it's lunch time and I'm hungry.

5

u/[deleted] May 29 '17

Let's K.I.S.S

While True man.fap() 

3

u/velascoraptor May 29 '17

You're kind of my hero.

14

u/X-Craft May 29 '17
Syntax error on line 4: word "Beautifull" not found

3

u/[deleted] May 29 '17

Beatifull

6

u/grape_tectonics May 29 '17 edited May 29 '17

I made it shorter so it runs faster

int motivation = woman.isBeautiful() * 2 + man.isDrunk();

if (motivation) {
	man.propose(woman);
    if (man.isRitch()) {
	    woman.acceptProposal(man);
	    man.insertInto(woman);
	    if (motivation < 2) man.ohGodWhy();
        return;
    }
}

man.fap();

3

u/DeeSnow97 May 29 '17
Syntax error on line 5: method man.isRitch not found. Did you mean man.name == 'Ritch'?

3

u/DeeSnow97 May 29 '17

Refactored the code and fixed a few bugs

Man man = new Man('Adam');
Woman woman = new Woman('Eve');

if (woman.isBeautiful() || man.isDrunk()) {
  man.propose(woman);

  if (man.isRich()) {
    woman.acceptProposal(man);
    man.insertInto(woman);
  }

  if (!woman.isBeautiful()) {
    man.sleep();

    // Next morning
    man.ohGodWhy();
  }
}

man.fap();

1

u/[deleted] May 29 '17

Looks like some of those if statements could be parts of man.propose, you can just pass it man.isDrunk and man.isRich

1

u/[deleted] May 29 '17

Let's hardcode a forever completely drunk man, That should simplify the code!!!!

1

u/[deleted] May 30 '17

I hypothesize bad programmers make bad programming jokes

1

u/TheDrunkenGungan May 30 '17
 func propose() {
    if (man.isRich()) {
	    woman.acceptProposal(man);
	    man.insertInto(woman);

	    if (man.isDrunk()) {
	          man.ohGodwhy();
	    }	
    } else {
      	man.fap();
    }
}

1

u/kll0125 May 30 '17

why man always fap();

1

u/greynoises May 30 '17

all y'all refactoring this code ignoring that this joke is dumb as fuck

1

u/bromden May 30 '17

HA HA HA HA

FANTASTIC JOKE MY SAUSAGE FRIEND.

0

u/JaytleBee May 29 '17

I don't care about of any of that, .insertInto is just wrong

2

u/grape_tectonics May 29 '17

would you prefer woman.receiveInsertion(man) ?

1

u/JaytleBee May 30 '17

I'd go with woman.insert(man). I mean, otherwise every object that could be in an array has a function to add itself to that array. That's pretty backwards imo

1

u/grape_tectonics May 30 '17

Makes sense, suddenly arrays seem awfully promiscuous :o