Live data from Hacker News

My Most Important C++ Aha Moments (2006)

artima.com

51–60 of 84 posts

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

#51

> Visitor lets you define a new operation without changing the classes of the elements on which it operates. Yes, but that's not the real point. You can do that in other ways. Creating a new std::algorithm does that, for example. The real purpose is letting one function be polymorphic in multiple directions. This is called multiple dispatch. Some languages support this as a built-in feature, but C++ doesn't, so a cou…

You can use visitor to implement multiple dispatch, but that's not it's "real" point. The real point, as stated, is to allow polymorphic methods that aren't defined directly on the class.

I've seen a lot of implementations of the visitor pattern, and almost all of them used it for single dispatch.

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

#52
post #50

Earlier quoted context omitted.

I'm sorry, but C++ does not exactly have a culture of secure, maintainable and understandable software.

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.

I haven't seen any evidence for this. A lot of vulnerabilities are found in modern C++11.

> Also while the C++ community is pushing for safety with activities like the C++ Core Guidelines and reducing the amount of UB in the standard, the C standard community doesn't care at all.

I don't see any way that the C++ Core Guidelines are going to be able to succeed in creating a usable language that is memory-safe. Robert O'Callahan and I have elaborated why in other posts.

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

#53
post #44

Earlier quoted context omitted.

> safety Um, no. C++ can be safer than C (which is an incredibly low bar) but only if you carefully constrain yourself to certain subsets of the language, which is why the web is chock-a-block with byzantine "C++ coding standards" documents describing all the rules you have to follow in order to avoid shooting yourself in the foot.

>only if you carefully constrain yourself to certain subsets of the language I'm curious which subsets are included in this?

The answer(s) to that question take(s) the form of documents with many dozens or hundreds of pages. For example:

https://github.com/isocpp/CppCoreGuidelines

So not the sort of thing one can answer in-line in an HN comment.

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

#54
post #3

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

Among many reasons, I would choose C++ over those languages because it has operator overloading. Expressing 3D spatial math and linear algebra in a language without operator overloading is incredibly tedious.

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

#55
post #50

Earlier quoted context omitted.

I'm sorry, but C++ does not exactly have a culture of secure, maintainable and understandable software.

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?

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

#56
post #3

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

It all depends on what you are building. Objective C is absolutely fantastic for rapidly developing GUIs because of its dynamic runtime and flexible typing. On the other hand, C++ makes it a lot easier to write efficient, (relatively) safe data structures.

I find it extremely frustrating when I have to use either language in an area that it wasn't designed for.

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

#57
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.…

> 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 creating a usable language that is memory-safe. Robert O'Callahan and I have elaborated why in other posts.

Rust will become a sound alternative to C++ when:

- Libraries stop using nightly

- Rust developers can call OS APIs like COM on Windows without gymnastics. I mean with the same ease that Delphi, C++ Builder and Visual C++ integrate with COM.

- Rust developers can call OS X and iOS APIs with the same ease than Swift and Objective-C

- Has IDE support that can match what QtCreator, Clion, XCode, Visual Studio, C++ Builder, Keil MDK, ...

I really would like to see Rust one day supersede C++, but in what concerns C family of the languages, C++ is the safest option we currently have.

I have been part of the C++ community since the early days as Turbo Pascal and strong type refugee, and have followed how hard it has been for a language that is almost copy-paste compatible with C to earn the position it holds in the industry.

So until Rust gets some OS SDK love, bashing C++ community efforts to improve security won't get many adopters.

I keep on playing with Rust, but I get to write production code it still is JVM, .NET languages, Swift or C++.

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

#58

Earlier quoted context omitted.

> Private-really-means-deleted was a cool and very useful trick before C++11 Rather, until every compiler you need to target supported this specific C++11 feature. In other words, it's still a cool and very useful trick ;)

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

There are tons of C++ compilers to chose from, not everyone uses only those three.

For example on the embedded space many toolchains are still C++98, not even C++03.

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

#59
post #57

Earlier quoted context omitted.

> 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.…

> 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 argument to be made that C++11 is less safe than C++03 in terms of use after free, because of features like move semantics and lambdas.

And I'm not intending to argue "use Rust" here. There are plenty of other memory safe languages out there. I'm simply arguing that C++ is not memory safe, and it cannot be while preserving any semblance of backwards compatibility. The specific technical reasons for this have been elaborated in posts that I've sure you've seen. I'd like to see proponents of the idea that modern C++ is memory safe actually try to rebut those.

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

#60
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…

> 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 is not necessarily a hard thing to do, but in some languages, like C++ it was made impractical at first. Then, templates introduced some metaprogramming aspects with another layer of Turing-completeness. I can appreciate the usefulness of C++ and how templates contribute to it, though.

> Templates are, after all, one of very very few wholly functional, immutable languages out there.

XSLT too ;-)

> And template instantiation is the underlying force behind many of the modern features like lambdas that allow you to access that power without actually knowing templates well.

Lambdas roamed the earth long before templates.

> ... and if you can accept that you will never know the entire language and can just use those bits that make things easier, it is possible to have a healthy relationship with the language.

Agree.

Post reply on HN