Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

I gotta say, reading this actually made me really excited about Rust. C++ without the annoying memory management but no GC-overhead sounds like a dream.


Just to temper your enthusiasm, the compiler errors can sometimes be irritating, especially when you want to do something the you are pretty sure will be safe. But on the whole if you work with it the pay-off is well worth the minor annoyances. Having the compiler always check your code for memory safety is a huge win for refactoring - C or C++ code bases get really brittle over time as developers forget what is actually going on. I would also say that the number of errors you encounter over time reduce as you gain an intuition for the rules.


> especially when you want to do something the you are pretty sure will be safe

(It's worth noting that often the compiler is complaining because it actually isn't safe.)


Indeed, I’ve been certain that something that it’s not letting me do is safe, only to realise a bit later that actually it was right in a subtle way.

There are certainly some valid things that the compiler will forbid which you then need to work around instead, but by and large I trust the compiler to be right more than I trust myself.

(Bear in mind, still, that these sorts of arguments of Rust’s superiority in such things are frequently only applicable for comparisons with languages like C++; often they are the sorts of things that a managed language would not have a problem with, though also not infrequently it would lead to things like data race.)


Yes! It is often showing a flaw in your mental model, which can be painful at first, but once solved it will ultimately result in more reliable code.


> C or C++ code bases get really brittle over time as developers forget what is actually going on

This is very true. And one of the culprits is a lack of modules, an shortcoming that Rust avoids. A module system for C++ is grossly overdue, and I'm not holding my breath that one will be forthcoming.


What's your definition of a "module" that is not a class, not an object file, not a .so, and not a namespace?

I'm not trying to be argumentative. I've seen this "C++ doesn't have modules" claim before, and I'm trying to get my mind around it.


Part of the reason that "modules" aren't in C++ yet is that there isn't a precise definition of what modules are or what they should be.

That being said, C++ doesn't have even the bare minimum of what would be considered a module system according to any definition. With a lot of hand waving, one should be able to more or less write:

    import std::vector;
...and have the compiler (not the preprocessor!) find the relevant declarations and definitions for std::vector. Probably also important are additional restrictions to give more control over when and how preprocessor macros affect client code.


C++ does not have modules. When people say modules they mean how the files compile, and the current way is #include directives which literally copy-pastes the contents of that file into the includer file. This is horribly horrible for compile times, and has been reviled for basically ever.

Here read this:

http://clang.llvm.org/docs/Modules.html


Right now the way you use a module in C++ is to tell the compiler to dump a subset of its source-code from that module into each file that uses it. Then you tell the linker to link in the objects from that module later.

This is a pretty ridiculous and highly inefficient way of doing things (Facebook improved compile times by crafting a server just to do the preprocessing for you).


Anecdotally, Rust is the most joyful language to program in for me at the moment. I find that I can express powerful ideas in the type system, with deep confidence that the compiler will catch my mistakes, and a strong mental model of how my program will actually execute. I don't know any other languages that "feel" that way. Perhaps D or Nimrod would, but there's only so much time for new languages...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: