5 ms·
Pardon 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
by rubyn00bie 6y ago
Pardon 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 agoI don't know if I am replying to an expert programmer, who writes programs on the daily basis, but you contradict yourself: >C doesn’t have strings. It has a set of poorly designed functions that operate on sequences of contiguously instances of char* Which reads as "C doesn't have strings, it has strings". You may have confused "std::string", which is a container, with the concept of strings as "array of characters". If so, then I'm clarifying, that I've meant the latter. If you wanted to emphasize that "char" is worse than "std::string", then I do not agree with you. The reason is that, well, as I already said - "std::string" is a container, which means using it causes unnecessary inefficiency. How do you think it was implemented? C++ was written in C, by using its functions and data types. Your phrasing of what "char" is reads like it is a some sort of a problem, however it's the way that things work on low level and by saying >I would skip the “operations on strings” part you would mean that you wouldn't want the person, whom I was replying to, to know about what you've wrote about "char*". >Nowadays, I wouldn’t start with C We don't know who you are, and what kind of programming you do, and how much you care about quality programming. The person I was replying to seemed to be interested in lower-level programming languages, so I assumed he's a some sort of a programmer who wants to understand if it's possible to write in C++ without the "Modern" stuff (which is possible, and this is what expert programmers that write quality software do).
- 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.