Jump to content

[Students] Teachers who write bad code

I'm working in a teacher's project right now.

It's a microcontroller c++ project, where he wrote all the peripheral classes and one "student" class.

The student class inherits from all the peripheral classes and we were told to write all our code specifically in this class.

 

The problem? The peripheral classes are weirdly programmed. We are expected to add delays but we are not given a peripheral interface to achieve this.

We are expected to do time aware calculations but are not given an interface to get any sort of time setting/information from the peripherals.

We are expected to do calculations before the process starts, but the student functions are called from the peripheral class after the process has already started.

 

Next to that there's no type consistency (A variable that is used for only one function is int16_t, whereas the function accepts uint16_t, and this is done a few times), and the writing style does not match the recommended code writing style - recommended by him.

 

Do any of your college professors do this? I'm going to talk to him about this tomorrow, but I was just wondering if this is a common thing or not.

Link to comment
https://linustechtips.com/topic/285168-students-teachers-who-write-bad-code/
Share on other sites

Link to post
Share on other sites

In a weird way this is a good thing. In school I found a lot of teachers just copied out of the book and served no purpose other than that. That said.. This guy is clearly incompetent.

The problem is I know he's really smart, which is probably the biggest reason this annoys me so much.

 

 

have you read the reccommend books, usually with course work style stuff you need to read alot to understand whats needed to be done. you no longer get handed stuff on a plater

Yeah dude, I completely know what's going on and stuff, it's just a lot of his assignments seem to contradict with the actual project code.

 

I know how to fix the issues, but the issues aren't in the segment I was explicitly told to work in.

Link to post
Share on other sites

well i had a teacher last year who coded extremely bad. among other horrors, he told me to put a break; on a for loop and he insisted on using unsigned variables (it's considered a bad practise)

The best way to measure the quality of a piece of code is "Oh F*** "s per line

Link to post
Share on other sites

What's so bad about that?

it's a bad practise, it makes the code harder to read and analice, if you are going to make an scape route in a loop, do it a while and include an if clause that given the circumstances, makes the condition false.

if you are making a for loop you asume that it will go through an specific amount of laps

The best way to measure the quality of a piece of code is "Oh F*** "s per line

Link to post
Share on other sites

I hacked my way around the issues. It's not pretty but it works. Contacted the professor and he said he understands why it was confusing. 

The way he wrote the assignment document made it seem like we had to use functions inside his base classes, but as it turns out, it wasn't supposed to be a pretty solution.

I guess I'm just too picky about writing code  :huh:

 

it's a bad practise, it makes the code harder to read and analice, if you are going to make an scape route in a loop, do it a while and include an if clause that given the circumstances, makes the condition false.

if you are making a for loop you asume that it will go through an specific amount of laps

So he made you use break; in a loop without it being inside an if-statement block?

 

unsigned variables can be useful; but only for integers of which I know they won't ever be negative, such as a sample count for an ADC. Especially if that one extra bits helps me keep the value within 16 bits, useful on microcontrollers.

I try to stay away from unsigned as much as possible, because it's too easy to start using them interchanged with normal integers and cause havoc all over the program.

Link to post
Share on other sites

You will learn that even when using the same language everyone writes code in their own way and similarly when you work you will find every company has a different way of doing things.

 

Your lecturers ways may seem odd to you but it can help prepare you for what you could be faced with in a work environment when your colleagues wouldn't like being told they are wrong.

Link to post
Share on other sites

So he made you use break; in a loop without it being inside an if-statement block?

 

no, obviously with it's correspondent if clause (where's the point of a loop if you are ading a break in the end?), however, i still mantain they make no sense in a for loop, or in any loop for that matter, adding a new condition to the while makes the code far more readable (coding is not only about eficiency but also about elegance)

The best way to measure the quality of a piece of code is "Oh F*** "s per line

Link to post
Share on other sites

You will learn that even when using the same language everyone writes code in their own way and similarly when you work you will find every company has a different way of doing things.

 

Your lecturers ways may seem odd to you but it can help prepare you for what you could be faced with in a work environment when your colleagues wouldn't like being told they are wrong.

This is very true. Up till now I've finished 4 large projects (half a year each) where we wrote code and managed it through SVN.

We always made clear how we programmed stuff; designed a class diagram, use case diagram etc before we started programming.

 

