How C++ took a turn for the worse

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Let's face it, C++ is a weird language. As a primary python developer. It's pretty exciting seeing C++ adapt more, quote unquote modern syntax over the past ten years or so. But there are still bits and pieces that make the entire language seem like a jumbled mess. With the rise in popularity of languages designed to replace C++, such as rust or carbon, the question has to be asked if it's even worth it to learn the more modern syntax. Although if you like many of the new features slow me down rather than make my code more readable and quicker. Many people who are use them for longer probably say otherwise. For starters, we have the auto keyword. I know auto as a keyword has been around for basically forever as it came from C rather than being a C++ exclusive. The main use case of auto being to deduce type came around in C++ 11 and in C++ 20. Auto could be used in a function parameter type as well. My issue with auto is not so much the convenience of shortening a long declaration statement, but rather the poor code practice for future debugging. For example, if we have a line of code auto foo equals some random function, there is no indication of what some random function returns. And with the generally poor naming conventions of the average programmer, it's extremely hard to deduce what type the variable foo is. It gets even worse when you have another function that takes auto as a parameter. At that point, it's pretty difficult to figure out what's happening and what any of the variables with the type auto actually are. I do think auto has its place and as someone who primarily writes code Python, I still think the addition of auto for deduce typing does more good than harm. The second thing that's confusing is the Modern Standard Template library I know its super useful, but some of the syntax can just get weird. I was watching this video from the code report and he was condensing heavily nested C++ code. The original code looks like something a developer would write to quickly try something out. However, as it got more and more condensed and the standard library started taking over, I had no idea what was going on. And this is one of the main issues I have with the standard library. While it is super powerful, there's just too much going on making it difficult to change the code. I mean, when you eventually have to edit the code two years later, it's hard enough deciphering regular, less condensed code. And this ultra condensed version would make me really think if I like programing again. While I am a fan of writing condensed code and have had my fair share of notorious one liners. Similar transformations could be best described as you took perfectly readable code with a logical progression easily debuggable and turned it into a nice spaghetti . The boomer in me would say that's what's wrong with this new generation. Package managers in C++ will always surprise me. I have no clue why. In all these years C++ does not have a default package manager. I know there's many third party package managers such as CONAN, BPT and vcpkg and more. But that's just not the same as something like PIP cargo or NPM. You could learn CMAKE to make it easier to use external libraries, but even that is not as easy as going pip install some package. The current way to work with third party libraries in C++ is to manually download the file and put them in some local folder. You then have to tell your environment where to look for these packages and then finally add your include statement. If you go down the path, hopefully you did everything right because well, linker errors and linker errors, at least to me, makes zero sense sometimes. Speaking of error messages, they're not great. I mean, they're not horrible either. But from what I've seen, it only really helps me when I write a percent F instead of a percent D inside of print f. Besides that, they're pretty generic. The reason I mention them is that segfaults also fall under error messages, and those are absolutely horrible. They give zero information of where the program crashes and just leaves it to the developer to find out the rest. To be fair, I'm not sure how other languages deal with safeguards, but at least in C++ they aren't the gold standard. I've been looking online at some rust error messages and maybe those examples are cherry picked, but they really are great. They seem to tell the developer where exactly the code messed up and how to fix it. And while StackOverflow can replicate this process, it's not perfect. The other day I was coding and StackOverflow was down. That's when I really realized that nicer error messages would drastically improve my coding quality as I could fix my code without having to do extensive research on the issue. Arguably, the biggest reason I say modern C++ is weird is that it has to remain backward compatible with C. This just makes it so that there's many ways to do one task. For example, to allocate memory on the heap we can use malloc We can also use the new keyword. There is also smart pointers which is just a third way you can do the same task every iteration of C++. More features are added, which means more things to keep in mind to not create a memory leak. Although the language continues to improve every couple of years, a feature becomes outdated and a new one is pushed out. While I do think modern C++ is weird, it's still considerably better than the older versions of C++ and is still worthwhile to understand and learn. Whether you like it or not, C++ is not going anywhere and it's going. A staple of the industry for years to come.
Info
Channel: Code Persist
Views: 262,824
Rating: undefined out of 5
Keywords: coding, c++, programming, weird, language, python, auto, STL, standard template library, computer science, software engineering
Id: Z_ahq2h9Xxg
Channel Id: undefined
Length: 5min 3sec (303 seconds)
Published: Tue Mar 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.