Thread: New C++ tutorial for beginners - opinions wanted!

  1. #31
    Registered User
    Join Date
    Jul 2015
    Posts
    37
    Here is what I wrote about the concepts. It got quite long, so I covered only the most important ideas:

    This tutorial is about learning computer programming. More precisely, it is about learning computer programming in imperative paradigm. Unavoidably, one imperative programming language had to be chosen, and given the contents of the tutorial it was determined that the C++ language would suit the best.

    The tutorial is written in programming by examples style, i.e. it is example-driven.

    In my experience, the hardest thing for a beginner to learn is NOT the programming language. Certainly, a beginner is going to make a lot of mistakes at first. But, most of those mistakes will be trivial and they will generally be caught by the compiler and reported correctly. Most today’s compilers are able to make comprehensible error reports. At the worst, when a beginner makes a mistake and doesn’t know how to fix it, he will ask about it on a forum, and there he is likely to get a prompt and correct reply, since the mistake is likely to be trivial.

    The hard thing to learn about programming is how to perform and organize the desired computation. This is the thing that experienced programmers take for granted – how to skip every third input value, how to select only values with some property, those are the toughest issues a beginner will face. Those problems can be perceived as a kind of simplistic algorithms, and the beginner’s problem is: how to write them down in the imperative programming style.

    Therefore, learning programming has very little to do with learning a programming language. The detailed description of the syntax and effects of statements is unnecessary and confusing for a beginner. He will easily pick up the syntax from the examples by himself without need for any extended explanations. It is sufficient to sporadically provide some hints on some elements of the syntax, in places where he is likely to make a common mistake.

    Instead, the explanations should concentrate on structure of the program and extremely simple ‘algorithms’ (perhaps it would be better to say that those are simple tasks). For example: how to add up numbers, how to find a minimum value, how to count values with given property. There should also be some advice on how to organize the computation (functions help a lot there), and how to analyze and understand the given problems.

    Therefore, the features of the language are to be explained only as necessary for solving concrete problems (where it would be ideal to introduce a new feature of the language just before solving a concrete problem using the feature). There is no need to go into extensive details about language features. Use the abstraction instead!

    There is absolutely no need to explain features of the language grouped by their language category (for example, don’t explain in a single chapter all kinds of loops that a programming language provides). Not only that there is no need for such groupings, but they are inherently bad. Even more, a complex feature of a language can be explained in several parts, through several chapters, each time giving more detailed information, as necessitated by example programs. It is easier to learn complex features and concepts when they are broken down into more easily digestible bites, supported by examples!

    In summary, when explaining computer programming to a beginner, you should be explaining computer programming more, and explaining the concrete programming language less.

  2. #32
    Registered User
    Join Date
    Jul 2015
    Posts
    37
    Elysia:

    I'm assuming the Visual Studio because the instalation of Visual Studio and project setup was explained in chapter 3:

    Installing an IDE | Learn Programming with C++

    Creating a Project | Learn Programming with C++

    But you are right, on other IDEs the error you mention wont be caught. In fact, the issue is even worse that that (for example: Code::Blocks on Windows cant catch SIGTERM because Windows has no Unix signals). So I will certainly do something about it.

    Thank you for catching that issue.

    I would agree with you that beginners should use only checked array indexing, but using at() is problematic for other reasons (ugly syntax, wont work on gcc in Windows)

  3. #33
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Kevin C View Post
    but using at() is problematic for other reasons (ugly syntax, wont work on gcc in Windows)
    Really? It's part of the international standard. It is supported on every C++ compiler I've used. Which versions have you used, and which versions did not implement it?

    Also "ugly syntax" is rather subjective. I'll take supposedly ugly syntax over unstable code any day.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #34
    Registered User
    Join Date
    Jul 2015
    Posts
    37
    Compilers do implement it, but on IDEs which lack the ability to catch this error the program will just terminate. Therefore the feature is of little use for demonstrating the error, which was the purpose of the chapter in question.

    "Ugly syntax" is subjective, but the number of characters isn't. Two characters for [], 5 characters for .at() .

    You have some point there on stable code being more desirable, but I don't see any better way to fix this issue? The only way is providing a pach in the vector template, so that it calls the assert on out-of-bounds when some tag is #defined, and then to also fix assert to throw a signal which can be caught on all OS-es. That would not be against the standard.

  5. #35
    Registered User
    Join Date
    Jul 2015
    Posts
    37
    I have added a note in the tutorial. That seems to be the best thing to do:

    Index out of Bounds | Learn Programming with C++

  6. #36
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Compilers do implement it, but on IDEs which lack the ability to catch this error the program will just terminate.
    What ? Exceptions are not meant to be caught by IDEs but in case you're debugging on one ,the exception with probably be passed to the IDE.

    A perfect example using gcc, with no IDE.

    Code:
    #include <vector>
    
    int main()
    {
        std :: vector<int> v;
        int a = v.at(6);
    }
    Output when program is run

    Code:
    terminate called after throwing an instance of 'std::out_of_range'
      what():  vector::_M_range_check: __n (which is 6) >= this->size() (which is 0)
    Aborted

  7. #37
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Kevin C
    I'm assuming the Visual Studio because the instalation of Visual Studio and project setup was explained in chapter 3
    On the previous page you mentioned GNU/Linux and Code::Blocks, so it is reasonable to suppose that you have a wider readership in mind, at least in part. This is a Good Thing.

    Quote Originally Posted by Kevin C
    But you are right, on other IDEs the error you mention wont be caught. In fact, the issue is even worse that that (for example: Code::Blocks on Windows cant catch SIGTERM because Windows has no Unix signals).
    No, as Elysia noted the issue for Code::Blocks if using the bundled GCC is that g++ does not use checked iterators unless enabled. If you do enable checked iterators (e.g., by passing -D_GLIBCXX_DEBUG to the compiler), the console window opened by Code::Blocks will likely show a similiar error message concerning an out of bounds access. The practical issue, of course, is that you then have to instruct the reader just how to pass -D_GLIBCXX_DEBUG to the compiler via the IDE, otherwise the reader will be confused as to why the result obtained was not as described, and then you cannot realistically pre-empt all possible IDE and compiler combinations.

    Quote Originally Posted by Kevin C
    "Ugly syntax" is subjective, but the number of characters isn't. Two characters for [], 5 characters for .at() .
    That is a ridiculous objection especially considering that the argument put forward concerns correctness that has a bearing on secure code. My objection to the use of the at member function is that when the elements are indeed accessed within the bounds, the excessive checking can be... excessive in production, since it cannot be disabled, whereas with checked iterators one typically can disable (or simply not enable) such a check on operator[] for a release build. This of course is not important in an introductory text.

    Quote Originally Posted by Kevin C
    Compilers do implement it, but on IDEs which lack the ability to catch this error the program will just terminate. Therefore the feature is of little use for demonstrating the error, which was the purpose of the chapter in question.
    Perhaps you could catch the std::out_of_range exception then. After all, it is just an example.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #38
    Registered User
    Join Date
    Jul 2015
    Posts
    37
    Silly me. I was working with Visual Studio for too long and wondered yesterday why nothing shows up when running a program in Code::Blocks with a debugger.

    Yes, about exceptions, I was actually talking about raising a signal. Without it the debugger can't catch the error before the program terminates, so the IDE can't mark the source code line where the error occured.

    Well, defining _GLIBCXX_DEBUG seems to solve this inconvenience with operator [] in Code::Blocks, so that is great. And there seems to be no need to use the .at() member function in that case.

    The issue of performance would really be overwhelming so early in the tutorial. The performance considerations are not for beginners, although the tutorial will be talking about performance in some later chapters, where there is also a mention of Debug and Release configurations in Visual Studio. At that point the readers can also be instructed to remove _GLIBCXX_DEBUG if they need more performance.

    I also have one more issue with Code::Blocks and gdb on GNU/Linux (more precisely, Ubuntu and Mint). The problem is that, in default installation, it seems not to show the elements of vectors (something seems messed up with pretty-printers). It would be necessary for the tutorial that Code::Blocks shows elements of vectors and of vectors which are members of structures and classes (one level deep, no more). I was thinking of asking about this in this forum, in some other topic...

  9. #39
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Kevin C View Post
    The issue of performance would really be overwhelming so early in the tutorial. The performance considerations are not for beginners, although the tutorial will be talking about performance in some later chapters, where there is also a mention of Debug and Release configurations in Visual Studio. At that point the readers can also be instructed to remove _GLIBCXX_DEBUG if they need more performance.
    Are you seriously going to try to teach everyone each and every macro for every compiler to enable iterator checking? Come on! This is a beginners tutorial! C++ is a dangerous language if mishandled. You should teach them the safest possible ways of writing code until they are advanced enough to venture outside the "safe" area. You don't let kids ride a bicycle for the first time without training wheels!

    So teach them a way that works on ALL compilers without tricky macros and which ALWAYS works regardless of flags, settings and macros. Using at() forces that exception down your throat, so you can't ignore it, unlike operator [] which may or may not find the error depending on settings, macros, etc.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #40
    Registered User
    Join Date
    Jul 2015
    Posts
    37
    You are right that it would be silly to attempt to handle all the possible compiler/STL combinations. But this is not a tutorial about C++, and I'm free to restrict the choice of IDE and compiler for the purpose of teaching programming.

  11. #41
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, if you are not going to accept feedback despite being unable to counter the arguments for it, then I have nothing more to say to you.
    Your "tutorial" will end up just like any other bad tutorial out there. Good luck with it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #42
    Registered User
    Join Date
    Jul 2015
    Posts
    37
    Why can't you accept that there can be programming tutorials that are not about C++ language? Besides, I have already accepted some suggestions.

  13. #43
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Kevin C View Post
    Why can't you accept that there can be programming tutorials that are not about C++ language? Besides, I have already accepted some suggestions.
    If you're going to have a programming tutorial that uses C++ for its examples, it should be correct C++.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  14. #44
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    If you're going to have a programming tutorial that uses C++ for its examples, it should be correct C++.
    O_o

    Hear. Hear!

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  15. #45
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Kevin C View Post
    Why can't you accept that there can be programming tutorials that are not about C++ language? Besides, I have already accepted some suggestions.
    Why can't you accept that if you're going to use a specific language for your tutorial, then you should use best practices for that language?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Researching C++ - Your Opinions Wanted Here!
    By McCrockett in forum C++ Programming
    Replies: 2
    Last Post: 11-08-2012, 09:38 AM
  2. Storing position/velocity of agents -- opinions wanted
    By Ocifer in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2012, 04:06 PM
  3. Expert opinions wanted!
    By MK27 in forum Linux Programming
    Replies: 8
    Last Post: 11-01-2011, 10:14 AM
  4. Beginners Contest #2 For those who wanted more!!
    By ILoveVectors in forum Contests Board
    Replies: 16
    Last Post: 08-12-2005, 12:03 AM
  5. Opinions Wanted
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 09:56 AM

Tags for this Thread