This is the first time I'm working with completely strange code with only some documentation. I now understand why programs should be made as maintainable as possible  :D

Link to post
Share on other sites

it's a bad practise, it makes the code harder to read and analice, if you are going to make an scape route in a loop, do it a while and include an if clause that given the circumstances, makes the condition false.

if you are making a for loop you asume that it will go through an specific amount of laps

 

Break is not bad practice. Like anything it can be used incorrectly, but it's absolutely vital for performance in some cases. A break is not hard to read, nor is it hard to follow with some practice whereas it can obfuscate the loop conditions to write them as a while loop and can lead to unnecessary variables in manually declared loop counter variables. When using a for loop you don't assume that it will go through a specific number of iterations, you say that it will do a maximum of the loop conditions iterations. For example in a linear search you might hit the element you're searching for at the first iteration. If the rest of the array had 3 million elements then you don't want to search the other 3 million unnecessarily.

Break is useful and necessary. Similar to the conditional statement, when used badly it can obfuscate code, but when used correctly it is significantly better than other approaches and refusing to use it is only hurting your progression as a programmer.

 

 

OP, I'd say the best way to go is to ask your teacher why something is written like that. I'm betting there's one of a few outcomes.

1. You're wrong and it's actually well written

2. The teacher is wrong and it is poorly written

2. a) The teacher recognises this and fixes it

2. b)The teacher disagrees and you have to deal with it

3. The code is intentionally poor to teach you a lesson

 

1. is quite likely in a lot of these cases because as someone is still being taught programming they are likely to miss things.

2. Is rather unlikely but I've seen it happen, one of my teachers didn't teach programming very well and didn't really understand how to design things very well. Recognising and fixing the issue or disagreeing depends on the teacher, can't comment on likelihood. If they disagree and defend their code when it is poor code is something you'll just have to deal with and take it in the same vein as 3.

3. In the real world, there is a lot of shit code out there and it will likely be your job at some point to refactor, maintain or interact with poorly written and designed code. It's good to get a lesson of that before you go into your job whether as an intentional lesson by your teacher or whether by 2b your teacher refuses to fix the code for whatever reason.

Link to post
Share on other sites

no, obviously with it's correspondent if clause (where's the point of a loop if you are ading a break in the end?), however, i still mantain they make no sense in a for loop, or in any loop for that matter, adding a new condition to the while makes the code far more readable (coding is not only about eficiency but also about elegance)

Misunderstood, sorry!

 

And yes, I understand where you come from. Only rarely have I had to use a break in a loop, and whenever I do use it, I feel bad about it. It doesn't look good, it doesn't feel good.

Link to post
Share on other sites

it's a bad practise, it makes the code harder to read and analice, if you are going to make an scape route in a loop, do it a while and include an if clause that given the circumstances, makes the condition false.

if you are making a for loop you asume that it will go through an specific amount of laps

 

One thing I forgot to mention is it really isn't any different to having multiple exit points in a method using return statements which also isn't bad practice.

Link to post
Share on other sites

I can't count the number of times I have corrected errors in code that the teachers provide or in the project specifications they write. This one professor in particular really ground my gears. The good thing was since I was ahead of the class I helped her cover her ass to the point that we were on a first name basis (out of her ~500 students that semester) and I may have benefited from some discretionary grading.

May your framertes be high and your remperatures low.

Link to post
Share on other sites

The problem is I know he's really smart, which is probably the biggest reason this annoys me so much.

...

 

Being 'smart' does not equate to being capable of producing good quality code and architecture. I've worked with some incredibly intelligent individuals over the years. Only a few of them were capable of producing well written code. It seems a rare combination to come across indeed.

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

it's a bad practise, it makes the code harder to read and analice, if you are going to make an scape route in a loop, do it a while and include an if clause that given the circumstances, makes the condition false.

if you are making a for loop you asume that it will go through an specific amount of laps

 

I don't think there's anything wrong with using a break statement in a for loop, as long as the exit terms are clear.

 

I've run into situations where the code only looks more like spaghetti or runs slower without the break.

 

 

he insisted on using unsigned variables (it's considered a bad practise)

 

Why is that considered bad practice? I've heard that before. Is it because of possible errors in comparison between signed and unsigned?

 

I think the only situation where I have seen a reason to use unsigned was when I was trying to do something by bit twiddling.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×