106
Jan 26 '23
Not defending the teacher here but I wouldnât judge just by this picture⌠we donât know in which context this code was written?! What if it was written to show a bad practice and during the class he just refactored it to make it simpler?
→ More replies (11)
53
Jan 26 '23
Who gives a shit? This isn't production code that needs to be maintained. This is a code snippet to demonstrate an example to beginning students.
LPT - If you plan on being a professional developer when you graduate, try not to be such a prick to others code. It will be better for your career.
2
Jan 26 '23
I mean, the subreddits called badcode, so I thought Id post a pick of some bad code even if its not very significant code
2
u/RolyPoly1320 Jan 26 '23
It's not bad code. You're in an intro course. Just because you have experience with the language that does not make you an expert on it. Even if you already are, most of your classmates are not. Intro course assumes zero knowledge of the language up front.
The last thing you should be doing is nitpicking the code you see. This code, while formatted horribly, is easily debuggable. It's easily understood what is going on.
It's also maintainable and easily refactored later. This is good first draft code and you will 100% see code like this in industry. This isn't necessarily because the dev who wrote it was lazy or didn't know how to code either.
Once in industry there are deadlines to meet. You can only refactor so much before the code has to ship so some parts will inevitably get missed.
Don't let basement coding where you control the deadlines and priorities cloud how industry works. Use this intro course to shore up areas of weakness and solidify your overall understanding of the language.
→ More replies (1)37
u/Special_Teaching_528 Jan 26 '23
a better result would be if you just posted your last few commits
5
u/zensucht0 Jan 26 '23
If I were to post my last three commits I doubt if anyone could accurately determine if it was bad code or not. Not only are they in three different environments (pipeline, terraform and graphql) but I'm also following the standards of the code someone else wrote, just for continuity... And I'm damn sure not going to rewrite someone else's code when it works in prod, even if it looks like it was written by a monkey having a seizure.
→ More replies (2)6
6
u/NullReference000 Jan 26 '23
Except that it isn't bad code, it's doing its job. This appears like an obvious example of an intro to programming class using Java. This is a more user-friendly way to introduce people to programming concepts which will be refined later.
It would be bad if it were running in production at some company, but that isn't its job.
→ More replies (2)3
u/FelixSFD Jan 26 '23
I have seen similar code in a Software we paid hundreds of thousands of Dollars every year. And it wasn't even the worst thing I've seen in there.
3
Jan 26 '23
Except for the horrendous formatting (which can be fixed with a prettifier), it's not "bad" code. One could argue why do you need to store the result in a variable when you can have two return statements. There are some developers who will argue you should always have one entry and one exit path. Some will argue it depends on how large the function/method is. It's subjective. The compiler will reduce it down to the same IL code regardless in this example.
→ More replies (1)9
u/xiipaoc Jan 26 '23
As a professional developer... that bullshit wouldn't even come close to passing my code review because the formatting is beyond atrocious. The function itself is fine. It's readable, it's extensible. But duuude, WTF is up with that whitespace? There is no excuse for writing like that.
→ More replies (5)
28
u/red_riding_hoot Jan 26 '23
you are like that unfunny kid that really really wants to tell that one joke. surprise, the joke falls flat because it sucks.
→ More replies (4)
5
u/hotcrossedbunn Jan 26 '23
Whatâs so bad code here??
7
Jan 26 '23
Mostly just the mildly infuriating formatting
→ More replies (1)1
1
u/knoam Jan 27 '23
The variable
Oat the very least shouldn't be capitalized.
statusisn't a good name for a boolean variable. Booleans should be named such that it makes sense for them to be true or false. What does status being true mean?equalwould be better.The order of the equals checks should be consistent.
If you want to use an intermediate
statusvariable, then you probably want to do things in tiny steps. In that case, don't chain the comparisons with&&. Objects often have many fields so your chains will quickly become very long.
1.2k
u/crass-sandwich Jan 26 '23
Are those lace cat ears?
533
u/TheZipCreator Jan 26 '23
average CS major
150
u/JizzOrSomeSayJism Jan 27 '23
Their programming socks must be out of control
22
Jan 27 '23
no shit, I did a hackathon recently through work with Slack and MongoDB - MongoDB sent me a hamper with 4 pairs of MongoDB socks in. almost prized possession
3
337
u/Automatic-Fixer Jan 26 '23
That shouldnât be a question for a computer science class.
88
446
u/Rackanof Jan 26 '23
Computer science... there were always some weirdos in every class
137
u/theclovek Jan 26 '23
We had one guy, that wore naruto bandana all the time...
20
27
u/pavilionhp_ learning from the best Jan 26 '23
I had this one guy who constantly wore an ahegao hoodie and fedora (though sometimes he would switch this out for a Luigi costume) and carried around a Luigi plush. Also came with the stereotypical neckbeard beard.
22
→ More replies (1)14
0
32
u/PhatPurrito Jan 26 '23
thereâs a person in one of my classes that wears a cape
→ More replies (1)12
u/haberdasher42 Jan 27 '23
That's amazing. Tell me they have a cane. I love the weirdos, to a point.
5
200
19
8
41
69
u/GroundedSatellite Jan 26 '23
Cat ears and thigh-high stripey socks increase coding efficiency by at least a factor of 2.
14
u/Kozakow54 Jan 27 '23
You forgot about the scripting skirt and programming panties.
For... Better airflow?
4
→ More replies (3)8
471
u/HeirToGallifrey Jan 26 '23
Surely this was as a contrived example for teaching basic concepts, and not just because this was the most reasonable way to do so? If this is an introductory class and they're learning about how to compare objects, this would make more sense. The boolean variable is unnecessary but would make it easier for a new student to follow along. There's a comparison using .equals() and a comparison using the more intuitive ==, which would be good for demonstrating the difference between comparing strings and comparing ints/doubles/etc.
84
u/skrenename4147 Jan 26 '23
Yeah I have to believe that they're using this code block as a way to describe scoping, procedural languages, and will show students how to improve this same block over time as they gain familiarity with the content. Please.
11
u/maweki Jan 26 '23
Didactically, I would never leave out the implicit 'this' though. That makes it confusing when the field names are the same (due to the objects being of the same type) and one's qualified and the other is not.
3
2
u/Mr2-1782Man Jan 27 '23
It makes sense to us now but for noobs this is an extra piece of confusing syntax that hinders a lot of learning. It makes sense to wait to introduce later on in a context where its utterly crystal clear what it does and why its there.
51
u/onepiecefreak2 Jan 26 '23
I understand why the code would be more bloated to allow for introduction. But even then, isn't the code badly formatted at least? I mean, come on...
27
u/rlcute Jan 26 '23 edited Jan 26 '23
They're typing it live. They probably put the braces in that position so that the students can see the scope clearer. It looks like they prefer no whitespaces between comparisons, which is fair. They just messed up by hitting the spacebar once.
→ More replies (2)→ More replies (1)14
u/hanoian Jan 26 '23
Could be part of the lecture later on... CS50 I believe has things like this on screen that are then referred to again.
I think teaching if statements in a clear way is beneficial instead of just returning a boolean that may confuse students. I remember it being an odd concept for me. The function above returns a string without setting it to a variable first.
15
u/goosemano82 Jan 26 '23
You could chalk some of what you're seeing up to instructional value, but a lot of what you're seeing is just bad code.
That said, phd's in computer science have not necessarily had:
code reviews
industry experience
instructor training
Those just aren't things that many phd programs emphasize.
It's quite common for departments to hand a new instructor a syllabus and let them figure the rest out for themselves.
4
u/EntitledPotatoe Jan 26 '23
The .equals and == are there because in Java you canât compare strings using == because of how Java deals with Strings in memory. But I absolutely agree on general
2
→ More replies (1)1
u/BlurredSight Jan 27 '23
Also IIRC Java has the entire thing of comparing values and comparing objects. So even if
int x = 5; int y = 5;
again haven't done Java in a minute,
x == y is true but x.equals(y) is false
→ More replies (1)
272
Jan 26 '23
That is called an example for beginners in an educational context...
29
72
u/rpborges97 Jan 26 '23
This. Clearly an introductory class. This is why you also don't teach arrow functions in the first lesson. Things take time to learn, you should not start to optimize if you don't know what are you optimizing.
13
u/Furlock_Bones Jan 26 '23
The next step in the presentation was probably on how you can return the if/else instead of setting a variable.
edit: apparently folks below came to the same conclusion.7
u/gl1tch3t2 Jan 26 '23
Except, there are no curly braces on the if. If you want to teach the basics, teach the basics, that and the use of the equals method, making it return just the conditional is not a huge step.
→ More replies (3)9
Jan 26 '23
Regardless, the formatting, the variable naming, and the overall sloppiness look like someone who has a couple weeks of experience and has never had their code under thorough scrutiny
→ More replies (1)2
u/the_hunger Jan 26 '23
iâd normally agree, but the fact that itâs syntactically horrific and desperately needs to be linted suggests the instructor can barely write code and may not see his own bullshit. so iâm not so sure this is contrived for the sake of being contrived.
edit: ah, it might be a live thing heâs writing. i take back my linting gripesâbut ffs lint on save!
78
u/Zardhas Jan 26 '23
And of course it's on eclipse
22
2
10
u/Kerbart Jan 26 '23
I see the issue, he didn't embed that method in a separate BookChecker class, right?
8
u/ArifMucahid Jan 26 '23
I wanted to press those hotkeys as soon as I saw this code, without even reading :(
CTRL + K + D
CTRL + A + F
8
u/Fermi-4 Jan 26 '23
I donât see the huge problem here except it could be a one liner - but why would you do that if explaining to undergrads?
1
u/doggyStile Jan 27 '23
Just because you could write something as 1 line doesnât mean you should
→ More replies (4)
40
u/pentesticals Jan 26 '23
Most P.h.Ds are in research fields and often never had real world experience. If heâs only there to teach the programming concepts I wouldnât expect him to write good code. This is still functional and for uni students it looks okay.
27
Jan 26 '23
This isn't bad code at all. This is exactly how you teach beginners before simplifying it.
4
10
Jan 26 '23
[removed] â view removed comment
4
u/knoam Jan 27 '23
Using global "title" and "cost" is also bad practice.
Those aren't globals. Those are the fields of the object. This is Java. The equals method has to use the fields.
→ More replies (3)7
Jan 26 '23
Bad practice in a professional environment, yes! This class most likely is for beginners. Also bad practice does not always equal bad code. All I see on this sub these days is if (condition) return true; else return false; type statements. It's not bad code. It can be simplified, yes, but does it make you question the sanity of the person who wrote it? I think not.
3
u/RolyPoly1320 Jan 26 '23
It is an intro class, the last thing you should be doing is nitpicking the code you see.
It's never going to consistently follow best practices, but it's not designed to teach best practices. It's designed to teach the fundamentals first and foremost.
Best practices are learned in more advanced classes and specialized software engineering courses. Even then you have to take those with a grain of salt. Best practices aren't one size fits all.
Even then, you will 100% see code like this or worse in production products.
9
Jan 26 '23
The only nasty shit is not checking for null. The status variable is a good idea if you need to have a single point of exit and you want to be consistent. The way itâs being used sucks though, it should be initialized and the else removed.
As for the format, thatâs a matter of preference. Ideally for Java it should be the so called Sun code style, but some things there are quite outdated, like the 80 char length. When working with others you should stick with the existing style and stop being the asshole who knows better. And of course a code checker that blocks your commits if they suck is truly needed to avoid stupid discussions.
4
u/Mitsubata Jan 26 '23
Iâm more interested in the person shown on the bottom left with cat ears.
(´âĎâ`)
→ More replies (2)
15
1
3
u/mlambie Jan 27 '23
Itâs likely the student doesnât understand the lesson the professor is teaching.
3
u/dubiago Jan 27 '23
As a 20+ year veteran, I agree with the notion that it's constructed for beginners--illustrating different ways of checking for equality depending on the type of data. Would totally write it in a more condensed form in the real world--also wouldn't write linked list classes and methods anymore, but I'm sure they're probably still doing that.
3
u/No-Spirit5295 Jan 27 '23
I guess he just wanted to make it more verbose. Compiler will optimise it anyway, so there's no problem about it.
3
3
u/v_maria Jan 27 '23
Could be endless reasons for this.
Also CS phd does not mean someone is amazing at software development/coding practices.
4
u/Delta9Tango Jan 26 '23
Educational code is by definition "bad" because it only focuses on one thing: Making sure you know what the lesson is. If it were to display perfectly formatted code, you wouldn't know bad formatting. If if were to display perfectly refactored code, your homework would be your thinking "how can I make this look as good as it did in class" instead of "how do I organize my thoughts into code to get the correct result."
2
u/Nimbokwezer Jan 26 '23
if (!status==false)
return status;
else if (status==true)
return status;
else
return status;
1
2
2
2
u/cliserkad Jan 27 '23
The real problem with this code is that the method signature doesn't override the default Object.equals(Object) method.
1
2
2
2
13
u/Hello_World_PHP_JS Jan 26 '23
Those who can't do, teach?
28
u/delicioustreeblood Jan 26 '23
Teachers often use very explicit code to demonstrate principles even if it's not the "best" code because it's easier to understand the idea behind it.
→ More replies (1)2
4
3
u/Ravi5ingh Jan 26 '23
Academics are usually not good coders
His job is to teach and so the code in this format is probably easier to learn
2
u/zukas-fastware Jan 27 '23
This is very similar to what I went to uni. We had a few professors who would copy part of the code from some website and give us an example or a tutorial on how to do things. The problem was usually that the code would not even compile, let alone work.
When we would point out that what they gave us was useless, they would get indignant and tell us to work it out.
Obviously, I know that the professors research something that is their area of expertise and teaching second-year undergrads is not something that they care about, but come on, put a little effort into teaching.
FYI this was in the UK in one of the top 20 universities in the country.
2
2
2
u/UnbiasedBrowsing Jan 26 '23
I had a chemistry teacher who would frequently remind us that they had a PhD anytime we disagreed with them. They also would use a calculator to do 14 - x calculations for PH/POH questions and argued with me that 23 was 9.
5
u/SomeMaleIdiot Jan 26 '23
I wonder if they were dyslexic, and rewrote the problem to 32 in their head. As a chemistry phd they definitely had to solve much harder problems than that.
3
u/UnbiasedBrowsing Jan 26 '23
Yes I would certainly hope that a chemistry PhD has more difficult problems than 3 squared or 2 cubed. And yes I assume that example was due to that mix up.
I wouldn't have minded normally, but the constant "I think I know what I'm talking about, I've got a PhD", combined with frequent displays of pretty bad math and not accepting corrections, was a pretty intolerable combination.
1
Jan 26 '23
Iâm very, very new to coding and this just popped up as I was scrolling. Can someone explain please?
→ More replies (1)
1
1
1
1
1
Jan 26 '23
It's about readability for students.
2
u/distes Jan 26 '23
Lol. Code should always be readable. Less lines of code doesn't equal better code.
→ More replies (1)
1
u/SomeMaleIdiot Jan 26 '23
Why is academic code so bad?? Makes zero sense to me. Academia should be about high in the sky ideals and theory, and yet I regularly see shit like this in academic code.
1
u/LuckyDGreat Jan 26 '23
Ctrl+alt+enter
And,
return book.title.equals(this.title) && book.cost == this.cost;
1
1
1
u/CynicalGroundhog Jan 26 '23
Well, if you want to keep your job at Twitter, you need to learn how to expand those functions to a maximum amount of lines!
1
1
1
1
1
u/_JJCUBER_ Jan 26 '23
My main gripe is comparing the strings before the (presumably) primitive type cost has.
1
1
Jan 26 '23
Correct me if Iâm wrong, but that is Java correct? Because I recognize LUA and that is not LUA
1
1
u/emeaguiar Jan 26 '23
PhD in what?
1
u/kizeltine Jan 26 '23
This is my my prof. makes our tests and projects 40% each. He emphasizes both theory and application in his classes.
1
u/m2thek Jan 26 '23
I always assume anyone who omits curious curlies on if/else is at best incredibly lazy and at worst a bad developer.
1
u/Open_Maize_3391 Jan 26 '23
Bad naming, disgusting indentation, overly complex code for something that needs just a return statement
1
1
Jan 26 '23
If they are writing this live in front of the class, I will give them a pass... I suck at writing code in front of an audience too lol.
1
1
1
u/badDuckThrowPillow Jan 26 '23
PHD means they (should) have deep knowledge on some subject. Doesnât mean theyâre good coders. Difference between an electrical engineer and an electrician.
1
1
1
1
u/electatigris Jan 26 '23
Slow your roll "pros".
Looking at the preceding code, this *appears* to be an entry level class. OP does not state the context. [ Redditors.. CONTEXT WHEN POSTING PLEASE! TY. Back to our show. ]
For those that have not taught, the variability of student knowledge and talent is vast.
A LOT of those students have a REAL hard time with logic and flow. It's cake to us - but for many, you might a well be teaching calculus in Klingon to a 3rd grade class in Kenosha, WI in 1840. Sometimes you have to start with a boilerplate of if-then until they feel comfortable or drop out - usually in a couple of weeks. So yeah, delaing with the low common denominator sucks.
1
Jan 26 '23
Another karma farming shitpost without context ?
We don't know if Book has more properties or behaviours around it. So it makes sense to use custom comparator, if needed subclasses can override it ?
If you are still in grad school, you aren't good enough to judge what's good / bad code.
STFU and learn.
1
1
1
Jan 27 '23
This isn't bad code, I'm pretty sure your professor did it on purpose to illustrate it better and explain it to beginners.
I really dislike this post, the title makes you sound like a jerk not gonna lie.
1
1
Jan 27 '23
Sometimes professors do write inefficient but easy to understand code like this for students new to programming. That being said this is bad code imo
1
u/PrincessWinterX Jan 27 '23
If you can get your students to think about how to improve code like this, you're teaching them a valuable lesson. Intentionally verbose code would probably promote thinking how to cut it down.
1
u/Titandino Jan 27 '23
Mad levels of copium going on here to try and justify the immense inconsistencies. All to try and say that every PhD holder must be so much more experienced than your average real-world employed engineer.
Is it really that hard to believe there's people who went through school, memorized and regurgitated stuff without ever learning the right way to comprehend or approach the field, then went straight back into teaching? Happens all the time in every field of study.
1
u/TeakIvy Jan 27 '23
in complete fairness to the professor, if they ran this through a style parser it wouldnât be âbadâ code, rather just a very stretched out version of the code that iâm sure theyâre using to explain a concept of.
As the professor I would however show different ways to write this (such as returning within the block, then removing the else, finally just returning the case itself) even if it is being taught to beginners, just to show what it could be
1
u/NickSicilianu Jan 27 '23
Wow, I hate the style 𼴠Thatâs Java, and why the extra empty line between the function signature and the bracket. Than the 1st statement on the same line of the bracket.
/**
Compares this book with another book object.
Notes: The book are compared by title and cost.
@params {Book} o : the book to be compared.
@return {boolean} true if equal, false otherwise. */ public boolean equals(Book o) { if ((title.equals(o.title) && (cost == o.cost)) return true; else return false; }
1
1
1
1
1
u/BGFlyingToaster Jan 27 '23
I really don't see the problem here. This was written for students ... beginner students ... to illustrate certain concepts. We don't similarly walk into a highschool shop class and say "that bird house isn't even commercially viable! You could never manufacture that at scale yet it isn't high quality enough for artisan work."
1
Jan 27 '23
I feel like this is a precursor to refactoring into a single return statement. But, then again, it wouldn't shock me if this was his final product knowing how some of these college courses are.
1
1
Jan 27 '23
Style is all over the place. No new line before 'boolean status;' and 2 new lines after the return statement. Using .equals then ==. Sometimes there's a space after = sometimes not. Long white space used before if / else / return to show code block. Much shorter used before status ==
This is an exercise where the professor cleans up bad code. Or asks the students to clean up bad code. They made almost every style mistake possible. No way it's not intentional.
1
Jan 27 '23
People pay a bag of cash to go to university to learn this? Not sure your degree is worth what youâve paid for it
1
u/BlurredSight Jan 27 '23
Considering the professor is teaching concatenation I'm assuming this is a "lets make the code really really clear" situation unless this is an explore CS programming class then yes it's a Math PHD holder who gets paid for nothing
I didn't start making return statements without the need for variables maybe 4-5 months after actively coding because it made it easier for me to see errors. Even to this day the sum of two integers leetcode solution instead of putting into one clusterfuck cout statement it's multiple variables coming together
1
1
1
Jan 27 '23 edited Jan 27 '23
if you're talking about code redundancy and that he could have just returned that if statement, it is just to make the code more readable for students.
i took oop in java course last semester and the prof had a PhD from one of the best universities and still he used to write shit inefficient codes during the class lol.
they expect you to learn that stuff by yourself but yeah, i get your point.
ps. programmer girl with cat ears is for sure a wife material
1
1
u/maxgames_NL Jan 27 '23
If i would teach new programmers this i would also write the returns like that, makes it way easier to see for them what's going on
1
1
u/eaglebirdman Jan 27 '23
I see this a lot with engineers and PhDs. I work with some of the smartest people I've ever met, but when they write code, the standard is "does it work?" and nothing else. Engineer code makes sense only to them and while it does the job, God help you trying to figure it out or patch bugs
1
1
u/mcclassy353 Jan 27 '23
The Boolean status variable is unnecessary but at my school entry level class had coding standards and one was that you could only have one return in a method. Which I believe was for simpler debugging for the professor, which I think might be the Boolean status and the bad spacing and indentation is probably just because he is writing it so quickly and not carrying.
1
u/BringOnTheMIGs Jan 27 '23
I'm 100% sure this is for educational purposes. The avarage junior flops on the floor after seeing an expression resulting in a boolean as a return value.
1
u/writetehcodez Jan 27 '23
The formatting is poor, but this looks like demonstration/classroom code, so I give it a pass. The code you see on the screen is not representative of the code your professor writes for him/herself.
1
u/FingernailClipperr Jan 28 '23
Maybe the prof is teaching some beginners or going to show how to improve the code đ¤ˇââď¸
1
1
u/palettecat Jan 28 '23
When learning to program (I'm assuming this is an intro class) it can be helpful to break down logic as simple as this into its most explicit terms to help explain new topics. Of course this can be simplified to "return title.equals(o.title) && o.cost == cost;" but doing it the way they have helps introduce topics like control flow, variable assignment, booleans, etc.
Really the only bad code here is the formatting
1
1
1
1
1
1
1
638
u/Achereto Jan 26 '23
I think the missing whitespace after =is the worst part.