Server Help

Non-Subspace Related Coding - My joke of a C++ class

D1st0rt - Sun Feb 04, 2007 3:56 am
Post subject: My joke of a C++ class
So I'm in a C++ class right now designed for Mechanical Engineers who have only ever used MATLAB up until this point for programming. Unfortunately, I actually have to learn stuff now because of this silly restriction I found in the course policy:



which is kind of a pain in the ass since I won't even be able to use stuff like sprintf which has nothing to do with displaying characters on the screen.

So the million dollar question is, is there anything I can do with the preprocessor to have stdio included without having the file contain "stdio.h"?
Mine GO BOOM - Sun Feb 04, 2007 5:21 am
Post subject:
Might I ask what he recommends instead? I know professors love cin/cout, which is not very often used by real programmers, but does he think that you should use a string class for everything? Are char arrays outlawed as well?

If he blames that they cause buffer overflows and are not type safe, you can either a) tell him to teach Python or Java, b) programming is all about making assertions and to be able to cope with them, be it due to the language being used or the data you are working with, or c) tell him about ISO/IEC WDTR 24731 (pdf) that deals with standardizing secure versions of strcpy/sprintf to prevent buffer overflows.

If you really want to have stdio type functionality without ever having called it directly or indirectly, just use wchar for wide-character support, which has all the same features of stdio, except for wchar_t instead of char.

Not allowing goto's is pretty good, as novices use it more often than they should, and there are much better ways to go about it than using them. There are exceptions to the rule of never using goto's, as one of my own personal projects uses them instead of being a recursive function and a for loop would be unwieldy and cause ugliness to enter the code more than a simple goto jump.

Only once you've programmed something complex in assembly are you allowed to use goto statements in C/C++. Removing char arrays and printf functionality is pretty harsh, but you just admitted that you don't program in C/C++ before you started this class. In the case of learning, as it seems that you won't use C/C++ very heavily in the future, just follow through with what the teacher requires. Use cin/cout and horribly slow string classes. It is not like you are programming for a system with 768K ram.
Bak - Sun Feb 04, 2007 11:29 am
Post subject:
Code: Show/Hide
#define LOLLERSKATES <stdio
#include LOLLERSKATES.h>

D1st0rt - Sun Feb 04, 2007 12:52 pm
Post subject:
Ah, thanks Bak. I had been trying that with "s instead of <s

Yeah, we're using cin and cout. Haven't gotten to anything yet that requires actual string manipulation, though I would have preferred to be able to use stdio for formatting. I never said I hadn't programmed in C/C++ before, just that the class was designed for people who hadn't.
Mine GO BOOM - Sun Feb 04, 2007 2:07 pm
Post subject:
Then just tell the teacher you have C/C++ experience and would like to use stdio. In every one of my programming classes, I used scanf/printf and never cin/cout. Teacher never cared, because I checked my inputs to make sure it could never allow the program to enter an unknown state, and because the code looked very clean and usually had more features than was requested.

Reminds me of math teachers that required me to show work. Nope, I just threw down an answer, sometimes with a line or two scratched down if I needed it. Every math teacher complained up front, but when I handed in the test a full fifteen minutes earlier than anyone else, it usually calmed them down and stopped marking points off for not showing work. You just need to show the teacher you are competent enough early, and you can generally do things your way.
Muskrat - Sun Feb 04, 2007 6:38 pm
Post subject:
In all my math/physics classes the answers were usually optional, they want to see that last step with pure variables. How do you do proofs?
SamHughes - Sun Feb 04, 2007 10:00 pm
Post subject:
You're whining about what library you have to use for output.
Animate Dreams - Sun Feb 04, 2007 10:32 pm
Post subject:
SamHughes wrote:
You're whining about what library you have to use for output. Get a life.

And here's one sentence of useful informativeness. If you wanted to use sprintf, use std::stringstream, which is a good substitute. I now prefer that to sprintf. Or implement your own printf and sprintf functions just to spite them. But why wouldn't you want to use the std::string class? It's easy and it's your friend. And if you're going to be a library bigot, I recommend avoiding programming for the rest of your life.


