5 ms·
The problem is when you try to write boring code, but the compiler or library decides to be clever for you. Now you have a weird bug in otherwise innocuous cod
by wffurr 6y ago
The problem is when you try to write boring code, but the compiler or library decides to be clever for you. Now you have a weird bug in otherwise innocuous code that requires an ISO expert to understand.
- pjmlp 6y agoIndeed, I won't believe anyone that asserts they can fit on their head all UB usecases that are documented on the standard (> 200). Nowadays I just use it for native library wrappers, as it is better than plain C, but still hoping for FFI improvements on the languages I use that will reduce that need even further.
- gumby 6y agoIn 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)
- 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.