Live data from Hacker News

C++11 FAQ

stroustrup.com

101–110 of 121 posts

Re: C++11 FAQ

#101

Earlier quoted context omitted.

I started with C++ around '92, but you are right, C++ was already complex back then, but it was still manageable, you could, sort of, hold its larger picture entirely in your head and still had some elegance to it.

As a dissenting opinion from someone who has not quite 20 years of experience with C/C++ but 14, modern C++ is what brought me back to the language. The idioms allow me to use the language more functionally. More importantly, the STL is actually usable now and you can just code using it and std::algorithm without thinking of the nuts and bolts of move assignment and stuff at all. In the case where you need performanc…

C++ still cannot compete with proper high level languages in this area.

C++ is precisely useful because it's a better C: it has a C-like subset, and works directly with C data structures and function call interfaces. Plus it has features to do that kind of programming in a safer, more managed way.

I would absolutely not use C++ for anything that isn't in the area of "this should be ideally written in C, but that would bring in undue difficulties, risks and time".

The more C++ moves away from its focus of being a language for writing low-levelish systems middleware, the more it loses its relevance.

> Also, you have a ref counted pointer thread safe pointer!

Had those in 1997 using draft ISO C++, thanks.

Re: C++11 FAQ

#102
post #95

Earlier quoted context omitted.

One of C++'s most glaring problems is that everybody only ever uses some subset of some version of the language, but you still need to know basically the entire massive, monstrous language because not everybody uses the same subset and you need to be prepared for anything. On top of that, you're lucky if your employer or potential recipient of contributions (e.g., FOSS project) or whatever has actually codified the s…

It applies to most mainstream languages, even Python has subsets.

I've written code in over 50 different programming languages at this point (though only about a dozen or so professionally, including Python), and the only languages where I've ever been asked or required to work with a subset in lieu of the full language have been C++ and Perl. I've never worked on a project or for a company that allowed unrestricted use of all of C++.

Re: C++11 FAQ

#103
post #86

Earlier quoted context omitted.

