Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

I think that is his point, he thinks Rust and C++ cannot do this. But is the default in C++ and well done in Rust.


sort by: page size:

All of those languages have a runtime that enables this sort of thing. That's not the case in Rust. It's a bit of an unfair thing to knock it for, given the restrictions.

You can do it non-properly in Rust as well, e.g. using unwraps, etc. but even then it's still way better than an UB-ridden component of a C++ codebase.

Absolutely, I was trying to communicate that this is true across a ton of languages. This one isn't super specific to Rust; others may be depending on the exact feature.

Not sure if I'm missing a joke, but the part commented out is in Rust (not C++) from the original post?

This is not an unique feature today, you can do the same in D and Rust and even C++14, I think.

Nope! Rust doesn’t have function overloading like C++. What would that code look like in C++?

(Rust has operator overloading - but that’s not the same thing).


Why do you say (3) does not exist? C++ has it (and it's one of the main reason why, at the moment, I wouldn't use Rust to do the things I do).

No, it's pretty much the same in C[0]. Sorry, my point was not laid out. It was not to be obnoxious, but that one can implement various pattern fairly succintly in C or C++ and thus "is difficult to do in language x" is not a very compelling argument there.

Rust has algebraic datatypes, memory safety, pattern matching, etc, - those are actual things that are, if not hard, then at least tiringly verbose to do in C and C++;

0: enumerating_parser now becomes struct enumerating_parser{}, the constructor becomes a factory function while next() takes in the parser as a state parameter.


I don't believe that it being written in Rust is a feature. The language it's written in is just an implementation detail.

It's all good; it's one of the things that's specific to our implementation. Other forms may or may not do this, but I'm pretty sure that it's novel to at least Rust, and maybe C++; there's some discussion that I think it can do this in some circumstances as well.

That's true of most languages, like C++, rust, etc.

Rust's behavior makes so much more sense! IMO, implicit conversions is one of C++ biggest weaknesses. Yes, it may save some keystrokes, but it can easily lead to subtle (or not so subtle) bugs.

But the way the Rust compiler works today is quite acceptable already. This isn't a Rust-the-language problem other than in secondary ways that are hard to address by definition (such as "movable" data being the default and Pin<> references being special), it's a Rust-the-library-ecosystem (including, but not limited to, std and/or core) issue. It can only be addressed as such.

The point is that while it's easy to do in C++, it's extremely error prone.

Rust encourages you to write code that works with things like slices and references instead of copying, because the compiler won't let you use them in a way that is error prone.


You mean there is no compile time way to accomplish that? Doesn't sound very Rust-like.

They are exactly the same practices that Rust has built-in into the language, so I'm not sure what you're hinting at.

That's the job of the language/compiler. Rust does a fine job of this.

I wish this was adopted more broadly, e.g. by Rust and other newer languages.

Fair enough. My argument here is more general than Rust itself, it's relevant to all languages with an Option type and no null. The verbosity can of course vary by language.
next

Legal | privacy