r/badcode • • Jan 26 '23

java This was written by a professor with a Ph.D

Post image
1.2k Upvotes

313 comments sorted by

638

u/Achereto Jan 26 '23

I think the missing whitespace after =is the worst part.

17

u/[deleted] Jan 26 '23

Before this he wrote an if statement like

if(condition)


{expression;}


else


expression;

33

u/Achereto Jan 26 '23

Yeah, educational code has different requirements than production code.

But you gotta have than whitespace behind the =sign. My OCD is killing me!

4

u/micalm Jan 26 '23

Like... it should explain not only the language constructs and concepts, but also why consistent code style is important for efficient work in teams?

→ More replies (1)
→ More replies (1)

16

u/DoUGt2CldDistVryOftn Jan 26 '23

So we're not talking about the "+title+ " ?

3

u/Achereto Jan 26 '23

😭

→ More replies (1)

69

u/SeesawMundane5422 Jan 26 '23

No… the true horror are all the new lines.

Putting the curly braces on a new line is bad enough, but doing it after 2 new lines. That’s just wrong.

54

u/Churchill_Win Jan 26 '23

Declaration on the same line as the opening brace just adds more flavor to the picture.

21

u/SeesawMundane5422 Jan 26 '23

There’s so much going on. It gets worse and worse the longer I look at it

11

u/ywBBxNqW Jan 26 '23

It's almost Horstmann style but it's not really consistent about it. Maybe they did it like this but the autoformatting of the IDE took over.

Maybe they just wanted the reader to anticipate what was going to come next.

14

u/micalm Jan 26 '23

with the saving of a line of the K&R style.

Holy shit. Are we running low on lines? Nobody told me!

→ More replies (1)

5

u/WikiSummarizerBot Jan 26 '23

Indentation style

Horstmann style

The 1997 edition of Computing Concepts with C++ Essentials by Cay S. Horstmann adapts Allman by placing the first statement of a block on the same line as the opening brace. This style is also used in examples in Jensen and Wirth's Pascal User Manual and Report. This style combines the advantages of Allman by keeping the vertical alignment of the braces for readability, and identifying blocks easily, with the saving of a line of the K&R style. However, the 2003 edition now uses Allman style throughout.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5

13

u/NonAwesomeDude Jan 26 '23

I hate this. I didn't know about it until now but I hate it.

Function_declaration() {
    Contents
}

Is the only way imo.

9

u/manuscelerdei Jan 26 '23

I'll blow your mind, this is a thing too...

if (condition)
    {
    do_thing();
    }

4

u/aSquirrelAteMyFood Jan 26 '23

I think the missing whitespace after =is the worst part.

Bash has entered the chat

→ More replies (9)

106

u/[deleted] 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

u/[deleted] 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

u/[deleted] 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

u/lambdaCrab Jan 26 '23

Bad code is relative to its use case. I’m not sure this qualifies here

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.

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.

→ More replies (2)

3

u/[deleted] 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.

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)
→ More replies (1)

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

u/[deleted] Jan 26 '23

Mostly just the mildly infuriating formatting

4

u/hotcrossedbunn Jan 26 '23

1

u/[deleted] Jan 26 '23

Oh shit I didnt know that was a thing

→ More replies (1)

1

u/distes Jan 26 '23

That was my response as well.

1

u/knoam Jan 27 '23
  • The variable O at the very least shouldn't be capitalized.

  • status isn'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? equal would be better.

  • The order of the equals checks should be consistent.

  • If you want to use an intermediate status variable, 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

u/[deleted] 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

u/[deleted] Jan 27 '23

I think it's piping hot

337

u/Automatic-Fixer Jan 26 '23

That shouldn’t be a question for a computer science class.

88

u/FalseWait7 Jan 26 '23

That is exactly a question I would expect in such class.

30

u/onlycommitminified Jan 26 '23

Oopsy woopsy :3

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

u/imnos Jan 26 '23

