Live data from Hacker News

My Most Important C++ Aha Moments (2006)

artima.com

61–70 of 84 posts

Re: My Most Important C++ Aha Moments (2006)

#61
post #60

Earlier quoted context omitted.

It's easy to dislike or hate C++ due to its immense complexity, and programmers like to be able to keep simple abstractions in their head so they can concentrate their energies on their problem domain without worrying about language confusion. With C and many other languages, this is possible as they are smaller languages. C++ on the other hand: is there any language with widespread use that is so deep and complex? H…

> Few languages allow you to just keep diving in deeper and deeper as you desire, while still letting you get to work right away without being a master. I find it to be the case with most languages. > Even template metaprogramming alone is gigantic area of ongoing research -- the stuff you can do with it is mind-bending and unavailable in nearly all other languages. Your are being a bit hyperbolic. Meta-programming i…

> Lambdas roamed the earth long before templates.

I'm talking about C++ lambdas, in particular, which are templates under the hood.

Re: My Most Important C++ Aha Moments (2006)

#62
post #57

Earlier quoted context omitted.

> Where is this modern C++ culture that has resulted in large-scale codebases free of memory safety vulnerabilities? In any large scale C++ conference like CppCon. In tooling from Microsoft and Apple. > I haven't seen any evidence for this. A lot of vulnerabilities are found in modern C++11. Using C++11 idioms, or C with classes? > I don't see any way that the C++ Core Guidelines are going to be able to succeed in cr…

> In any large scale C++ conference like CppCon. > In tooling from Microsoft and Apple. Microsoft and Apple regularly ship memory safety vulnerabilities in their codebases that are written in modern C++. Their browser engines, for example. > Using C++11 idioms, or C with classes? Using C++11 idioms. C++11 doesn't actually do anything to mitigate use after free, for example. In fact, I think there's a reasonable argum…

When pcwalton appears in a C++ thread, we are already past the rustwin point.

Re: My Most Important C++ Aha Moments (2006)

#63
post #50

Earlier quoted context omitted.

Yes, it does. The majority of C++ programmers make use of: - RAII - String classes instead of char* überall - Vector classes instead of char* überall - new and delete instead of malloc()/free() and casts - References for out parameters instead of pointers - Real enums, specially since C++11, instead of #define - Smart pointers for memory management - Type based programming to reduce errors - Minimize the use of the p…

And yet, most of the Unix tools just work, which I cannot say of the average C++ program. Can you name one C++ program with the same track record as postfix or qmail?

qmail contained a buffer overflow that allowed remote root access, prevented only by having a low limit on available memory.

http://web.archive.org/web/20160401021400/http://www.guninsk...

djb is a smart and motivated guy and even he isn't quite capable of writing correct C code; how much chance does anyone else have?

Re: My Most Important C++ Aha Moments (2006)

#64

> Realizing that C++’s “special” member functions may be declared private Don't do this anymore! Just delete them: MyClass& operator=(const MyClass&) = delete; Private-really-means-deleted was a cool and very useful trick before C++11. So useful, that it was a shame to require secret knowledge and aha moments to use. So they just made it a normal feature of the language. There's also a way to explicitly use the defau…

Alternative view: if you must use C++, stick to nothing later than C++2003. Anyway, declaring a constructor " = delete" isn't the same thing as making it private. If it's private, the code in your class scope can still use it. If you can't trust your class private code to do things correctly, then you're screwed; go join IT and write backup shell scripts. So basically this "= delete" is just another ear growing out o…

The reason for testing and static typing is that you can't trust yourself to be perfect. I want to declare that I won't do things that don't make sense, so the tools will tell me if I do them unintentionally.

Re: My Most Important C++ Aha Moments (2006)

#65

Earlier quoted context omitted.

And yet, most of the Unix tools just work, which I cannot say of the average C++ program. Can you name one C++ program with the same track record as postfix or qmail?

qmail contained a buffer overflow that allowed remote root access , prevented only by having a low limit on available memory. http://web.archive.org/web/20160401021400/http://www.guninsk... djb is a smart and motivated guy and even he isn't quite capable of writing correct C code; how much chance does anyone else have?

qmail is supposed to be used with "softlimit" from daemontools. All decent tutorials mention that.

Again, which C++ program has been even analyzed to that level?

Re: My Most Important C++ Aha Moments (2006)

#66
post #3

I love C and Objective-C. I can't stand C++. Is that common among programmers?

It's easy to dislike or hate C++ due to its immense complexity, and programmers like to be able to keep simple abstractions in their head so they can concentrate their energies on their problem domain without worrying about language confusion. With C and many other languages, this is possible as they are smaller languages. C++ on the other hand: is there any language with widespread use that is so deep and complex? H…

It's not just the complexity. It's the complexity relative to the payoff. It seems like since C++ 98, the language has accreted a ton of new features that add complexity and decrease regularity without really carrying their own weight. Templates are a good example: lots of little features to make template mets programming easier to offset the fact that templates are a poor basis for metaprogramming to begin with.

Re: My Most Important C++ Aha Moments (2006)

#67
post #57

Earlier quoted context omitted.

> Where is this modern C++ culture that has resulted in large-scale codebases free of memory safety vulnerabilities? In any large scale C++ conference like CppCon. In tooling from Microsoft and Apple. > I haven't seen any evidence for this. A lot of vulnerabilities are found in modern C++11. Using C++11 idioms, or C with classes? > I don't see any way that the C++ Core Guidelines are going to be able to succeed in cr…