I guess you were rooting for the Bears? Calm down, I think D1's problem is that his professor is a library bigot, not the other way around.
SamHughes - Sun Feb 04, 2007 11:05 pm
Post subject:
What are the Bears? Please don't take me too personally, or yourself too seriously. The professor may have made that rule for a good reason, so that TAs don't need to be familiar with stdio libraries. iostream is much simpler, much easier to grade, and much easier to help students with, and much easier to teach.
Dr Brain - Mon Feb 05, 2007 8:56 am
Post subject:
iostream is also more efficient, though it's been many moons since I've used C++.
Cyan~Fire - Mon Feb 05, 2007 11:17 am
Post subject:
Darnit. I was so glad none of the Java acolytes had posted here, but looks like I celebrated too early.

iostreams more efficient? No. I can tell you for sure that switching from iostreams to stdio both decreased the size of one of my apps and increased the speed of a large file load.

Simpler? Easier to grade? These go together. Which of these is easier to understand?
Code: Show/Hide
cout << "Freq " << freq->id << " has " << freq->flagcount << " flags!";

Ahh, did I put all the spaces in the right place? Man, just glancing at this line I can't get a good idea of what it outputs anyway. Too many symbols and interruptions in the string.
Code: Show/Hide
printf("Freq %d has %d flags!", freq->id, freq->flagcount);

Nice and simple.

Easier to help students with? Easier to teach? Yep, as MGB said intro professors love this stuff because it's easy to teach. That's all.

If you want easy, use Java.
Animate Dreams - Mon Feb 05, 2007 11:23 am
Post subject:
SamHughes wrote:
What are the Bears?


The guys who lost the super bowl. I figured, since you were so pissed off with no actual logical reason, you must have lost some bet on the Bears.
D1st0rt - Mon Feb 05, 2007 1:20 pm
Post subject:
It's an automated grader, which is what I had a beef with because if it finds stdio.h in the file it spits it back and won't grade it.

I can see teaching iostream, but not preventing people who are more used to stdio from using it.
Smong - Tue Feb 06, 2007 5:43 am
Post subject:
If you use that << gibberish don't you also have to use weird wrapping functions to format decimal places and add left/right padding?

I don't use C++ much but aren't you able to leave off the .h on includes? Like:
#include <stdio>
I guess that would load some special C++ version of stdio.h. I've never tried it myself so I may be talking more gibberish biggrin.gif
Cyan~Fire - Tue Feb 06, 2007 1:00 pm
Post subject:
You're right on all counts, Smong.
SamHughes - Tue Feb 06, 2007 5:36 pm
Post subject:
That would be #include <cstdio>.
Animate Dreams - Fri Feb 16, 2007 12:03 pm
Post subject:
Um, my professor just gave us a lecture on programming languages. He started off by proclaiming C++ to be the hardest language out of 200 possible programming languages. Which after I think about it, it's possible, but it just makes him sound extremely biased. He followed up by explaining that C++ programmers get the highest wages(which if you believe the Stroustrup interview, both of these things make sense, I guess...), but we shouldn't put TOO much stock in the language, because C# is the best language that exists. He's currently encouraging all of us to take his C# class next semester... um. Now he's telling us we aren't even going to learn to program in this class. Apparently he doesn't teach us how to program until the C# class. -.- Sometimes, I feel like a clown is going to bust through the door and explain that the CS major here was just a joke, give us our money back, and send us home. >_> Is this how class is for the rest of you guys?
Bak - Fri Feb 16, 2007 12:47 pm
Post subject:
I actually wish they taught programming concepts independent of languages, as lots of things would make sense and therefore be easier to learn once you understand them, instead of just memorizing everything and then figuring out the "why" afterwards.
Animate Dreams - Fri Feb 16, 2007 6:43 pm
Post subject:
Bak wrote:
I actually wish they taught programming concepts independent of languages, as lots of things would make sense and therefore be easier to learn once you understand them, instead of just memorizing everything and then figuring out the "why" afterwards.


I've come to think this way too. But is such a thing even possible? That's learning communication without learning any of the forms. I mean, can you really learn anything without an instance of that thing to understand? Heck, I can't even figure out how to word the question correctly. Anyway, if you find anyone's written a book like that, let me know....
SamHughes - Fri Feb 16, 2007 9:48 pm
Post subject:
Bak, what do you mean? What would a course teaching programming concepts end up teaching, and what are you referring to by "just memorizing everything"? What's there to memorize?
Bak - Fri Feb 16, 2007 10:33 pm
Post subject:
hmm I guess it would start at a lower level, then build the language from the bottom up.

