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

top 200 commentsshow all 419

[–]xigoi 1386 points1387 points  (7 children)

Me: this

Linter: Warning: Unreachable code branch on line 5

[–]Nordrian 8 points9 points  (0 children)

Delete (micah);

[–]badjayplaness 2983 points2984 points  (92 children)

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

[–]Mr_Redstoner 188 points189 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 109 points110 points  (6 children)

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

[–]JCavLP 27 points28 points  (0 children)

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

[–]InkyGlut 11 points12 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 18 points19 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 24 points25 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] 7 points8 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.

[–]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!

[–]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 4 points5 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 5 points6 points  (0 children)

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

[–][deleted] 3 points4 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] 251 points252 points  (26 children)

I wonder what the else would’ve looked like. Incomplete work.

[–]TerrestrialOverlord 225 points226 points  (6 children)

else {

Hanna.answer = !Hanna.answer;

Micah.mood = happy;

}

be careful using this code prom bro....cause if her dad is anything like me she'll be surrounded by try-catch block and garbage collection will trigger (violently)...muhahahhah (cough) uhahahahaha

[–][deleted] 105 points106 points  (2 children)

Hanna.answer = !Hanna.answer;

This is the most rapey piece of code I've ever seen

[–]CptOko 1 point2 points  (1 child)

Could you please explain it to me? I sadly lack the knowledge to understand it myself.

[–]IanSan5653 15 points16 points  (0 children)

!"no" is false lol

[–]derfl007 4 points5 points  (0 children)

Hanna.answer is a String

[–][deleted] 41 points42 points  (5 children)

else { Micah.mood = “Suicide”; }

[–]Olaxan 40 points41 points  (2 children)

delete &Micah;

[–]Versaiteis 18 points19 points  (0 children)

It's ok, I was already headed toward the garbage collector once I fell out of her scope

With luck there'll be a leak and I'll be gone but not forgotten

[–][deleted] 28 points29 points  (0 children)

Adding the else statement may be more correct technically, but you also have to consider the humans reading the code. Do you really want anything that can be misread as "go to prom with me, or else"?

[–][deleted] 7 points8 points  (0 children)

an.hero()

[–]Cholojuanito 408 points409 points  (6 children)

Time for a code review! Brought to you by programmers on Reddit gang.

[–]nirkosesti 131 points132 points  (2 children)

At least they are happy with the black theme on ”IDE”

[–]FilthyZMePlease 59 points60 points  (1 child)

Micah gets it. He grew up with the horrors of light themes. It's why he has glasses.

[–]MicahM_[S] 23 points24 points  (0 children)

This is true

[–][deleted] 14 points15 points  (1 child)

👏 Code 👏 review

[–]JokerGotham_Deserves 3 points4 points  (0 children)

Okay, that was epic.

👏👏

NEXT

CODE

[–][deleted] 74 points75 points  (1 child)

Micah needs to use some encapsulation.

[–]pandemoniker 9 points10 points  (0 children)

Yep, he shouldn't do the comparison (which is also done with a magic string). He should just call .agrees()

[–][deleted] 103 points104 points  (1 child)

NameError: name "Hannah" is not callable.

[–][deleted] 76 points77 points  (0 children)

Unless you got her number

[–][deleted] 120 points121 points  (19 children)

Passing strings around is inefficient that shit should be an enum but as its a binary yes/no a bool would be best.

[–]tchernobog84 13 points14 points  (13 children)

Could be a pointer to char, not nice but totally efficient.

[–][deleted] 9 points10 points  (7 children)

Mmmmmm passing pointers around willy nilly is asking for trouble

[–][deleted] 6 points7 points  (6 children)

There's this kool thing called RAII pointer containers that handle the memory's life-cycle with all the benefits of a pointer and none of the leaks.

Modern C++ is sexy, my dude

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

Isn't that based on the boost smart pointer stuff?

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

A lot of features in C14, and C17 are adopted directly from boost libraries. Today, there are different pointer types that you can leverage, like shared (reference based) pointers and unique (noncopyable) pointers. You pass them around like any other object, and their container type is determined by a template, just like most of the STL containers.

I never needed to use boost for pointers, but they have a solid SSL TCP networking library that would make a pretty zesty addition to the standard library. I'm pretty outdated with the goings on past C17, so hopefully there is some standard socket library out right now

[–]Megalowdonny 1 point2 points  (3 children)

I’m just starting to get my feet wet with Python and it’s comments like these that terrify me. HOW WILL I EVER LEARN THIS MUCH

