23
luaq
6y

Is Santa coming to your house? Use my "advanced" algorithm to find out.

Person kid = getKidByName("yourName");
FatGuy santa = new FatGuy("santa");

if(!kid.wasNaughty()){
System.out.println("Good child");
santa.sendGift(kid, "train");
return;
}
System.out.println("You're on the naughty list");
santa.sendGift(kid, "coal");

Comments
  • 4
    So every kid is on the naughty-list? Guess that explains why the parents have to take care of the presents
  • 3
    You forgot an else, dude. Everyone will turn out naughty in the end.
  • 8
    @DjSall @Krokoklemme no the return ends the function. After a nice child the function ends with the return and skip the naughty part.
  • 3
    @oldfrizt so we just got proof that this is poorly designed code
  • 0
    Coal market’s about to boom
  • 2
    @Krokoklemme and how is this poorly designed ?
  • 0
    @samfreeman05 first and foremost: weird branching

    Second: return in a void method? dafuq
  • 4
    @Krokoklemme if you say so, I see those two things very often
  • 0
    @samfreeman05 my condolences. Well, I guess over time you get used to that stuff
  • 0
    @Krokoklemme what do you think return is ? you think it's only used to return a value ?
  • 0
  • 1
    Sorry if this wasn't clear. I didn't write the function down, but I'd expect that if you are on a developer app, you know what return does.
  • 1
    Think of it like this. If that were a for or while statement, return acts just as break.
  • 1
    @ssync no matter if it is a void or not. As soon as return is called, it stops the function because it has already returned the value it was running for in the first place. But in this case, because it was a void, we return nothing, pretty much saying the function has done it's task.
  • 1
    @oldfrizt thanks for explaining. Never seen it used in my main languages, excuse my confusion...
Add Comment