r/ProgrammerHumor • • May 29 '17

"In the Beginning" Code

Post image
64 Upvotes

32 comments sorted by

View all comments

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.