About teaching/learning C++

Pages: 123
Rand... now there is something that I could happily see thrown in the garbage.
Qsort as well. Those work in c++ because they are inherited from C. They don't belong.

If it is up for a vote I'd say "yah" to this, and add something else that needs to be giving the heave-ho when it comes to teaching newbies:

using namespace std;

Still would expose students to rand/srand and qsort. Just not abuse newbies with it as is done now.
I'd say I slightly misspoke about C-strings. They should be taught as a concept since strings themselves are built around C-strings. If learning pure C++, C style strings aren't really that useful. If you ever need a C style string, figuring it out is the easiest thing in the world, literally just an array of characters.

Rand, Qsort, and C-strings are obsolete in C++. C-strings is obsolete as long as strings are an option.
If you don't teach c-strings, how do you propose to deal with arguments to your program? The
int main( int argc, char * argv[] )
form?
Like this:

You don't



It's one of those things you don't really run into, and if you do, is it really going to be that hard to pick up? If you understand int i[], what's suddenly going to throw them off about char a[]?
zapshe wrote:
It's one of those things you don't really run into

Actually, @zapshe, I do run into it quite a lot: it is extremely convenient to start programs with their parameters, rather than have to input them later or read from file.
Herein, I suspect, is a big difference between those who run programs from the command line - in Windows or linux - and those who never run anything outside of an IDE.


zapshe wrote:
If you understand int i[], what's suddenly going to throw them off about char a[]

The extra character needed for null termination for starters. Also, the distinction between const char * and char *.


We end many data structures with some sort of 'null' - trees and lists, for example. It's not that unnatural to end strings in the same way.
Last edited on
windows drag and drop will work off argv/argc input.
almost all major commandline tools like ls, grep, etc use command line options, dos too .. dir, etc…

you CAN deal with it with
string s = argv[n];
but that is, as I said above, an extra useless copy if you just need a strcmp() or strstr() on it. For inputs the extra copy is probably harmless for most programs on most devices.
Giving arguments to int main() isn't exactly something one does when learning C++. I've personally never even declared a C-style string in my life, but if I needed to use one I'd be able to. Using arguments isn't something you usually need to do when learning. Moreover, if you need to pass in arguments, that's something you can learn separately and probably quickly. I suspect it would be harder to learn the many ways you can pass an argument into int main() than actually taking them in with a C-Style string.
We can ask beginners to add this one line to main, and carry on from there:
const std::vector<std::string> args( argv, argv+argc ) ;
Giving arguments to int main() isn't exactly something one does when learning C++

...and most curricula proceed to teach students to (poorly) write interactive programs, when the stream-based interface in the standard library is not suited for this kind of work.

I know some students are interested in the topics that C++ is suited for, but for the majority of new programmers, C++ shouldn't be used as a first exposure to programming.
Last edited on
If you don't teach c-strings, how do you propose to deal with arguments to your program? The
int main( int argc, char * argv[] )
form?

I'm sure "modern" C++ in addition to new language features also means that command line programs are legacy programs too, and new/modern software is in most cases GUI.


also, majority of computer users are not super users, meaning they don't even know how to use command line or that such thing even exists.

so if considering what to learn/teach let's be complete to the end then, let legacy code and programs remain history of once great stuff, to the full extent :)
Last edited on
JLBorges wrote:
We can ask beginners to add this one line to main, and carry on from there:
const std::vector<std::string> args(argv, argv+argc);

That is a lot better of a "boilerplate" code snippet than is routinely taught now:
using namespace std;
"computer users"

Ah, computer programs and users.

https://www.youtube.com/watch?v=z4eNi0zJxdA

Interesting how for a movie about the inner working of computers much of the world inside the computer was created by traditional people-drawn/painted animation work.
closed account (2z0kLyTq)
I probably shouldn't comment because this could derail the thread, but I find I'm much more productive when I work from the terminal/command line.

I've always compiled my programs, when using a compiled language, with a makefile. Even when writing in Java I use a makefile and compile from the command line. Regardless of what language I use my text editor is always Vim. And when I write programs at work more often than not the interface I employ accepts parameters from the command line only. I do this because it ensures complete fools won't use my programs.

The people who work with me often make careless errors because they rely on a graphical interface which is faster when you don't understand how to use command line tools, and the learning curve is definitely less, but after just a week or two of effort you'll work just as quick or quicker. Writing scripts to increase productivity is easier using the command line, text based commands, then using binaries in my opinion.

The term superuser is a term probably invented by a marketer who never wrote a program. You don't have to be smart to work from the terminal.

