DEADLY C++ Mistakes Beginners Make

NOW OPEN! Python Bootcamp –

💯 FREE Courses (100+ hours) –
🐍 Python Course –

✅ Data Structures & Algorithms –

~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

✉️ Newsletter –
📸 Instagram –
🐦 Twitter –
🔗 LinkedIn –
▶️ Subscribe –
👨🏻‍🎓 Courses –

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

↪ My Amazon Store –
🅿 Patreon –
🅖 GitHub Sponsors –
Ⓟ Paypal –

🅑 Bitcoin – 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth – 0x350139af84b60d075a3a0379716040b63f6D3853
📈 Buy Bitcoin –
Reserve the Ruby Steel crypto rewards card and get a $25 bonus (use affiliate code “Caleb”) –

22 thoughts on “DEADLY C++ Mistakes Beginners Make

  1. Using floats instead of doubles isn't just dumb, since with automatically vectorizing compiler you can quite often get 2x performance because the SIMD instructions can operate on twice the amount of floating point numbers at a time.

  2. I disagree about float vs. double. Doubles are always going to be slower due to larger memory footprint leading to more frequent cache misses (regardless of architecture). There is hardly anything that would make code harder to read by using floats. Functions are often templated for both, so in worst case you might have to throw in a static_cast<float> on the return value. In game-dev it is not premature optimization to use floats, just common sense. However, there are places where double is useful, like where precision errors can accumulate in an algorithm.

  3. When I started programming in C++, it was back before move semantics existed and the STL was making copies everywhere (we thought, turns out compilers were smart enough to move elide when it didn't even have to yet). C and C++ were almost indistinguishable aside from a few extra "struct" keywords back then, and I thought the "backwards" compatibility was a real selling point. Now, I actively like to make my C++ code as incompatible with C as possible because it's fun to convert everything all to containers and algorithms and see functions shrink from 30 lines to 1 statement. I hate seeing output parameters so much now, which is the worst thing about interfacing with windows system headers; back in the old day I was all about output parameters, with pointers to pointers and references of references in every method call. What fools we were in those ancient days of the mid 2000's. The compiler was move eliding the whole time; if only we'd profiled sending our results back by value instead of trusting our professors!

  4. I'm from the UK,trading with Mr Peter roland has been great,my last investment with a sum of £8300 made a turn out of about £19202 under a trading period of 10 days

  5. Okay, I warched it, there is some really bad advice here. Here we go:

    First minute is literally a paid ad for some IDE I have never heard of

    Don't use "using", because it can cause naming conflicts. Instead write e.g. std::cout every time you use it.

    You can selectively get things into scope, e.g. "using std::cout"

    Try to not just write C code if you are using C++, e.g. take advantage of classes and the std stuff.

    Don't optimize prematurely, e.g. don't try to squeeze out some performance trying to fiddle with fixed size arrays or floats, just use vectors and doubles, the overhead does not matter on modern platforms

    If you are doing a test in uni, pay attention what features are supported, becausr if you use C++11 and your code does not compile because it is not supported, you may get a zero.

    If you are using C++, don't use pointers, use references instead

    He explains the difference between errors, warnings and logical errors, aka bugs

    Pick the right tool for each job, Cpp may not be the perfect choice for everything

    That was it. Now my opinion:

    This is a beginner teaching beginners. That's how I learned initially, so nothing per se wrong with that. If it gets people excited and motivated, that's great. BUT

    The using keyword is totally fine, e.g. in translation units after the last header include. It even says that on screen as he shows the stackoverflow answer about this.

    There are specific purposes for using fixed size arrays and floats. Using floats instead of doubles is not "dumb". Claiming this actually makes the author look dumb. You can easily reach memory and time limits on modern hardware. For beginners this is not an issue, but he could phrase that better.

    References are not meant to replace pointers, they are specifically designed to make operator overloading and some other stuff possible. There are other differences and using pointers is often still a valid approach.

    Oh boy. That was hard to watch. Not my cup of tea at all.

    – u/Backson

  6. What an exaggeration! These would only potentially be deadly if the code you write is meant to run in nuclear reactor, a car, a pace maker, medical equipment, or something like that. For a normal program it's unlikely to cause death. So unlikely that I must insists that doing these things should not be made illegal.

    1:00 Naming conflicts are most often not dangerous. Often they just lead to a harmless compilation errors. Yes, in theory they could lead to the wrong function being called which might end up doing the wrong thing but it only happen under special circumstances. I would consider ADL, which you cannot avoid unless you make sure to qualify all function calls, to have a higher risk of this happening.

    1:37 About using "using" to bring in just some of the names… Now you need to maintain lists of using declarations all over the place, and you need to use brain power to think about which names you have in the list, which ones you should add, and which ones you should qualify. In my opinion it's just much easier and consistent not to do it.

    2:35 The biggest problem with global variables is that it gets harder to test and reason about code because any part of the code could affect any other essentially. You still get the same problem with global variables even if you try to "hide" them inside a namespace or "disguise" them as singletons. It has very little to do with name clashes.

    2:46 If you don't consider C to be a "bad" language I don't think there is necessarily anything wrong using a C++ compiler to get a few extra features while still keep to a mostly C style of programming. It's probably not most people should do, but everything that you mentions, OOP, vectors, etc. have trade-offs, so I like to keep an open mind. I think people using both languages can learn a lot from each other. C is after all a much simpler language. It's easy to overcomplicate things when working in C++.

    3:58 I think there is a balance. Just wasting memory is one of the reasons why we now need many gigabytes of memory to run a normal computer. It's a bit ridiculous if you think about it. For local variables or things that you don't have a lot of it won't really make much of a difference but if you're having millions of objects it could be beneficial to use smaller types. I don't think using float instead of double is necessarily dumb. double is a good default but if you're using a lot of them and you don't need the extra precision (which is common in for example games) you could potentially save up to half the memory usage. If you're taking advantage of SIMD instructions (instructions that can carry out the same operation on multiple values at the same time) you can essentially process double the amount of data in the same amount of time if you work with floats instead of doubles.

    6:03 Was it a C++ course or was C++ just used for teaching about programming in general? If it's the latter then there is nothing really wrong with restricting what you're allowed to use.

    6:51 I think this is a common mistake for people that come from other OOP languages like Java because they are used to always having to use new when creating class objects and then pass them around "by reference". Except for the syntax, what's called a "reference" in many other languages are more similar to C++ pointers than C++ references.

  7. Software engineer and operating systems developer here. I only has to watch a few minutes of this to realise you’re full of shit and are in no way qualified to make any of these false statements you have made.

Leave a Reply

Your email address will not be published. Required fields are marked *