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

I would be happy with code that does what I intended it to do by default.


Do-What-I-Mean isn't possible. What Rust does give you is Do-What-I-Say which mostly leaves the problem of saying what you mean, a significant task but one that is hopefully what software engineering was training you to be most effective at.

One important trick is ruling out cases where what you said is nonsense. That can't be what you meant so by ruling it out we're helping you fall into the pit of success and Rust does an admirable job of that part.

Unfortunately because of Rice we must also rule out some cases where what you said wasn't nonsense when we do this. Hopefully not too many. It's pretty annoying when this happens, however, it's also logically impossible to always be sure, Rice again - maybe what you wrote was nonsense after all. So I find that acceptable.


All programming languages do what you say, the question is more about how easy it is to say something inappropriate.

For me Rust rarely hits the sweet spot since there are easier languages for high level programs (python, C#, Swift...) and for low level programs you usually want to do unsafe stuff anyway.

I can see usefull applications only where you cannot have a garbage collector AND need a safe high level language. Even there Swift's ARC could be used.


> All programming languages do what you say

By definition the Undefined Behaviour can't have been what you meant. So, all the languages where you can just inadvertently "say" Undefined Behaviour aren't meaningfully achieving this goal.

I must say I'm also extremely dubious about some defined cases. Java isn't UB when we try to call abs() on the most negative integer... but the answer is just the most negative integer again, and I wonder whether that's what anybody meant.


I think you have a misunderstanding of undefined behavior.

> So, all the languages where you can just inadvertently "say" Undefined Behaviour aren't meaningfully achieving this goal.

This is absolute nonsense.

You should generally avoid writing programs with undefined behavior.

C and Java can be used to write programs with defined behavior (even if you can't) that are used by billions of users every day.


No, I'm pretty sure I understand the nature of Undefined Behaviour well.

It's not nonsense, since writing this I have watched several videos in which people playing with newer languages say [of Rust] "Oh, I guess I got that wrong, I'll fix it" when Rust's compiler tells them what they wrote is nonsense, but they do not make similar corrections in the languages where what they wrote is UB because it's never brought to their attention.

It's human nature, I assume what I wrote is correct, the machine accepts it, I guess it was correct. Right? Nope, for several of these languages - including C and the various "C successor" languages like Zig or Odin - the compiler blithely accepts nonsense and it has UB - that's my point here.

You lump together Java and C at the end which is silly. Java doesn't have UB except narrowly via clearly labelled "it's unsafe to use this" features. On the other hand in C even adding 200 and 300 together may be Undefined Behaviour in some contexts and you need a compiler vendor chosen flag if you even want to be alerted to the most obvious examples of this because the language doesn't care that you're about to shoot yourself in the foot.


What is "Rice" referring to?


Rice's Theorem: https://en.wikipedia.org/wiki/Rice%27s_theorem

Or the "why we can't have nice things" theorem. Colloquially, anything interesting about a Turing-complete program is unprovable. You may have proved specific instance of this if you went through a formal computer science program and reduced problems like "this program never uses more than X cells on the tape" to the halting problem.




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

Search: