Live data from Hacker News

3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

stroustrup.com

61–70 of 231 posts

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#61

Earlier quoted context omitted.

I felt some nostalgia for Fortran a while ago. Spent half an hour programming in it, cured. Maybe take a shot at parsing JSON in C++ and see if the nostalgia survives the process.

It took 30 minutes to cure you?!? One of the first things I did when I got my PiDP-11 which can run RSX-11M and the DEC fortran compiler. I spent many many hours programming in Fortran when I was in college and thought wow I could relive some of that, about 5 minutes in I was "okay, step slowly away from the console." :-)

There's a fun stream where tsoding decides to learn Fortran, and the instructions he's working from say to turn off implicit typing (ie write "implicit none"). He's familiar with modern languages with type inference and with C++ type deduction which is a similar idea to full blown inference - and so he has no reason to even guess what Fortran is going to do without that admonition and you can see he's not happy when he finds out.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#62

This is the book i used to learn programming 10 years ago! After that I never really learnt anything new.. been using the same concepts.

Did you use it to learn programming as a novice to the field? I have always wanted to learn programming as a hobby, but never really found the right entry point. Would you recommend this?

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#63

Earlier quoted context omitted.

Why is that? I'm genuinely curious. Also, what languages / environments do you prefer?

Same for me. Mainly due to the packaging fiasco (and to a lesser extent, imports). The actual language is not awful. Some features are even nice, like infinite precision integers by default, and separate / and // operators. Language is ok. Setting everything up is atrocious. The other quite annoying thing is that the docs are extremely badly organised so Google rarely points you directly at what you want. Instead you…

poetry with poetry2nix with nix flakes will do magic in terms of setup.

if stick with pyright(inference) it is as modern as rust.

python speed increases heavily in all directions.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#64
post #2

Sharing the C++ Annotations here, which is a continiously updated book on modern C++. http://www.icce.rug.nl/documents/cplusplus/

If I just use C with classes, plus smart pointers and auto, for my emulator project(s), would that be a reasonably good approach? I once heard that the C++ language contains 4 components: the first catalog is "C", the second is for OOP, the third is for productivity and flexibility such as stl and templates, and the last one is for special cases such as volatile, asm, etc. He then recommends to use catalog 1 with car…

Yes, roughly so.

1) The major part of C to avoid is raw pointers and malloc, and generally anything where C++ has a more modern alternative. Don't use C datastructures (pointers, strings, arrays) where C++ replacements exist (smart pointers, std:string, std::array and std::vector, etc), or use C libraries where C++ replacements exist (e.g. C++ std::string vs C's string.h).

Of course you can't avoid all of C, since the syntax of C++ is an extension of C.

2) I wouldn't characterize what C++ adds to C as OOP. OOP is a design methodology, whereas the main addition C++ gives you is classes which are better thought of just as powerful and convenient type of data structure.

The core feature of classes you always want to use are constructors and destructors. Any initialization of the class's data members should be done in the constructor (don't leave things uninitialized), and any final cleanup (releasing memory or locks, closing files, etc) should be put in the destructor so that it always happens (even if your program throws exceptions).

Don't feel that just because classes support subclassing, polymorphism (virtual methods), etc, that you should be using them. They are there in case you need them, but if in doubt don't.

3a) The STL is just the standard library for C++. You should always be using STL data structures (std::string, std::list, std::vector, std::map, etc) when applicable - not just "for productivity".

3b) Templates (template classes, constructors/methods, functions) are not needed for most everyday use of C++. They are there for library writers, and on occasion for writing your own class and libraries. Think of them a bit like class inheritence - they are there in case you need them, but not something you should be reaching for unless there is no better way.

4) C++ has a LOT of stuff (esp. libraries) that might be considered as "for special case use only". A rookie mistake might be to think that C++ has all this stuff - I should be using it! In general you should ignore the obscure stuff, and only use it when some special circumstance requires it.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#65
post #56

Oh, he switched to QT for the GUI chapter. That's a significant change from FLTK. Should be well received as QT is popular in industry. Not sure how the learning curve will be affected.

For the better, with Qt there is QtCreator.

Not sure what you are trying to say here. Qt, the library, and QtCreator, the IDE, are completely separate products. You can use QtCreator without Qt and vice versa.

Now, I'm pretty sure you know that, hence my confusion...

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#66

I've always wanted to learn C++. I have a great handle on C#, making large applications and architectures as well as legacy refactoring in C#, and I would love to learn C++. I recently started at a company with a bit of a hairy c++ application that I would love to refactor or understand more thoroughly. Is this book a good place. Note that I have read a very basic book on C++ much more learning programming book, but…

I haven't read this new edition, but the previous ones are pretty decent for the why's and hows.

If you want to work on your "hairy c++ application" you'll benefit from understanding how "modern c++" it is (and what your toolchain supports).

Meyer's effective books are good with two caveats: first, they are really meant to improve practice for people who are already working in the language (e.g. don't do it that way, and here's why). Second, the older ones are now dated and some advice need updating to work with newer language spec.

If 3rd edition of this one lives up to previous, it should be a pretty good read but as others have mentioned the "Tour of C++" book is a good entry.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#68
post #34

Sorry if it is a bit off-topic. If you just started learning C++, why did you choose it instead of another language? (Rust, C#, Go, etc) I know a bit of C but feel that the sheer "thickness" of C++ is too daunting and scary to even start.

I started because I became interested in graphics and audio programming. Audio plugin development in particular is completely dominated by C++.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#69

This is the book i used to learn programming 10 years ago! After that I never really learnt anything new.. been using the same concepts.

Did you use it to learn programming as a novice to the field? I have always wanted to learn programming as a hobby, but never really found the right entry point. Would you recommend this?

I would start with Python instead of C++, if you just want to learn a useful tool as a hobby. The official tutorial is a good starting point: https://docs.python.org/3/tutorial/index.html

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#70

Earlier quoted context omitted.

It took 30 minutes to cure you?!? One of the first things I did when I got my PiDP-11 which can run RSX-11M and the DEC fortran compiler. I spent many many hours programming in Fortran when I was in college and thought wow I could relive some of that, about 5 minutes in I was "okay, step slowly away from the console." :-)

There's a fun stream where tsoding decides to learn Fortran, and the instructions he's working from say to turn off implicit typing (ie write "implicit none"). He's familiar with modern languages with type inference and with C++ type deduction which is a similar idea to full blown inference - and so he has no reason to even guess what Fortran is going to do without that admonition and you can see he's not happy when…

I don't get that at all. Old FORTRAN has a mildly confusing feature that is easy to disable. He then got upset about the mildly confusing feature that everybody now disables. If one wants to bitch about Fortran, at least complain about the modern language (which is still a horror show of poorly defined and often unportable features), not the stuff that has been made obsolete.
Post reply on HN