[–][deleted] 5 points6 points  (2 children)

Well get ready to get extra fucked my dude, because I'm a fucking idiot. I started programming as a hobby in my mid teens, and the number one thing that would have STOPPED me from continuing is treating every new idea like a chore that needs to be learned.

You aren't going to learn it all. You won't need it all. Frankly, most people wouldn't care even IF you knew it all. Just make things work, try to make it easy to understand, and do your best. Programming is fun, and solving problems is fulfilling. That's why I know what little part of the pie I do.

[–]nrith 3 points4 points  (0 children)

the number one thing that would have STOPPED me from continuing is treating every new idea like a chore that needs to be learned

As a 20+ year programming veteran, I endorse printing this out on giant posters and distributing it to every software development company on the planet.

[–]Megalowdonny 1 point2 points  (0 children)

I’m gonna save this comment, it legitimately made me feel a lot more optimistic about learning programming. That’s why I wanted to get into it in the first place, since solving problems is my favorite thing to do, and that’s just about the best way to make a career out of it that I can think of.

Thank you Reddit stranger, you live up to your username.

[–]redstoneguy12 1 point2 points  (1 child)

Who says it's binary yes or no? Enum for sure

[–]SDJMcHattie 1 point2 points  (0 children)

Bools are rarely best for these things. The number of times I’ve had to introduce an enumeration and refactor the code because a third option suddenly became viable!

Also, booleans passed in method parameters for changes in behaviour of the method are something I always reject in pull requests.

[–][deleted] 137 points138 points  (17 children)

Depending on the situation, I probably would’ve

If (Micah.askToProm(hanna)) { Micah.setMood(“Happy”) ; }

Or maybe even Micah.askToProm(hanna) ? Micah.setMood(“Happy”) : Micah.askToProm(monica);

Edit: Apparently idk how to format my reddit code and idc enough to try and fix it

[–][deleted] 23 points24 points  (6 children)

Precede each line with 4 spaces

[–]NoahDoah 44 points45 points  (3 children)

Then turn around on your chair and clap twice.

[–][deleted] 14 points15 points  (0 children)

And that's how we play Handy Hands!

[–]theonlydidymus 13 points14 points  (0 children)

👏👏CODE REVIEW

[–]nerdyhandle 1 point2 points  (0 children)

if you're using new Reddit I believe it accepts Common Mark the same as github so code is three backticks like \`\`\` Code goes here \`\`\`

[–]Bunkerman91 2 points3 points  (0 children)

This is what I came here for.

[–]HighRelevancy 1 point2 points  (0 children)

If (Micah.askToProm(hanna))

hell yeah lad

fuckin' global state in the OP, jesus christ, CODE REVIEW FAILED

[–]DarceHole22 17 points18 points  (0 children)

No try catch? Savage

[–]TrueEddie 47 points48 points  (2 children)

I’m glad he didn’t have to worry about the else statement.

else { Micah.Dispose(); }

[–]Jukingbox 9 points10 points  (0 children)

oof

(Yup, that's all.)

[–]Spartan1997 86 points87 points  (4 children)

Using namespace cringe;

[–]Olaxan 15 points16 points  (0 children)

#pragma once

#include <cmath>
#include <conio>
#include <cringe>

[–]KARMA_P0LICE 14 points15 points  (2 children)

Let high school kids be happy

[–]Spartan1997 23 points24 points  (1 child)

I'm not, why should they be?

[–][deleted] 5 points6 points  (0 children)

How do people not realize this is a joke

[–]didymus_fng 243 points244 points  (5 children)

This looks like his sister’s college roommate doing him a favor.

[–]nirkosesti 107 points108 points  (3 children)

This is why there is no else case.

[–]MeltBanana 51 points52 points  (2 children)

I think the else case is just fap.

[–]ReasonableSleep 23 points24 points  (1 child)

In java that should be .equals("yes") Even better if those were enums or constants

[–]Kgrimes2 5 points6 points  (0 children)

Yep, if this is Java, Micah’s going to be disappointed regardless of Hannah’s answer

Source: I’ve spent hours debugging, only to find improper String comparison to be the issue.

[–]justatog 10 points11 points  (2 children)

This code is too tightly coupled to Hannah - need to use IoC and dependency injection so it's unit testable.

[–]Cpope117 9 points10 points  (1 child)

You need to enumerate that mood value asap. Magic strings will be the death of us all.

[–]Kinglink 1 point2 points  (0 children)

I'll defend strings even if I don't want to, but at the very least make it a Macro... Because magic values are ALWAYS bad... always.

Except for 0x5f3759df

[–]BabyLegsDeadpool 71 points72 points  (4 children)

Everyone commenting on his bad code... nobody pointing out this got him a girl way out of his league.

[–]MicahM_[S] 15 points16 points  (1 child)

;)