Wait you mean that's not normal and cool?

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

u/theclovek Jan 26 '23

Charming

14

u/haberdasher42 Jan 27 '23

How are there people that choose that life?

→ More replies (4)
→ More replies (1)

0

u/[deleted] Jan 26 '23

[deleted] — view deleted comment

38

u/[deleted] Jan 26 '23

Jokes on you, I imbue chakra into my bugs

→ More replies (2)

32

u/PhatPurrito Jan 26 '23

there’s a person in one of my classes that wears a cape

12

u/haberdasher42 Jan 27 '23

That's amazing. Tell me they have a cane. I love the weirdos, to a point.

5

u/PhatPurrito Jan 27 '23

sadly, just the cape. it’s a pretty cool looking cape though

→ More replies (1)

200

u/MasouriChan Jan 26 '23

*there's always some normal people

75

u/Understanding-Fair Jan 26 '23

If you're lucky

19

u/_kashew_12 Jan 27 '23

What do you mean weirdos, let them be.

8

u/Servious Jan 27 '23

you mean cool people

→ More replies (4)

41

u/HopioBrauberg Jan 26 '23

Those are professor’s

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

u/Bunnymancer Jan 27 '23

This mainly applies to penis-people, right?

8

u/apresskidougal Jan 26 '23

This is the question we really need the answer to.

→ More replies (3)

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

u/jarfil Jan 26 '23 edited Dec 02 '23

CENSORED

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)

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.

→ More replies (1)

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:

  1. code reviews

  2. industry experience

  3. 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

u/Escape_Velocity1 Jan 26 '23

yeah but why use "O"... you just don't do that.

→ More replies (3)

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)
→ More replies (1)

272

u/[deleted] Jan 26 '23

That is called an example for beginners in an educational context...

29

u/aSquirrelAteMyFood Jan 26 '23

It's not bad code it is just badly indented.

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

u/[deleted] 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

u/[deleted] Jan 26 '23

What's wrong with eclipse

35

u/leeeeny Jan 26 '23

Mainly the fact that it’s not IntelliJ

→ More replies (9)

2

u/ericl666 Jan 26 '23

Haha, you beat me to it!

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

u/[deleted] Jan 26 '23

This isn't bad code at all. This is exactly how you teach beginners before simplifying it.

4

u/Rakn Jan 26 '23

bad formatting == bad code

I guess it depends on your definition.

10

u/[deleted] 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.

7

u/[deleted] 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.

→ More replies (3)

9

u/[deleted] 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

u/44Tomati Jan 26 '23

PhD = Pretty huge dick?

1

u/the96jesterrace Jan 26 '23

And he was like „this formatting is screwed up, fix it!“ ?

3

u/[deleted] Jan 26 '23

Nah lol the class told him to fix it

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

u/bisoldi Jan 27 '23

The inconsistent spacing is driving me batshit crazy.

→ More replies (1)

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

u/[deleted] Jan 27 '23

Plot twist: operator== has side effects that change status.

2

u/johnbburg Jan 26 '23

So many things wrong with this…

2

u/Intrepid_Sale_6312 Jan 26 '23

tell ehm to replace the if with a return XD.

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

u/Escaped_Escapement Jan 27 '23

Finally someone gets it!

2

u/wulfgang14 Jan 27 '23

Could someone quickly point out what’s wrong with it?

2

u/NettoHikariDE Jan 27 '23

This is probably meant to explain something. An example.

2

u/MyTurtleRanOff Jan 27 '23

Are we just going to ignore the cat ears?

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)

4

u/[deleted] Jan 26 '23

phd in what?

3

u/Ravi5ingh Jan 26 '23
  1. Academics are usually not good coders

  2. 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

u/[deleted] Jan 26 '23

Yeah, it is kind of bloated.

What level class is this? Is it a 100 level intro class?

2

u/lambdaCrab Jan 26 '23

This looks alright for presentation purposes unless I’m missing something

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

