5 ms·
In my experience that essentially never happens. One of the complaints about c++ is how many obscure features it has. Most of those obscure features are for a
by gumby 6y ago
In my experience that essentially never happens.
One of the complaints about c++ is how many obscure features it has. Most of those obscure features are for authors of the standard library implementations (or other libraries intended for widespread use), not for user code. If you look at the standard library source it’s very hard to read because it’s full of things to transparently handle weird corner cases in order to avoid user surprise.
But in my code I don’t use any of that stuff. There’s a pretty straightforward modern language in the middle of that, and not even a huge one.
- rubyn00bie 6y agoPardon me, and of course you have no obligation to answer (I'll be googlin' a fury after I post this), but could you perhaps share a resource or two for c++? I ask because this: > There’s a pretty straightforward modern language in the middle of that, and not even a huge one. made me literally mutter "woah... really?" I've always had the impression, and granted it is based primarily in ignorance and group think (looks around), that learning C++ is an endeavor that takes years because the language is so complex. And so, I would love any resources that make it more tractable... or does it really boil down to don't use "obscure" features you don't need?
- jpcooper 6y agoI learnt a good bit of C++ by going through Elements of Programming Interviews, trawling through cppreference.com and getting help from #C++ on FreeNode for the difficult parts. Coming from mainly functional languages, I actually found it quite fun going through cppreference.com and seeing all the interesting ways in which C++ does things. Especially the STL. Pick an interesting project and continue in that vein. The biggest difficulty for me was understanding the memory model and all the different types of value, references and so on, but #C++ was again a brilliant resource for smart pointers to good articles on the difficult subjects. Professional C++ programmers might have other opinions on how best to learn.
- pelmo 6y agoThe most common confusion among beginner programmers who want to pick C++ as their programming language (in contrast to scripting or interpreted languages) is that you may think that C++ is much harder than "even higher-level" programming languages, which means you rather miss the point of what programming is. Almost every programming language (if we're going to exclude some exotic ones, or domain-specific languages) - i.e. C++, C, Python, Java, etc. - have the same things in common, which are data types and control flows. When people judge C++ for its complexity - there's a reason for that. C++ is both a syntax and a program. The program is the compiler, and the syntax is the part of the compiler that parses your text file to produce machine code. What you want to do to learn programming, is first understand why do you want to learn programming and what kind of thing you want to create. Everything you need to know to not write obscure programs in C++ is to learn C. C can provide with every basic concept you need in order to be able to program anything that you want. Maybe, if you invest enough time and dedication, you'll realize that all these fancy features that C++ implements are unnecessary. Learn operations on strings, dynamic memory management with boundary checking, control flows, simple and abstract data types, etc. But, most importantly, you should have a goal - an idea of what you want to accomplish with that knowledge, otherwise learning the syntax of the language and its "cool new features" will leave you thinking "welp, what do I do now".
- Someone 6y ago“Everything you need to know to not write obscure programs in C++ is to learn C. C can provide with every basic concept you need in order to be able to program anything that you want. […] Learn operations on strings, dynamic memory management with boundary checking, control flows, simple and abstract data types, etc.“ _If_ you start with C, I would skip the “operations on strings” part. C doesn’t have strings. It has a set of poorly designed functions that operate on sequences of contiguously instances of char* that satisfy the constraint that they contain exactly one char* whose value is zero: the last char in the sequence. Nowadays, I wouldn’t start with C, though. I think it’s more distant from modern C++ than python, go, or scala (yes, you can write C++ in C style, but you shouldn’t)
- pelmo 6y ago
- gumby 6y agoThere’s a short book by Stroustrup called “a tour of C++” that shows you the essentials. Get the 2018 edition. Then read some code and write some code. Don’t worry about efficiency. You can read the “core guidelines” as well which are quite useful, but for a complete beginner many of them will be more than you need. Like Lisp, C++ is a multi paradigm language: you can write procedural, o-o, and other styles of code. It has a pretty powerful type system. Don’t worry about old, c-inspired c++. If you know C, as a learner consider c++’s relationship with C to be no different from Java’s or even Python’s relationship with C: some common syntax and conventions. Of course C++ is indeed more tightly coupled with C, but if you think of it that way you will make your life significantly harder, especially when starting out. I find c++ pretty convenient for rapidly prototyping something that runs reasonably quickly. Then if I care I have enormous power for optimizing...but it’s often unnecessary.
- dgellow 6y agoA tour of C++ 2nd edition: https://www.stroustrup.com/tour2.html https://www.stroustrup.com/tour2.html C++ Core Guidelines: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines GSL (Core Guidelines Support Library): https://github.com/Microsoft/GSL https://github.com/Microsoft/GSL
- AnimalMuppet 6y agoI second the recommendation of A Tour of C++. It's not going to give you a detailed explanation of every page of the specification. It's going to show you the basics of using the major parts, and why they are the way they are. From there, start exploring on your own.
- secondcoming 6y agoOur codebase is a few hundred thousand lines of C++. I think we use enable_if two or three times. Templates are used when necessary. I've been paid to write C++ for about 15 years at this stage, and I still regulary refer to example code online. And if you want to see exactly what the compiler's doing to with your code use Compiler Explorer.
- gumby 6y ago> And if you want to see exactly what the compiler's doing to with your code use Compiler Explorer. With real code (with a build system, various includes, and likely your employer's proprietary code you aren't allowed to upload to some web site) it's usually far simpler to simply use -S or --save-temps. Sometimes you can make a toy case or take a sample from your employer's code base and paste it into godbolt. It's very rare for most users to want to see the assembly code.
- secondcoming 6y ago> It's very rare for most users to want to see the assembly code. Maybe, but if I'm hiring a C++ programmer I'd expect them to want to do this occasionally.
- wffurr 6y agoI try to write pretty straightforward modern C++ as well, but have been bitten repeatedly by weird corners of the language. For a recent example, I was using the address of some functions from a library, and the library changed to provide the exact same functions in a different way that broke taking their address. Seems like that particular Abseil ToTW isn’t public, but it alluded to this practice being banned in the C++ STL. Or for another example, writing code that can be compiled by different versions of a single compiler, clang, e.g. across the Android NDK, XCode, latest LLVM on Linux, and Emscripten, will occasionally give surprising results. To say nothing of supporting msvc or gcc.
- pjmlp 6y agoMy problem is mostly the libraries, and in-house code written by other contractors, not all of them have been written at the same quality level as the C++ standard library. Contracting is the main point that makes me happy not having to deal daily with C++.
- wffurr 6y agoFinding bugs in the standard library is doubly "fun".
- gumby 6y agoChannelling your inner Sartre or weary voice of experience?
- pjmlp 6y agoExperience of handling code written by all known consumers of H1B visas in US and other major sweat shops, across industries whose main business isn't selling software. The real world isn't the pleasant CPPConf and C++Now session rooms, nor the quality standards that FAANG expect on their work processes. The mess that is done will less complex languages takes another level when they also have touched C++ in the process. Remember some Bjarne talks, on the real world many students still get introduced to C++ via Turbo C++ for MS-DOS.