Venting - College Coding

Pages: 123
I myself would prefer something more like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main()
{
    int a = 10;

    if (a < 10)
    {
        std::cout << "Less Than 10";
    }
    else
    {
        if (a > 10)
        {
            std::cout << "Greater Than 10";
        }
       else  /////////////  Notice just plain else.
       {
           std::cout << "Equal To 10";
       }
}


or:

1
2
3
4
5
6
7
8
9
10
11
int main()
{
	int a = 10;
	
	if (a < 10)
		std::cout << "Less Than 10";
	else if (a > 10)
		std::cout << "Greater Than 10";
	else   /////  Again notice the plain else.
		std::cout << "Equal To 10";
}


I will quite often start with something like the first snippet and then simplify to something like snippet two after I have all the logic ironed out (although I most often use braces on most of my control statements).

But if your instructor states that if else() is not valid you should stick to snippet one for all classwork if you want to do well in the class.




I'm partial towards array-oriented solutions.
1
2
3
4
5
6
7
8
9
10
11
12
13
int signum(int n){
    return (n > 0) - (n < 0);
}

int main(){
    static const char * const s[] = {
        "Less Than ",
        "Equal To ",
        "Greater Than ",
    };
    int a = 10;
    std::cout << s[signum(a - 10)] << 10 << std::endl;
}
Beautiful. Should make the second and third 10 be a named constant, for maintainability!
Changing it means someone has to go out on a limb and risk failure.

Yeah, I get that, but in this particular case, upgrading the compiler is not a particularly failure-causing action (unless your CS department is stupendously incompetent).

"stability concerns"

That’s BS for “...which would also require us to upgrade other systems on our server, and we’re going for the ain’t broke angle here...”

Upgrading the compiler does also entail a lot of other upgrades, which actually can cause some systems maintenance, particularly with legacy applications. The consequences are:

  • potential downtime of one (or more) of the university’s servers

  • potential for loss of legacy application support that some professors require
    (possibly even by contract)

Both of those are somewhat red-herring issues, because both can be dealt with by a competent staff.

What you need to do is get enough students to complain that the people sitting in the offices might decide to direct the CS office to get some of it fixed during the summer.

Through Bobby, you connect to the ancient C++98 compiler

As a curiosity, how does one invoke said compiler? I think it odd that you can connect to “Bobby” without knowing that you are connecting to one of the university servers, and then use the compiler without knowing its name.

This is fairly standard fare for using systems like your university’s. If you go into the CS lab, they probably even have printouts for how you can go home and connect to the server using something like SSH and PuTTy.


...Now, take a few hundred dollars from that and use it to buy a licensed up-to-date compiler.

That was fairly tactless.

If your goal is to persuade the university to upgrade their systems to use a modern compiler (C++14 minimum), you have just started out by burning a bridge before crossing it. I’m certain you can find a better way to get People In Charge™ on your side — or at the very least, sympathetic to you.

Fail that and you’ll be the student that make people want to take a coffee break when you appear, and they will actively resist helping you.


Understand that this professor isn't some genius in what he does. He's a nice guy but not really good at teaching and doesn't seem to understand the concepts as well as he should. He's not a seasoned veteran or a professor who's brilliant to the point where I miss understand his intellectual wisdom.

When I correct his code the situation is usually like this. His code isn't doing what he wants but he doesn't know why. He stares at his code for up to 20 seconds. I finally just tell him what he needs to do, then he goes "Oh" or "You're right".

You are editorializing what is going on in your teacher’s mind in the worst way possible.

It might help you to reconsider the kind of things that might actually be going through his head. Maybe even something like:

  • These people don’t seem to be getting this. What else can I do to it to show them the
    logic this structure represents?

  • I should have prepared something to help step visually through this code.

  • Crap, they’re all looking at me and this one guy keeps wrecking my train of thought.

  • No one is saying anything. Does this mean the class is too stupid for them?

  • I should have prepared more material. People are bored. That girl in the back is falling
    asleep while texting her friends.

  • I’m not getting enough sleep. Two big essays, field work, outstanding labs to fix, and
    this dumb class with these outdated notes. How do I fix this stupid example to be more
    clear?

The point is, all you have to do is attend the class and feel smug. You have no idea what brings your teacher to the class, or what he is thinking.

I would consider it more productive and proactive to assume that he is really trying to help your class understand the material. And, as you have round-aboutly noted, most people are not conditioned to thinking logically like a computer, which makes teaching this stuff doubly-hard. Blank stares and a few people hanging around the office or after class to say they just don’t get it adds to the pressure.

I will agree that he is not presenting himself as a very good teacher. Teaching is a difficult skill that takes a long time to learn. He may feel over his head — not with the material, but with the task of teaching it.

Hint: in an introductory course, don’t spend time deviating from the prepared material except to clarify. Frankly, you are showing yourself to be inept at teaching* as well, so your judgement on what needs clarification is suspect.

*Which is not the same as sitting down with one or two people and showing them how to use <strings>.

Let him work through the material and see how it works out. Making sure other students are educated is not your job. You should feel perfectly free to assist outside of the lecture period — some people will even charge for tutoring — but don’t interrupt a lesson for small variations on a theme:

Speaking of which:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
	int a = 10;
	
	if (a < 10)
		std::cout << "Less Than 10";
	else
	{
		if (a > 10)
			std::cout << "Greater Than 10";
		else
		{
			if (a == 10)
				std::cout << "Equal To 10";
		}
	}
}
int main()
{
	int a = 10;
	
	if (a < 10)
		std::cout << "Less Than 10";
	else if (a > 10)
		std::cout << "Greater Than 10";
	else if (a == 10)
		std::cout << "Equal To 10";
}