like rather than learning the syntax for do while loops, you learn the pseudo-assembly equivilent, then learn how the C abstraction works.

I just remember when learning coding always getting messed up with the syntax, but that's not really what coding's about
SamHughes - Fri Feb 16, 2007 11:47 pm
Post subject:
If you don't want syntax, maybe Scheme? Have you ever taken a look at
http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/ ? But I don't think that's the best introductory course for most colleges. Not even for MIT, which is why they're changing it.

I would agree with the pseudo-assembly language idea. This would force students to use abstractions as a mental model, not a physical thing they write in code.

The first time I tried learning C++, I got bogged down when the book started mentioning stuff like cout.setf(ios::fixed). It was a big WTF. So I gave up on C++, and instead learned programming in Reverse Polish Lisp, on a handheld calculator. That's a stack-based programming language, like Forth and Factor, and like the pseudo-assembly language idea, it forces you to keep your abstractions in your mind, not in code. Then again, the C++ book I had was very bad. CompSci II with Koenig & Moo and Stewart was much better.

Which would be better for a starting language, a stack-based language or an assembly language? I don't see the point in having students manage registers, so I'd go with a stack-based language. I'd bet the Factor language would be a good starting language. I don't think this is a very good "tutorial", but here is one. http://factorcode.org/responder/help/show-help?topic=tutorial . It is a high level language in one sense, but in another sense, it is low level in that students will have to think in a concrete, low level fashion.
Muskrat - Sat Feb 17, 2007 12:21 am
Post subject:
I think the introductory courses should center on a transition from math and stress the connection by maybe starting with some mat lab type coding. That way people will have a better way of understanding where functions come from and how to build algorithms. Besides, the logical thinking involved in math is very much a prereq to understanding formalized language structures.
SamHughes - Sat Feb 17, 2007 12:49 am
Post subject:
Maybe. But I have to stop when you say "mat lab type coding". That would cause irreparable brain damage. But the general principle... how would you structure the course? What would its table of contents be?

By the way, where do functions come from?
Bak - Sat Feb 17, 2007 3:25 am
Post subject:
You could even do simple things like unary adders with turing machines, computing factorials using abacus machines or designing a binary adder circuit. After doing these a few times you learn to think about problem solving with the tools you're given, and can understand why modular code is a good thing.

Unfortunately it would probably be discouraging to take a computer science course and not learn how to code a real language, as Animate Dreams undoutably feels about his non-programming CS course. It would probably work best to mix in practical programming in a real language with the more abstract stuff, plus it would give students a good foundation for CS theory.
Animate Dreams - Sat Feb 17, 2007 7:53 pm
Post subject:
Actually, Bak, my course is kind of the opposite side of the same token. We're learning the language, without learning how to program. I would like to learn one of two ways. One being where they teach us how to program in C or C++ or something like that, and they teach it to me so I can actually use it. Or, they teach it to me from the bottom up(the preferred method), and teach it in such a way that afterwards, I could teach myself a language. So instead of learning programming, I'm learning how to learn how to program. They seem to have taken the third option, teach me a language but no actual programming, so I can't do squat. And it's done in such a way that it helps me none at all when it comes to me trying to learn programming on my own. Programming ought to be taught as a vocation, the way I see it. If college wasn't free, I'd've dropped out by now, no way would I pay to learn absolutely nothing. >_>
Cyan~Fire - Sun Feb 18, 2007 1:02 am
Post subject:
Uninspired CS professors seem to save the programming for later, after you've learned more of the language. It's stupid.
Animate Dreams - Mon Feb 26, 2007 11:30 am
Post subject:
Haha, I just found my professor's powerpoint slides and assignments for his C# class he keeps advertising. Now I have something to do during C++ labs. Other than reading this forum. <_< You know, if I go ahead and do the assignments now, I bet I could take that class, and just show up for tests. I guess I should check to see if he takes attendance first.
Anonymous - Tue Apr 17, 2007 9:20 pm
Post subject:
Use streams if you are coding in c++. They are very nice.
Animate Dreams - Tue Apr 17, 2007 9:24 pm
Post subject:
unknown1988 wrote:
Use streams if you are coding in c++. They are very nice.


So are dates on posts.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group