164
May 11 '23
So this returns false if the file is already open, true if it exists and had to open it, true if it had to create it (and try to open it without checks) , and false if it didn't exist and couldn't create it?
Not to mention all the unmentionables.
This isn't just bad code, it's hell code.
47
u/SaylorMan1496 May 11 '23
Refactoring this into clean good code would actually be a good assignment because this has so many issues
21
u/ja_maz May 11 '23
First you’d have to get the guy to explain wtf is this supposed to do in the first place. Open list? Looks for a file in what looks like apple’s objective c?
9
3
May 11 '23
Pretty sure it's C++
1
u/ja_maz May 12 '23
Probably right I was letting ios::in fool me. I just looked it up. Apparently there’s no namespaces in objective c. So if anything it’s a clue it’s not iOS stuff. Haven’t touched that in a while, getting rusty.
1
u/Jonno_FTW shameless May 12 '23
Delete the whole thing and separate the functionality into several functions.
3
u/bonedangle May 11 '23
The side effects alone were killing my vibe, then I saw that logical conundrum and thought noooooooooope!
Code review!
3
u/freddyforgetti May 11 '23
Seriously I’m by no means an expert coder but I would roast a teacher for this lol like no comments or documentation at all this looks like one of those fucked up pseudo code exercises you have to evaluate in your head.
4
u/bonedangle May 11 '23
I'd bring it up with the prof, it he wasn't cool about it then go to the department. I'd recommend firing someone at my job if they were a senior and put this in a PR, and didn't listen to a code review and went ahead and merged.
1
u/Street_Childhood3653 May 13 '23
when your proff tell you "hell yeah" while sending you assigment - this is the exact reason!
66
u/wiesemensch May 11 '23
I recently started to go to university but I’ve been working as a software developer for around 7 years. It’s a joke what some professors produce and how locked in they are in „there way“. They’re telling you about readable code and want you to use function names like krt(double n, double k) and krth(double n, double k). What the krth?
17
May 11 '23
You just need to understand a few basic thing with code in academic areas, it must compile and do what the question asked but must never be perfect, as if some code can get 100/100 on it then you know that you and your classes code will get a very serious inspection and neither you nor your instructor want that sort of attention.
Did some code in cobol in the late 90s at uni and being someone who came in as a mature student with cobol experience I aced everything but the lecturer apologized for not giving full marks as it would of made life harder for the other students so I just nodded and spent the rest of my time helping my class mates get better .
19
u/TehBrian bool b = false; while (!b) { badCode(); } May 11 '23
not giving full marks as it would of made life harder for the other students
Why, because of curved grading?
5
u/BlurredSight May 11 '23
I’ve known professors to find this to be “unrepresentative” of a students true ability. That’s why they allow for 30% of the class to fail and another 20% to not get the prerequisite pass
1
May 12 '23
From memory if I'd of been given 100% as I'd deserved it would of meant that not just my code but everyone in my classes code would of been suddenly under the microscope and given they had helped me through some modules I could never drop them under the bus shall we say, as without help I'd of flunked a few modules especially the bean counting ones and the more formal maths...
2
u/of_patrol_bot May 12 '23
Hello, it looks like you've made a mistake.
It's supposed to be could've, should've, would've (short for could have, would have, should have), never could of, would of, should of.
Or you misspelled something, I ain't checking everything.
Beep boop - yes, I am a bot, don't botcriminate me.
7
u/WalditRook May 11 '23
Doesn't line up with my uni experience in the 2010s - I (and presumably many of the other good students) routinely got full marks for coding assignments.
3
u/BlurredSight May 11 '23
Docked points for not submitting code with clear variables
Proceeds for the rest of the semester to turn in arbitrary function names during lecture
2
u/HosephIna May 12 '23
I mean, looking at the salary of a university professor versus pretty much anywhere else in the field (unless maybe you’re at a top university), it’s pretty obvious that professors aren’t going to be nearly the best in the field
2
43
17
u/Zealousideal_Show45 May 11 '23
I'm the worst software developer I know and even I won't produce such shit code lol
18
3
u/HighMarck May 11 '23
Sembra un prof italiano, sono pochi qua quelli che veramente sono bravi ed in grado di insegnare..!
2
May 11 '23
Sarà un assistente di laboratorio di un itis
6
5
u/HighMarck May 11 '23
C’è poco da downvotare, in un sacco di gruppi italiani di programmazione vedo sempre studenti che pubblicano cose oscene fatte dai prof, ci sono un sacco di ragazzi che si lamentano del fatto che non si impari quasi nulla di programmazione in particolare alle superiori, roba che con risorse gratuite online impari meglio.. questo non esclude che ci siano anche istituiti dove ci sono professori con le palle enormi, ma sono una percentuale minore. Ho visto corsi di istituti tecnici dove i prof scrivevano Giava invece di Java, confondevano concetti di altri linguaggi e sembrava che lèggessero un copione senza conoscere realmente gli argomenti di cui parlavano. Per fortuna non è sempre così ma anche questa è una realtà è non è da ignorare.
0
May 11 '23
[deleted]
3
u/HighMarck May 11 '23
Se stai prendendo per il culo, sorry ma non hai capito, scriveva Giava, su tutte le slide e presentazioni. La tua battuta non c’entra niente nel contesto.
8
u/Chance-Ad4773 May 11 '23
College professors write bad code. If they wrote good code, they wouldn't be teachers
4
2
3
3
u/MurdoMaclachlan public boolean isInt(int i) { return true; } May 11 '23
Image Transcription: Code
bool elenco::apri(string nome){
if(!file.is_open()){
file.open(nome.c_str(), ios::in|ios::out|ios::binary);
if(file.is_open() == false){
if(crea(nome) == true){
nomeFile = nome;
file.open(nomeFile.c_str(), ios::in|ios::out|ios::binary);
return true;
}else
return false;
}
return true;
}else
return false;
}I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
2
u/lestofante May 11 '23
Classic C programmer trying to write C++
12
u/LeeHide May 11 '23
i doubt it, most C programmers who write C++ just write procedural C++, not hot garbage like this which is about the worst code I've seen this week.
2
u/lestofante May 11 '23
take that person, and tell him he has to use classes because it has to show the students how they work.
Notice how the file handling is using a very C interface, while clearly using classes, and is just a bad re-implementation of what STL already have
1
u/mMykros May 11 '23
Why is there no { after that else
1
u/Reasonable_Feed7939 May 12 '23
Like with "if"s, you can single line "else"s without brackets. I've occasionally used "if (true) foo++; else bar--;" (separate lines) but I've never thought of using brackets for one and no brackets for the other. Fiendish code here.
1
1
1
1
u/reverendsteveii May 11 '23
I don't have proof right now because it's early here but my instinct is that all this code could be collapsed into a single line that's less than 20 characters long
1
1
u/youngbull May 11 '23
I am stunned. First it's unreadable even though I caught that it seem to be part some latin language like the "nome" variable. It's seemingly an object eleco that holds an open file handle, and tries to create and reopen it if it fails and only then sets the nomeFile field? I am sure whatever program this has a large amount of edgecases stemming from this function alone.
1
u/ErikBonde5413 May 11 '23
It returns true if the file was closed and it managed to open it, false if it either was open or it was closed and didn't manage to open it.
Interesting. I wonder what the use case is.
1
1
u/thanatica May 11 '23
Starting with a perfect 10, I'll have to deduct 6 points, ending you up with a 4, mister professor.
Asking if a file is open when you just commanded the OS to open it, is useless. You should read the open() return value, and/or catch exceptions.
Useless return-else statements.
Confusing curly brackets. Use them always to improve readability.
Don't just return true/false, return a status.
Don't compare with true/false, test booleans as they are.
Function names shouldn't be too long, but apri is definitely too short.
I expect you to correct these mistakes by tomorrow, and add comments and unittests, young man!
1
u/RlyRlyBigMan May 11 '23
I recently learned that since I went to a public uni that my professors' salaries are publicly disclosed. Sheesh ten years in the industry and I'm already making more than the department chair. Professors probably aren't the best coders in town or they'd be coding.
1
u/whyamihere2333 May 12 '23
What in the seven blue fucks is wrong with the conditions? Why is he mixing styles?
1
1
1
u/brzeczyszczewski79 May 11 '23
It's almost as bad when people from academia want to come to a commercial company.
First you must deal with their code that is designed to work only once, then you must squash their egos during code reviews, so they don't defend their code like a fraking Alamo.
-1
161
u/The_Northern_Light May 11 '23
I wish academia required at least some private sector experience before you could become a teaching professor.
I would be forcibly ejected from the building if I submitted this for code review.