Why did you learn OCaml?

I don’t want to turn this thread into a C++ thread, and I left it overnight before deciding whether to comment on this, but this morning felt sufficiently moved to do so. I am saying that I think C++ has serious problems, most notably with the attitude of the C++ standard committee who seem to be quite happy to have had the C++17 standard break previously valid C++11/14 code, particularly in its changes to object lifetime rules. Did you know that you cannot now construct even trivial objects (ints and so forth) in raw malloc’ed memory by assignment or memcpy() as in C - you have to use placement new. This will break shed-loads of previous code. And array placement new is totally defective and unusable. Furthermore it is no longer enough to comply with strict aliasing rules when considering pointer dereferencing - you now also have std::launder to consider. And they didn’t notice that std::uninitialized_copy() and cognate functions now, by their own rules, have undefined behaviour!

If you want to see something which makes you consider the competence of the committee, read this committee document pointing out defects in C++17: P0593R6: Implicit creation of objects for low-level object manipulation

You simply don’t get this kind of stuff in Ocaml, nor in Haskell or Rust for that matter. There is no way the C standard committee would do this kind of thing and I now try to avoid C++ in new projects. Something like Ocaml with C for the hairy or maximum-speed bits works well I think.

5 Likes