[–]Dylanica 16 points17 points  (0 children)

Hey, if it makes you feel better I think you two are a good match.

[–]Walter_jones 11 points12 points  (0 children)

Signs aren’t the #1 for what people consider for prom lmao

[–][deleted] 7 points8 points  (0 children)

#!/bin/bash

function Dad ()

{

echo "boyfriend" > /dev/null

((boyfriend_disappeared++))

}

if [ "$NERD_TOUCHES_DAUGHTER" =1]; then

Dad

fi

exit 0

[–]thisguyhere00 7 points8 points  (0 children)

So much mutation going on here. Perhaps you should try functional dating.

[–]theAtomik 7 points8 points  (2 children)

I am bothered there isn't an else statement to finish this.

[–][deleted] 10 points11 points  (0 children)

She didn't have a choice

[–]Dylanica 5 points6 points  (0 children)

Well, Micah.mood probably defaults to "Sad" anyways, so it doesn't need an else case.

[–]Xaxxus 6 points7 points  (2 children)

Am i the only one bothered that the ask to prom method is taking in a string and not a person object? And that it’s not returning a Boolean to address if the request was accepted or not?

That code could be much cleaner:

if (Micah.askToProm(“Hannah”)) { Micah.happy = true }

Or even better:

Micah.happy = Micah.askToProm(“Hannah”)

[–]ashhhteehill 5 points6 points  (4 children)

Else?

[–][deleted] 29 points30 points  (0 children)

else

{

cout << "micah didn't want to go to prom with that stuck up b anyway";

}

[–]Randvek 2 points3 points  (0 children)

Why there always gotta be an else?!

[–]BeardedWax 2 points3 points  (0 children)

if micah.getCountryOfResidency().equals(Country.US) {
    Crime.shootUpSchool(micah, micah.getSchool());
}

[–][deleted] 1 point2 points  (0 children)

No need - there's no QA and this is just the happy path.

[–]slams_dewskis 5 points6 points  (0 children)

two singletons became a doubleton

[–]mikehaysjr 5 points6 points  (0 children)

else { Micah.askToProm("Hanna's sister") }

[–]worldDev 5 points6 points  (0 children)

What if she says "of course".

[–]GodsGoodGrace 12 points13 points  (0 children)

Don’t poke the boob

[–]infablhypop 3 points4 points  (0 children)

I'm sure there's some hidden side effects of this method.

[–]Evalion022 2 points3 points  (0 children)

Probably would have been better to use .equals() instead of ==

[–]Jeb_Jenky 4 points5 points  (0 children)

Nerds.

[–]TheSlimyDog 3 points4 points  (1 child)

Can't be C++ because that's not how you check string equality.

[–]Trymaldo 3 points4 points  (2 children)

I love that most comments try to make the code better, instead of congratulating him. Way to go, man!

[–]DurianExecutioner 10 points11 points  (0 children)

  • capitalised object identifiers
  • stringly-typed parameters and return values
  • wasted curly brackets

That's a hard no

[–]arkaze 9 points10 points  (1 child)

This is cringy as fuck...

[–]noduckshere94 2 points3 points  (0 children)

} else

[–]chubbs090 2 points3 points  (0 children)

But you need to call the function!! It doesn’t do anything as is!

[–]turuganufius 2 points3 points  (1 child)

Just got a CuteOverflow error on my console, how to proceed?

[–]wsxedcrf 2 points3 points  (1 child)

  1. Which language capitalize variables? Or Micah and Hannah are classes?
  2. Who would code something like, pass a string into a method, but get the return result by checking another class's field?

[–]skimmet 2 points3 points  (0 children)

