Hacker News new | ask | show | jobs
by umanwizard 618 days ago
> Now, let me explain why I felt that way. First and foremost, the phrase "undefined behavior" only applies to C and C++ because the specifications of those languages define it. The statement that Rust has no UB does not make sense because Rust has no specification, and all behavior is defined by the default implementation.

There are at least three classes of definedness of behavior:

1. The behavior of a program is defined by a spec.

2. The behavior of a program is not formally defined by a spec, either because the language has no spec or because it's imprecise, but it's defined in a sociological sense: that is, if a compiler doesn't follow the apparent meaning of the program, the people who develop the compiler will consider it a bug and you can report it to mailing lists or GitHub and probably get support.

3. The behavior is definitely undefined: a compiler can do anything in response to the program and the developers of the compiler will not consider it a bug.

C++ has a lot of 1, comparatively not a lot of 2, and a lot of 3.

Rust has none of 1, a lot of 2, and a lot of 3. But safe Rust has very little of 3.