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.
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?
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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
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!
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.
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.
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.
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.
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.
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."
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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; }
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."
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.
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.
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
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
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
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.
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.
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.
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.
638
u/Achereto Jan 26 '23
I think the missing whitespace after =is the worst part.
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?
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.
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.
5
u/hotcrossedbunn Jan 26 '23
Whatâs so bad code here??
1.2k
u/crass-sandwich Jan 26 '23
Are those lace cat ears?
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.272
u/[deleted] Jan 26 '23
That is called an example for beginners in an educational context...
78
u/Zardhas Jan 26 '23
And of course it's on eclipse
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 + DCTRL + A + F8
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?
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.
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.
(´âĎâ`)
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/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.
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;
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.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?
4
u/[deleted] Jan 26 '23
phd in what?
3
u/Ravi5ingh Jan 26 '23
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.
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?
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.
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/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/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/DeC3x0 Jan 26 '23
Ph.D-
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.
/**
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/facorread Jan 27 '23
CS PhD?
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.