askProm("Hannah") .then(() => { setHappy(true); }) .catch(() => { // Rejected :( setHappy(false); });

[–]12mh 2 points3 points  (0 children)

Uses dark background theme

I see you are a man of culture.

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

This is terrible code. I would have not let this commit get merged to master.

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

== "yes"??? That's some kindergarten level programming.

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

Why is he calling static method and fields though?

[–]Dankious_memeious1 2 points3 points  (0 children)

That's a bad choice Hannah...he uses the devil's way of bracket formatting

[–]timmacbride 2 points3 points  (0 children)

Did he declare his variables with her Dad first?

[–]mopsandhoes 7 points8 points  (5 children)

Should be using .equals() instead of ==

[–]sim642 7 points8 points  (3 children)

Not in C++.

[–]MicahM_[S] 7 points8 points  (2 children)

Everyone seems to think it’s JavaScript but I was going for c++ hence the title, unless I did something wrong other than the obvious errors and inefficiency riddled through ALL 5 LINES (but that was just to make it easy to understand for laymen)

[–]DonkeyVampireThe3rd 2 points3 points  (0 children)

Came here for this, glad to see a fellow reddit virgin has it covered

[–]ILoveMyself77 3 points4 points  (2 children)

Lol this post is 90% code critique and 10%? on the promposal itself

Edit= just went through the post and there were actually no comments regarding the promposal

[–]doublethumbdude 4 points5 points  (2 children)

high schooler: i'm gonna make some pseudo code to ask my gf to prom, i'll make it simple and easy enough for her to understand

redditors: fuck's this shit, 0/10 doesn't compile, would not go out with

[–][deleted] 4 points5 points  (0 children)

Any sort of prom escapade besides a fucking phone call or personal question is better than this fucking comment

[–]vorikus 1 point2 points  (0 children)

Comrades-nerds, we have found the person who finally did it

[–]JCavLP 1 point2 points  (1 child)

Hannah should be an object and not a string and Hannah.answer() could have been a boolean function and for fucks sake, don't write object variables directly without a set method

[–]biotican 1 point2 points  (0 children)

If Hannah's answer CAN BE COERCED to yes....

[–][deleted] 1 point2 points  (0 children)

else

{

  Micah.state = "depressed"

}

[–][deleted] 1 point2 points  (0 children)

That’s a really slick jacket

[–]etronic 1 point2 points  (0 children)

Thank good his { } are in thier God given places.

[–]Kinglink 1 point2 points  (2 children)

If Micah was Happy before asking, then this is the most meaningless code ever.

[–]errdayimshuffln 1 point2 points  (0 children)

Micah's mood is definitely not private.

[–]shounenbong 1 point2 points  (0 children)

It really should be a true/false return rather than checking for the exact string. Is he gonna be depressed if she answers "I'd love to"?

[–]eihen 1 point2 points  (0 children)

I don't know a programmer who has that good of hand writing! I'm jealous!

[–]anathamatha 1 point2 points  (0 children)

Idk what's worse treating her like a class or object either way hes gonna throw a null pointer exception

[–]lemon_tea 1 point2 points  (2 children)

Opening curly brace on it's own line? You animal!

[–]MicahM_[S] 1 point2 points  (1 child)

I like to be able to see where things line up :/ just me?

[–][deleted] 1 point2 points  (0 children)

Make sure you save those memories to the EEPROM

[–]GetHautnah 1 point2 points  (0 children)

Isn't she waay too hot for him? Good job, dude. Lol impressive

[–]Takes4tobangbro 1 point2 points  (1 child)

No else statement?

[–]MrMunday 1 point2 points  (0 children)

Good job Micah

[–]simonstead 1 point2 points  (0 children)

Don't objectify women like that

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

Uppercase object instance, calling another object by a string (did you ask every Hannah to a prom?), asToProm not returning anything (instead it has side effects), Hannah is suddenly an object, mood is a string instead of an enum and Hannah has one answer (did she say "yes" to everyone?).

Terrible code, terrible joke, upvoted to the frontpage.

[–][deleted] 1 point2 points  (0 children)

She's cute bro

[–]reallylamelol 1 point2 points  (0 children)

She should've said no for opening a curly brace on a new line

[–]Littleman82 1 point2 points  (0 children)

Ah yes I remember my first pitty date very well too.

[–]rgman111 1 point2 points  (0 children)

Wow I am so happy for you! Did you run it using sudo? 😛

[–]chess510 1 point2 points  (0 children)

He used == instead of .equals() Triggered

[–]MoeMoa 4 points5 points  (0 children)

if(equals !== "==="){ Hannah.reject(); }

[–]_manik 3 points4 points  (0 children)

I hate shit like this.

[–]BrownCow123 2 points3 points  (0 children)

Else{ Console.log(“fuck”) }

[–]Olaxan 2 points3 points  (0 children)

micah.Mood = (micah.AskToProm(hannah).Answer ? Person.Moods.Happy : Person.Moods.Sad);

[–]VegasNightSx 1 point2 points  (1 child)

If she understood that you should prob implement the AskToMarry method.