Um... those programs are identical. [edit]Except the one on the left has better structure.[/edit]

I admit to being a little confused about the professor’s supposed shortcomings based only on an argument over these code snippets.

An “else if” is not a language construct in C or C++. Yes, you can chain words together like that, with meaning, but an if statement has the form:

    if (condition)
      true_expression;
    [else
      false_expression;]

The most apropos way to organize the structure is exactly as your professor has demonstrated for you. He even made sure to indent things logically and to use multiple-statement blocks, which is a highly-recommended habit to get into when coding in C and C++.

(He should, at some point, notice to the class that the final if (a == 10) is redundant, but he may not, considering it to be too elementary an observation to make explicitly.)


Sorry for the kick in the pants. Hope this helps you further your goals.
Last edited on
As a curiosity, how does one invoke said compiler? I think it odd that you can connect to “Bobby” without knowing that you are connecting to one of the university servers, and then use the compiler without knowing its name.

This is fairly standard fare for using systems like your university’s. If you go into the CS lab, they probably even have printouts for how you can go home and connect to the server using something like SSH and PuTTy.

I never had to do this before so it was all pretty new to me. But through Putty, as you said, I can connect to the compiler. When it opens up, it says Bobby is huge print, everyone calls it Bobby, and the TA kept saying "you'll run your code through Bobby" which to me sounded like it was the name of the compiler.

As a side note, apparently the compiler they have they're using for free. "since gcc is distributed under the GNU GPL, it doesn’t even cost hundreds of dollars for a license and is completely free to run, share, modify, etc."

That was fairly tactless.

Lets be honest, they were never going to change anything. If I tried to rally students, it would likely fall apart on me. I couldn't convince them to tell the professor to teach them strings so that they can actually do the lab (for the students who hadn't yet taken the lab). In the end I had to speak up and tell him so that he'd cover it. When I told the professor that we were using strings in the lab, he had no idea.

Teaching is a difficult skill that takes a long time to learn... *Which is not the same as sitting down with one or two people and showing them how to use <strings>.

Believe me, I know. It's something that a person can always improve at and learn from. Sitting down with a few people is more like a little private tutoring and they'll be more open to asking questions and easier to teach. But I have taught before to a class. It was math, anything I said was articulated in ways I knew they'd understand and no one seemed confused, though obviously I can't go into their heads. Setting aside natural ability and a multitude of talents that I have, one reason I can teach effectively is because I understood the material inside and out. This professor.. not really.

but don’t interrupt a lesson for small variations on a theme

I interrupted no lesson. I only get involved when he pauses for long periods of time not knowing what's wrong with his code. This was really the first time I even asked about anything and the interruption didn't last 10 seconds. If you're talking about me tutoring those students, it wasn't during a lecture, it was during the lab which the TA left us alone to code.

Um... those programs are identical. [edit]Except the one on the left has better structure.[/edit]

As I said earlier, I understand that. They do exactly the same thing, maybe the left one is structured better, but the right one has better readability. And if someone showed you these two pieces of code when you are just starting to code and coding seems like a whole new difficult world to you, which of those two samples would seem easier to read? I guarantee you that no one remembers even how to do the left one because they barely understand the basics of coding, which, yes, he did hopscotch through as if everyone was just gonna pick it up.

An “else if” is not a language construct in C or C++. Yes, you can chain words together like that, with meaning, but an if statement has the form:

I didn't think of "else if" as its own keyword as I mentioned earlier. I only thought that after he said that it doesn't work in C++. That made me think that it was its own function but, as you said, it's not.

The most apropos way to organize the structure is exactly as your professor has demonstrated for you. He even made sure to indent things logically and to use multiple-statement blocks, which is a highly-recommended habit to get into when coding in C and C++.

Funny, that was just an example I wrote to show what he did. The indentations, conditions, and everything were all what I did. He wrote his example on the board and didn't bother writing real conditions or anything. And his hand writing was super messy and he ran out of space by the end so he ended up writing it slightly sideways and tiny. Not only that, he always uses "using namespace std". He said himself that it causes bad habits but he's taught the whole class to use it. No one in the class even knows what it really does or that they'd need std:: in front of a lot of their functions.

So thanks for the compliment, I'm sure I'd be a great CS135 professor.

(He should, at some point, notice to the class that the final if (a == 10) is redundant, but he may not, considering it to be too elementary an observation to make explicitly.)

He did mention in a previous example how you wouldn't need the final condition if it'll be obvious what it is once you reach the end. However, I left the final condition because his example had an if statement at the end as well.

Moreover, he said you'd have to do that for as many conditions as you need. Notice 17 lines could be 11 lines. Over a period of more conditions, you'll have less overall code and better readability.

Sorry for the kick in the pants. Hope this helps you further your goals.

Don't worry, I have a gamer's reflex (between 100-180ms) so I was able to dodge. My goal at this point is to get to 85 and die.

On a more serious note, I do appreciate that you took the time to write. Thanks.

https://www.youtube.com/watch?v=oDAQY_0tUl4
Last edited on
@helios in the snippet you posted:
1
2
3
4
5
6
7
8
9
10
11
12
13
int signum(int n){
    return (n > 0) - (n < 0);
}

int main(){
    static const char * const s[] = {
        "Less Than ",
        "Equal To ",
        "Greater Than ",
    };
    int a = 10;
    std::cout << s[signum(a - 10)] << 10 << std::endl;
}

[signum(a - 10)] should be [1 + signum(a - 10)]
Because the function has a range of -1, 0, 1 but there are indexes only for 0, 1, 2

By the way.. thaz cool as hekk.
Oops. Yeah, I meant to do that originally, but I forgot.
Topic archived. No new replies allowed.
Pages: 123