I strongly believe the terminal when still be around and be being used even after I retire. There was a kid I worked with who use to be able to write programs who told me the command line was "old school". He doesn't write programs anymore now he just uses other peoples programs.

Please forgive me for this derailment.
Last edited on
Please forgive me for this derailment.

"I do not forgive." ~ Someone

The command line has its uses I'm sure, but if it can be avoided then why not? It's annoying and time consuming. My professor spends a solid few seconds on the command line every time he runs his code, when the same things could be done with Visual Studio ONCE and then run with the shortcut Ctrl + F5. In fact, using the command line is such a huge pain, to save time, any .cpp I have to test with the command line I end up renaming so I don't have to go back and change the name of the cpp in every instance of it in my saved commands.

If it can be avoided for the best, WHY DO IT?

There was a kid I worked with who use to be able to write programs who told me the command line was "old school". He doesn't write programs anymore now he just uses other peoples programs.

One example is hardly evidence.
closed account (2z0kLyTq)
@zapshe

I can code c++ on my pixel3 android phone using vim a makefile and clang. It's very pleasant. Not for my phone but on my phone. Which I enjoy doing on the train. It's a freedom I have because I'm comfortable on a terminal.

The up arrow is just as fast as ctrl + f5.

It takes a couple weeks to be as quick using a terminal as a GUI.

I'm sorry I offended you, it was not my intention.

In fact, using the command line is such a huge pain, to save time, any .cpp I have to test with the command line I end up renaming so I don't have to go back and change the name of the cpp in every instance of it in my saved commands.

I don't understand your problem, but a good scripting language can make any tedious problem disappear, and it keeps you sharp.
Last edited on
I can code c++ on my pixel3 android phone using vim a makefile and clang.

I'm sure the command line has it's uses as I've said. Even on my iPhone, I have an app which can compile and run C++ code. Not sure how well it works since I only have it just in case and tested it with a small program, but I'm not sure why anyone would want to code on their phones if they could avoid it.

The up arrow is just as fast as ctrl + f5

You have to do it several times. You have to go to the compiling line, let it compile, then go to the other line so you can run it. And if you're trying to run a .cpp after running a different one (which I have to do often), then you go back in and change the name of the .cpp and then run it.

It takes a couple weeks to be as quick using a terminal as a GUI.

I've been using it for at least a year, it's never as quick and easy as finishing the last line of code and then pressing Ctrl + F5.


I'm sorry I offended you, it was not my intention.

If a debate on command lines is offensive to anyone, they probably need help.

I don't understand your problem

I sometimes want to run several .cpp files in a row, and I have to go back each time to change the name of the .cpp file. Especially with the line the professor wants us to use, it has the name of the .cpp at least 3 times. With Visual Studio, I can just open the solution and run it. I can have several of them open at once and just switch between them if I ever need to run several of them.
wilson52 wrote:
I can code c++ on my pixel3 android phone using vim a makefile and clang.

You've mentioned elsewhere you've been programming for quite a few years. You aren't a newbie, someone learning how to program without any prior experience.

You'd didn't hijack/derail the thread, this is the Lounge after all, but the thread topic started out being about what should be taught to beginning programmers. And what shouldn't. The difference(s) between Programming 101 and Programming 201 or 501.

How to use the passed command-line arguments in a program IMO is not something that needs to be taught to newbies. It is an intermediate programming topic.
Umm, but:
(a) C++ is a great language ... but I'm not sure that it should be the first language that you learn. If I was starting from scratch now that first language would almost certainly be python.
(b) If these are Computer Science students, then I would sincerely hope that they knew how to work in a linux shell: that's pretty "command line" to me.

Personally, I agree with everything that @wilson52 wrote. (Wish I could get C++ to work better on my iPad: I have a lot of train journeys that I could usefully fill.)
the thread topic started out being about what should be taught to beginning programmers.
For the record, I never said "beginning programmers", I said "newbies". I was actually referring to C++ newbies. I agree that C++ is a bad first language.
I agree that C++ is a bad first language.

indeed, the learning curve is far to big.

and in the future the standard will expand much more, as B. Stroustrup says: "C++ is
evolving language" so it will surely become even harder to learn, so the learning curve continues to expand like our universe.

it's not only the language that expands, but there are thousands of different libraries too, mostly doing the same or similar thing in different ways. that expands the learning curve even further.

what is interesting, is that (again according to Stroustrup) there is a fear that the language may collapse to 2 or more branches in the future. that is programmers and language may gloriously split like the church in 1054. (ie. 2 or more separate but similar C++ languages)

knowing that your question is just one of the first signs that such thing may happen, ie. "why learn/teach this or that?" not everybody agrees, see?
Last edited on
Pages: 123