Program Programmer, I seriously recommend you carry on with C++ if you want to learn more about programming. It's a lot harder and the benefits aren't so obvious immediately, but it's far more worth your time. Spending more time in Batch files could also be counter-intuitive, or at least is wasting your time.
Take my word for it, or if you don't please read this whole post.
For one thing, the simple aspects of C++ are all easily far more advanced than what Batch files can provide and way more powerful. They're also probably roughly 10000 times faster.
Basic C++ programming is a type of
structured programming. This is a fancy name to point out that C++ doesn't rely on a very linear limited control-flow system (that batch files happen use). In batch-files you control program flow using IF statements in conjunction with GOTO and labels, right? Well you've probably already noticed that it's easier to read Batch files when they're nicely split-up into different sections, i.e. different blocks of consecutive commands in the file for different logical parts of the program (like different menus, or a saving mechanic). The idea of structured programming is to use actual syntax to represent these different logical parts, either separating entire parts of a program (into functions) or representing common control-flow patterns (loops / if statements with blocks).
For example, I bet at some point you have a menu that's structured something like this:
:mymenu
CLS
ECHO. This is my menu, choose an option.
ECHO.
SET /P choice= x to quit:
IF "%choice%"=="x" GOTO menuskip
GOTO mymenu
:menuskip
Well in typical non-structured style you must read the whole thing to understand what's going on.
Now let's see how it could be implemented in C++:
1 2 3 4 5 6
|
string choice;
do {
system("CLS");
cout << "This is my menu, choose an option.\n\n x to quit: ";
cin >> choice;
} while (choice != "x");
|
Provided you understand the syntax, you can
instantly recognise how that functions; it's obvious from the syntax
at a quick glance. Isn't that a better way of doing it?
Not only that, but there are no named labels. This is nice too, because you don't have to come up with names for different lines of code continuously while thinking to yourself "
if only there was some nice way of getting it to do all this automatically".
Don't get me wrong, it's not actually too much of a bother writing everything with GOTO commands, labels and all that. Eventually people adopt a kind of 'style' in their batch files that makes it easier to read their own code and do common things like menus without breaking a sweat. It's just that in C++, provided you know how to write C++ and have a little practise with programming structures, you can have that ease for free straight away because loops, functions, etc. can be moulded into pretty much whatever flow you need and don't require too much thought to make readable for even other programmers to understand.
AND AS A MASSIVE PS:
For any other members of this forum who managed to see my use of
system()
without dying of a heart-attack, yes I'm aware it's bad practise and a bad idea to show to people learning C++. However, if it will convince someone to stop learning Batch files on the basis that if they really need to they can still get any of the old functionality back then I believe it's the lesser of two evils. ProgramP: using system() will make your program specific to Windows, if you avoid it and manage to write a program without it you can compile that program on any system, whether Windows, Mac, Linux, and it should still run. So one day maybe you won't need it but for now you can get away with it.