> In any large scale C++ conference like CppCon. > In tooling from Microsoft and Apple. Microsoft and Apple regularly ship memory safety vulnerabilities in their codebases that are written in modern C++. Their browser engines, for example. > Using C++11 idioms, or C with classes? Using C++11 idioms. C++11 doesn't actually do anything to mitigate use after free, for example. In fact, I think there's a reasonable argum…

The issue is not that C++ is 100% memory safe language, it is not.

Personally I would rather be using Ada or Modula-3 for the few use cases I still use C++.

However in the context of security minded developers that can only choose between C, Objective-C, C++ and nothing else, C++ is the only one providing the features to write safer code.

Of course if not all team members play ball it doesn't work, but it is better than not having an option at all.

Re: My Most Important C++ Aha Moments (2006)

#68
post #50

Earlier quoted context omitted.

Yes, it does. The majority of C++ programmers make use of: - RAII - String classes instead of char* überall - Vector classes instead of char* überall - new and delete instead of malloc()/free() and casts - References for out parameters instead of pointers - Real enums, specially since C++11, instead of #define - Smart pointers for memory management - Type based programming to reduce errors - Minimize the use of the p…

> Yes, it does. Where is this modern C++ culture that has resulted in large-scale codebases free of memory safety vulnerabilities? I've never seen even one , much less a "widespread culture". > The majority of C++ programmers make use of: None of this, empirically, results in safe code. > Most of the unsafe C++ code is written by the "C with C++" sub-community that are mostly C refugees forced to use a C++ compiler.…

> Robert O'Callahan and I have elaborated why in other posts.

One point of note is that O'Callahan's "Vapourware" post points out a problem that's solvable, it isn't some big blocker the way he claims it is. Your comment 162 days ago describes the real problem, or at least one of them.

Edit, because fuck:

> Where is this modern C++ culture that has resulted in large-scale codebases free of memory safety vulnerabilities? I've never seen even one, much less a "widespread culture".

The rest of your post shifts the question from "is there a culture of secure, maintainable, and understandable software" to "Is C++ software free of memory flaws." Are these concepts not distinct to you?

Why even bother replying, if you're going to drag the discussion into some corner like that?

Re: My Most Important C++ Aha Moments (2006)

#69

Earlier quoted context omitted.

This is my ignorance speaking, but with the gcc, clang, and msvc all fully supporting C++11, where are the holdups?

There are people which, for reasons good and bad, use very old versions of their tools. There are also C++ compilers other than gcc, clang and msvc.

And to share some of the less horrible reasons to be on older versions of tools:

You can't just download the latest version of MSVC and target the Xbox 360 or Xbox One with it - their SDK integrations aren't instantly forward compatible. Even if you could, you might fail cert - Microsoft requires you to use specific compiler versions, and specific compiler flags, in an effort to improve security. Keep in mind the 360 wasn't even x86 - just because the x86 compiler had been sufficiently tested for regressions for release, doesn't mean QA was done vetting the PPC compiler.

While Sony has been contributing upstream much of the clang work they've done to support the PS4, I don't know that everything has - and even if it has, I'd rather not spend the time to try and recompile clang myself just to embrace the most bleeding edge of compiler tech. I'd much rather just keep to whatever version Sony supplies. Some of their APIs come as binaries for C++ - I do not want to mix and match compiler versions!

...the above reasons have forced me to have multiple MSVC versions installed at the same time. Which isn't all that annoying until you target pre-release Windows 8 because Microsoft is your publisher and wants ModernUI apps, and you have to wipe - and reinstall - every few months to get on the latest version. And if you install in the wrong order, you get to restart from the beginning.

A number of game studios buy MSVC straight up instead of MSDN subscriptions for various reasons, so MSVC upgrades may cost tens of thousands of dollars (a bit under $1k per head last I checked.) Even if MSVC upgrades are 'free' for you (e.g. you have MSDN subscriptions), upgrading still involves:

1) Getting matching updated binaries for any third party C++ SDKs 2) Testing to ensure the optimizer hasn't found new an exciting ways to break your code via exploitation of (previously benign) undefined behavior. 3) Dealing with an updated IDE frontend, with all it's bugs, unupdated plugins, etc. 4) Reworking build scripts to correctly invoke the new build 5) (Re)installing MSVC across the entire studio, all build machines, etc.

Doing a VS2008 -> VS2010 upgrade of a large codebase required a rewrite of most of our build configuration, in my experience (Microsoft revamped things in terms of MSBuild.) VS2010 -> VS2012 was much less harsh - I could even share build configurations when we had to support VS2010 and VS2012 simultaneously - but getting everyone up and running again after the upgrade was still days of downtime for no gains on our end, except regaining the ability to pass certification.

More in the "bad" column: At home, I have hundreds of projects in my I:\home\projects\dead\ folder. As a result, I still keep VS2008 installed. (I also have VS2013 installed - I may skip VS2015 in favor of VS2016/2017? We'll see.)

Re: My Most Important C++ Aha Moments (2006)

#70

Earlier quoted context omitted.

qmail contained a buffer overflow that allowed remote root access , prevented only by having a low limit on available memory. http://web.archive.org/web/20160401021400/http://www.guninsk... djb is a smart and motivated guy and even he isn't quite capable of writing correct C code; how much chance does anyone else have?

qmail is supposed to be used with "softlimit" from daemontools. All decent tutorials mention that. Again, which C++ program has been even analyzed to that level?

Did it ever occur to you that if a C++ programmer of security mindset wanted to make something like postfix or qmail, they'd just pick a language that was garbage collected?
Post reply on HN