I agree. The other day I had to dive into the libigl [1] matrix structure (for those that don't know, a matrix is basically a 4x4 grid of numbers). What I found was over 10 levels of inheritance, along with rampant template use and macros _everywhere_. It actually took so long to parse I ended up just changing my algorithm completely to avoid having to use it. I have utmost respect for anyone that can work with C++ d…

Odd. I wonder why they didn't just use Boost uBLAS or similar.

Last time I checked, Boost uBLAS was horribly slow and one should not use it. Use Eigen or Blitz++ (or just call BLAS directly) instead.

Re: C++11 FAQ

#104
post #93

Earlier quoted context omitted.

> 1992 was just the year MFC came out. Ignoring the nice work of PowerPlant , Turbo Vision and Object Windows Library, because they were too high level for C devs. So Microsoft ripped off their Application Frameworks (Afx) prototype and we got MFC instead.

OWL and TurboVision... now these are names I haven't heard in a long time. I remember the company I interned at was looking for TurboVision programmers at some point, none were found, soin a true Russian fashion they just wrote their own clone of it.

I used Turbo Vision in Turbo Pascal 6/7, then migrated to Turbo Pascal for Windows 1.5 with OWL and eventually to Turbo C++ 3.1 with OWL.

Re: C++11 FAQ

#105
post #92

Earlier quoted context omitted.

Works for me in both C++03 and C++14? https://ideone.com/KhfGaN

Your code is not the same as my code and you're probably new to C++. I suggest trying two changes: 1) Replace max("a", "b") with max("b", "a"). Run it, look closely at the result, and be enlightened. 2) Replace max("a", "b") with max ("a", "b"). Run it, look at the result, and be enlightened in a different way. As a small hint, your code invokes unspecified behavior, while my code invokes undefined behavior. If this…

Sorry, can you clarify? Adding the template argument causes a crash on idone, but I have no idea why that happens. Moreover, the output on my computer is always b\n.

EDIT: Not sure if this is it, but after some digging I've found [0] on lifetimes of temporaries. As for the lacking template argument, presumably const char* is inferred and a temporary string is constructed in main?

[0] http://stackoverflow.com/a/2784304

Re: C++11 FAQ

#106

I've been programming for money for over 20 years and I grew up professionally writing C and then half-migrating to C++, because the latter very naturally captured lots of C patterns and allowed for more succinct expression of the same. It was lean, expressive and elegant . Just needed a bit of Lisp-y closures and it would've been perfect. And then things got completely out of hand. Elegance was nuked from the high o…

I agree. The other day I had to dive into the libigl [1] matrix structure (for those that don't know, a matrix is basically a 4x4 grid of numbers). What I found was over 10 levels of inheritance, along with rampant template use and macros _everywhere_. It actually took so long to parse I ended up just changing my algorithm completely to avoid having to use it. I have utmost respect for anyone that can work with C++ d…

Doesn't libigl use Eigen for matrices? Eigen is a full-featured matrix library with a pretty decent API. If you just need a 4x4 grid of numbers, then you don't really need a library, sure. But once you need to do matrix arithmetic, basic linear algebra, various forms of indexing, mixing matrices of different types (e.g. float/double/int/etc), things get complicated, fast. A complex library like igl needs all this and more. I'm guessing this is why there's so many matrix libraries - everyone prefers rolling their own, after all, how hard can it be? (I'm guilty of this, so I'd know. But I reach for Eigen most of the time these days).

Re: C++11 FAQ

#107
post #105

Earlier quoted context omitted.

Your code is not the same as my code and you're probably new to C++. I suggest trying two changes: 1) Replace max("a", "b") with max("b", "a"). Run it, look closely at the result, and be enlightened. 2) Replace max("a", "b") with max ("a", "b"). Run it, look at the result, and be enlightened in a different way. As a small hint, your code invokes unspecified behavior, while my code invokes undefined behavior. If this…

Sorry, can you clarify? Adding the template argument causes a crash on idone, but I have no idea why that happens. Moreover, the output on my computer is always b\n. EDIT: Not sure if this is it, but after some digging I've found [0] on lifetimes of temporaries. As for the lacking template argument, presumably const char* is inferred and a temporary string is constructed in main? [0] http://stackoverflow.com/a/278430…

So first of all, max("a", "b") expands to max("a", "b"). It computes the maximum of two pointers, without looking at the characters at all. Comparing two pointers to unrelated objects is unspecified behavior, but in this case it usually returns the second pointer.

As for max("a", "b"), it implicitly converts both arguments into temporary strings, then returns a const reference to one of them. Since it's a reference to a temporary, it becomes dangling when max returns, but you can assign it to a const string& anyway. When you try to access it, you'll get garbage or crash.

Re: C++11 FAQ

#108
post #105

Earlier quoted context omitted.

Sorry, can you clarify? Adding the template argument causes a crash on idone, but I have no idea why that happens. Moreover, the output on my computer is always b\n. EDIT: Not sure if this is it, but after some digging I've found [0] on lifetimes of temporaries. As for the lacking template argument, presumably const char* is inferred and a temporary string is constructed in main? [0] http://stackoverflow.com/a/278430…

So first of all, max("a", "b") expands to max ("a", "b"). It computes the maximum of two pointers, without looking at the characters at all. Comparing two pointers to unrelated objects is unspecified behavior, but in this case it usually returns the second pointer. As for max ("a", "b"), it implicitly converts both arguments into temporary strings, then returns a const reference to one of them. Since it's a reference…

Thank you for the explanation! I'll have to look out for that one...

Re: C++11 FAQ

#109

I've been programming for money for over 20 years and I grew up professionally writing C and then half-migrating to C++, because the latter very naturally captured lots of C patterns and allowed for more succinct expression of the same. It was lean, expressive and elegant . Just needed a bit of Lisp-y closures and it would've been perfect. And then things got completely out of hand. Elegance was nuked from the high o…

The less I use C++ the happier I am.

Re: C++11 FAQ

#110
post #86

Earlier quoted context omitted.

Odd. I wonder why they didn't just use Boost uBLAS or similar.

Last time I checked, Boost uBLAS was horribly slow and one should not use it. Use Eigen or Blitz++ (or just call BLAS directly) instead.

That's what I meant... Though Boost uBLAS is still way faster than a deeply inherited 4x4 matrix...
Post reply on HN