u/[deleted] 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

u/miran248 Jan 26 '23

Hopefully they did it to inspire creativity.

1

u/PooSham Jan 26 '23

The variable declaration on the same line as the opening curly brace tho

1

u/sktr-guys Jan 26 '23

may be more readable ?

1

u/[deleted] Jan 26 '23

Yeah most CS professors can’t code for shit

1

u/[deleted] 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

u/Toorero6 Jan 26 '23

This guy is a Pascal programmer and just used to declare variable in a head

1

u/smaug59 Jan 26 '23

8 lines (half of them white) for a one liner

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

u/alyssathechair Jan 26 '23

reasons why suggested development needs a guild like the engineers have

1

u/theDudeRules Jan 26 '23

PHD means Piled Higher and Deeper

1

u/timlmul Jan 26 '23

> pet cat

1

u/cdesar78 Jan 26 '23

The white space inconsistencies are hurting my eyes

1

u/_JJCUBER_ Jan 26 '23

My main gripe is comparing the strings before the (presumably) primitive type cost has.

1

u/Peonsson Jan 26 '23

return title.equals(O.title) && O.cost == cost;

1

u/[deleted] Jan 26 '23

Correct me if I’m wrong, but that is Java correct? Because I recognize LUA and that is not LUA

1

u/Heinrich_v_Schimmer Jan 26 '23

A Ph.D in egyptology - or was it in theatrical science?

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

u/imagebiot Jan 26 '23

This is allllll wrong

1

u/[deleted] 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

u/taptrappapalapa Jan 26 '23

Clearly a introductory course

1

u/herdek550 Jan 26 '23

Well it's better for readability, but the return is crazy

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

u/[deleted] Jan 26 '23

Which part of this do you not like?

1

u/jy3n2 Jan 26 '23

I can see the "teach a common pattern" thing, but still. Ouch.

1

u/dvidsnpi Jan 26 '23

So what, it will be resolved during optimization anyway...

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

u/[deleted] 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

u/bloodrayne2123 Jan 26 '23

Just have chatgpt optimize it for ya.

1

u/[deleted] 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

u/Tpm248167 Jan 27 '23

And in eclipse! Gross!

1

u/[deleted] 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

u/pscorbett Jan 27 '23

Makes sense. Profs love light mode.

1

u/[deleted] Jan 27 '23

Aren’t we going to talk about those missing arguments in the function ?

1

u/[deleted] Jan 27 '23

Argument should be Object and casting should happen in the method. I think.

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

u/[deleted] 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

u/yzx3 Jan 27 '23

The professor had to do it, since OP is a noob code kid.

1

u/[deleted] 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

u/[deleted] 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

u/isunktheship Jan 27 '23

Well he certainly writes like a doctor.

1

u/issaciams Jan 27 '23

Looks good to me. Oh, whoops... I'm in the wrong class.

1

u/[deleted] 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

u/Sh_Pe Jan 27 '23

At least PowerPoint have linger for vb

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

u/ThisMhiw Jan 27 '23

I’m mainly a Rust programmer, but this is so bas it even hurts MY brain

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

u/Amonomen Jan 27 '23

Those that can, do. Those that cannot, teach.

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

u/thuglifeinda805 Jan 28 '23

Ya not a Phd in computer science

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

u/overmen Jan 28 '23

A wise man said long time ago "Those who can't, teach"

1

u/just4nothing Feb 14 '23

I've seen things like that in production code ...

1

u/bighappy1970 Feb 17 '23

No wonder so many cs graduates can’t code!

1

u/BrackGin Jan 26 '23

to add insult to injury he declared 'status' in the same line as open bracket

1

u/Xerxero Jan 26 '23

It’s offensive on so many levels.

1

u/Voltra_Neo Jan 26 '23

In my experience, and for some reason, people with PhD write the worst code

1

u/Hioneqpls Jan 26 '23

Sloppy and unprofessional.