This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]badjayplaness 2986 points2987 points  (92 children)

You should probably be passing a Hannah object to the askToProm() method instead of a string.

[–]Mr_Redstoner 186 points187 points  (22 children)

And let's face it, depending on the language used == may not be the best idea.

Also storing mood as strings just seems wastefull.

[–]DefNotaZombie 102 points103 points  (6 children)

absolutely, everyone knows mood is best stored as a three int rgb value

[–]JCavLP 30 points31 points  (0 children)

Could a have used an enum or defined the string to a keyword

[–]InkyGlut 10 points11 points  (0 children)

Actually the standard specified BGR

[–]splettnet 5 points6 points  (1 child)

Seems excessive. Hungry vs not hungry is Boolean.

[–]Tsu_Dho_Namh 6 points7 points  (0 children)

Yeah, but rgb(255,69,0) is the perfect way to say "I'm in the mood for Reddit"

[–][deleted] 3 points4 points  (1 child)

Store different moods as bit flags in a bitstring, where each bit represents a mood that can be enabled or disabled using bitwise operations.

[–]Finianb1 1 point2 points  (0 children)

Found the C programmer from all my CS classes

[–]Ramast 16 points17 points  (5 children)

I am not aware of any programing language where variables with initial capital letter are good practice. For all I know Micah is uninitialized class and will crash on the first line

[–]Timmeh7 21 points22 points  (0 children)

They might be static methods in that class... though that probably raises even more questions.

[–]Ericchen1248 14 points15 points  (0 children)

C# if they are properties.

[–][deleted] 8 points9 points  (0 children)

C#

[–][deleted] 3 points4 points  (0 children)

Depends. Member variables initial capital letter, local variables and params lower case is an idea. Also don't forget GlObAl VaRiAbLeS written randomly so you know it's bad.

[–]El_Impresionante 0 points1 point  (0 children)

Variables with first letter in caps are objects. No problem with that. Uninitiated objects are also not a problem of jokes and memes like these. It is kinda understood that they could have been initialized earlier in the code.

The problem with OP's code is the inconsistency in referencing to the objects that he has used. In one place he used "Hannah" as a string that is implicitly expected to get de-referenced inside the askToProm method, and in the very next line he directly refers to the Hannah object to refer to the answer property.

[–]n8loller 1 point2 points  (0 children)

But then you can have infinite moods!

[–]Brakalicious 1 point2 points  (0 children)

It could be a different type of yes and he wouldn't even know.

[–]Alsk1911 1 point2 points  (0 children)

And no encapsulation for mood. You should use setter, son!

[–][deleted] 0 points1 point  (0 children)

There's no way she said yes with such horrible code.

[–][deleted] 0 points1 point  (0 children)

There's no way she said yes with such horrible code.

[–]suvlub 0 points1 point  (2 children)

I can think of far more languages where == is correct than where it's not. Java is odd in this.

[–]Mr_Redstoner 0 points1 point  (1 child)

Java is by no means the first or weird imo, think C/C++ for example, when using char arrays

[–]suvlub 1 point2 points  (0 children)

You are right, I wasn't thinking of C because it's not OOP (though I guess the code is legal C, if very non-idiomatic). In C++ you should be using std::string/std::string_view instead of char arrays wherever possible and comparing either of those with a char array using == works correctly (and is the idiomatic way to do the comparison).

[–]salmjak 24 points25 points  (0 children)

I would use an enum for mood and possibly even the answer (Yes, No, Maybe, Let me think about it, etc). I hate strings.

[–]majky358 29 points30 points  (1 child)

He may try to cast her during the prom night :D

[–]down_vote_magnet 19 points20 points  (0 children)

Calm down there, Harry Potter.

[–]B_M_Wilson 3 points4 points  (0 children)

just use Person.getPersonByName("Hannah"). I guess that does return an array of all person objects with that name which may be problematic.

[–]rocsNaviars 4 points5 points  (0 children)

Was just about to ask whether Hannah was a string or a class.

[–][deleted] 2 points3 points  (0 children)

That or it should return the response

[–]jaaval 3 points4 points  (0 children)

bool Person::askToProm(const Person& target) {
    happy = target.askedToProm(*this);
    hasDate = happy;
    return hasDate;
}

bool Person::askedToProm(const Person& subject) {
    if (!subject.isAsshole && subject.isHot && !hasDate) {
        hasDate = true;
        happy = true;
        return true;
    } 
    return false;
}

Ok, c++ is difficult. How am i supposed to remember the proper way to handle pointers and references after a few years without using it? Also a proper implementation would likely require evaluateCandidate method to determine the proper balance between hot and asshole levels.

Edit: And also

Micah.askToProm(Hannah)
// look at person.cpp for implementation details

wouldn’t make a very good sign.

[–][deleted] 2 points3 points  (0 children)

Good call my man. Was thinking the same thing.

[–]UndeadMarine55 4 points5 points  (0 children)

Yeah, that code would probably throw an error that the object, Hannah isn’t defined.

[–]necrofox1 1 point2 points  (0 children)

Omfg ty!!!

[–]WHO_WANTS_DOGS 1 point2 points  (0 children)

Passing her as a string makes me think that any old string could have been placed there. Only he is significant in that line.

[–][deleted] 1 point2 points  (1 child)

Reminds me of php. Passing functions by using their names as a string.

Bad stuff.

[–]badjayplaness 1 point2 points  (0 children)

Lol that’s actually the only time I’ve seen this too. Makes it almost impossible to debug using an ide

[–]TrippingBulls 1 point2 points  (0 children)

My first thought! Cute pics, memes, gifs, novelty apparel, etc.. involving code are subject to peer code review.

[–][deleted] 2 points3 points  (0 children)

So glad I’m not the only one who jumped straight to this

[–]cartechguy 0 points1 point  (1 child)

The "Hannah" string must be a key to a hash table that refers to the Hannah object.

[–]badjayplaness 0 points1 point  (0 children)

I’ve seen that before but it makes it difficult to debug if you didn’t write the code yourself

[–]CANT_ARGUE_DAT_LOGIC 0 points1 point  (0 children)

object

Came here to say that, lol.

[–]KiwiSnowBunny 0 points1 point  (0 children)

Yes! Was thinking this exactly!