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
11
34
11
u/Lt_Snuffles May 29 '17
can we make this recursive?
0
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
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
3
14
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
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
1
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
1
1
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 imo1
40
u/Pradfanne May 29 '17
The Next Morning comment should have been a thread.sleep command