Live data from Hacker News

Was Rust Worth It?

jsoverson.medium.com

641–650 of 736 posts

Re: Was Rust Worth It?

#641
post #479

Earlier quoted context omitted.

Rust's compiler is the first one I've seen to use the word perhaps . My main gripe is that I still don't fully comprehend lifetimes and the compiler can't really help me every time, because it (understandably) errs on the side of caution.

Whenever you see weasel words like that, it means the compiler knows that the issue you encountered could be what it is saying but the necessary metadata to figure out for sure is inaccessible to it. It's the problem with classical stage-oriented compilers. A compiler designed for diagnostics from the beginning would end up looking like a plate of spaghetti where you can call type checking from the parser, to give an…

>It's the problem with classical stage-oriented compilers. A compiler designed for diagnostics from the beginning

I'm not sure any compiler, even one "designed for diagnostics," can gather the "necessary metadata" from inside my brain based on my original intentions. If the compiler could unambiguously interpret what I meant to write, it wouldn't have needed to fail with a compilation error in the first place. Whenever I see something like "perhaps" or "maybe" in a compilation error, the information just didn't exist anywhere the compiler could possibly get to, and it's just a suggestion based on common mistakes.

Re: Was Rust Worth It?

#642
post #338

Earlier quoted context omitted.

I rather use compiled managed languages like Swift, D and C# instead, they provide enough low level coding knobs for C and C++ style coding, while being high level productive. Would add Go to the list, but only when I really have to. Nim and Crystal could be alternatives, but don't seem to have big enough communities, at least for what I do. However I do agree with the conclusion, Rust is a great language for scenari…

> compiled managed languages like [...] C# I've been out of the windows development game for a long time, so I haven't used C# since it strictly required a VM... what's pre-compiled C# development like nowadays? Are there major caveats? If you can emit plain old binaries in C# with no runtime dependencies, that would make it a truly compelling language IMO. And as another question, what's the cross-platform (mainly L…

C# supports AOT since forever, NGEN was present in .NET 1.0. Not many people used it, because it requires signing binaries and only supports dynamic linking, with a performance profile towards fast startup.

On Microsoft side the Singularity and Midori experiments used AOT.

They influenced the AOT toolchains for Windows 8 store apps with MDIL (Singularity/Bartok), and Windows 10 store apps with .NET Native (Midori/Project N).

Now there is Native AOT, which supports CLI and native libraries,.NET 8 extends that to EF and ASP.NET frameworks. For GUI applications, maybe only fully on .NET 9.

Mono AOT has had support for ages, being used on iOS, Android, and Blazor.

Finally there is IL2CPP and Burst compiler from Unity.

Re: Was Rust Worth It?

#643
post #96

Earlier quoted context omitted.

So we shouldn't use Rust at all, since Rust is not completely memory safe since it let's you disable the borrow checker. We should be serious as professionals and use safe languages like Java, JS, Python, etc. But of course there are use cases where you need memory safety guarantees and bare metal performance. In those cases, sacrificing some memory safety by using Rust is an acceptable tradeoff I think.

> Rust is not completely memory safe since it let's you disable the borrow checker. No, it doesn't. What's interesting isn't so much that random HN posters believe this sort of thing, because hey, who needs to know anything about a topic to post their opinion on a forum right? No, what's fascinating is that this applies to people like Herb Sutter in his "cpp2" language, here's Herb: > I don’t like monolithic "unsafe"…

    fn trust_me_i_dont_need_a_borrow_checker (x: &'a mut u32) -> &'b mut u32 {
        unsafe { core::mem::transmute(x) }
    }

    fn main() {
        let mut owned = vec![40, 2];

        let mut_1 = trust_me_i_dont_need_a_borrow_checker(&mut owned[0]);
        let mut_2 = trust_me_i_dont_need_a_borrow_checker(&mut owned[1]);

        drop(owned);

        let undefined = *mut_1 + *mut_2;
        println!("The answer is {undefined}");
    }

Re: Was Rust Worth It?

#644
post #626

Earlier quoted context omitted.

Thanks for pointing out you didn't got what the whole point of the wrong design is about.

Thanks for confirming you'd rather be a hater than someone with justified opinions.

I am quite open about my opinion regarding most of Go's design decisions.

Re: Was Rust Worth It?

#645
post #398
post #231

I wrote a lot of rust, but after some years it still feels unproductive. I do a lot of zig now and I am like 10 times more productive with it. I can just concentrate on what I want to code and I never have to wonder what tool or what library to use. I know rust gives memory safety and how important that is, but the ergonomic is really bad. Every time I write some rust I feel limited. I always have to search libraries…

Given that Zig is memory unsafe it isn't either a good general purpose language. IMO a good GPR is memory safe (no C, C++, Zig), is easy to use(no Rust), has strong static typing (no Perl, Python, Ruby) and is "stable" (no Scala). Lots of choices remain: Java, Kotlin, Ada, D, OCaml..

From these, my favourite is D

Re: Was Rust Worth It?

#646
post #585

Earlier quoted context omitted.

That's the entire point we're making. Rust's type system forces you to deal with the problem early on and saves time towards the end. It's not like that's impossible with Python with addons like mypy. But Rust's type system goes beyond just data types - lifetimes are also a part of the type system. I don't know how you can tack that on to Python.

> Rust's type system forces you to deal with the problem early on and saves time towards the end. It's not like that's impossible with Python with addons like mypy. Definitely not - mypy's pretty good these days, and lots of people use it. > But Rust's type system goes beyond just data types - lifetimes are also a part of the type system. I don't know how you can tack that on to Python. Well, Python's objects are gen…

Lifetime analysis matters a lot for way more than just garbage collection.

File handles, iterators, mutex guards, database transaction handles, session types, scoped threads, anything where ordering or mutual exclusivity matters.

Re: Was Rust Worth It?

#647
post #537

Earlier quoted context omitted.

> At this point, I'm about as fast in Rust as I am in Python. This is factually impossible. For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages. This is not even considering more local complexities, like data structures with cyclical references.

I think this is a very valuable comment, and the replies don't do it justice. I strongly agree from my own and my peers experience with the sentiment that latency from zero to running code is just higher in Rust than Python or Go. Obviously there are smart people around and they can compensate a lot with experience.

[deleted]

Re: Was Rust Worth It?

#648
post #513
post #487

Earlier quoted context omitted.

The problem with C and to C++ is that it’s 2023 and the CVE list is still loaded with basic memory errors. These come from everywhere too: small companies and open source all the way up to Apple, Microsoft, and Google. We as a profession have proven that we can’t write unsafe code at scale and avoid these problems. You might be able to in hand whittled code you write but what happens when other people work on it, it…

It is, however those same companies aren't dialing full safe ahead knob either, hence why Microsoft just recently published a set of secure coding guidelines for C and C++. https://devblogs.microsoft.com/cppblog/build-reliable-and-se...

Quite annoying to read in my native language, German. Do they use automatic translations? It's full of grammar errors and mistranslations.

Re: Was Rust Worth It?

#649

Earlier quoted context omitted.

I used to be .NET dev and don't agree. Couple of reaons: 1) Modern Java is almost as good as C# with some things I can't give up in Java (static imports => succint code, Groovy Spock => succint tests) 2) Kotlin is better than C# 3) JVM has much much bigger ecosystem (almost all the apache projects are JVM oriented) and default web framework is much less code to type (SpringBoot) is much more productiv 4) JVM has wide…

Java is surely keeping up but I can't name single Java feature that I miss in C# or is implemented better in Java. I haven't used Java in a long time though, just occasionally I read about new Java features and I've never said to myself "cool, I wish I had it in C#". Static import are also available in C# for quite some time now (c# 6, released in 2015, and in C# 10 you can even make this import global for for projec…

Kotlin is younger and made better choices by default, like immutable "val" as default option.

Also since it's Jetbrains - IDE integration is superior compared to anything C# can have (including Rider...)

Re: Was Rust Worth It?

#650
post #190

Earlier quoted context omitted.

Can you give an example of non-C++ code that a modern compiler (MSVC, clang, g++ or something) successfully compiles with no diagnostics? I’m genuinely curious. If not, this just sounds like more C++ FUD because the spec doesn’t define everything under the sun and allows a certain amount of leeway to compilers for things like emitting different error diagnostics.

Consider: #define _FOO int main() {} Per the C++ standard ([lex.name]/3), this program is ill-formed: > In addition, some identifiers appearing as a token or preprocessing-token are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required. [...] Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the…

> Thus, the compiler theoretically has the liberty to emit whatever it wants for this program.

In theory, sure. In practice, what does it do? We can look and see.[0][1][2] (I don't know of any compiler that emits garbage in the example you listed). For some reason, there's this sentiment that's arisen that treats undefined behavior as some sort of bugaboo that's capable of anything and everything (including summoning nasal demons).

Here's a question that I can't find an answer to. Is machine code well-defined (as in, can it contain undefined behavior)? If the answer is yes, then all Rust programs can also contain undefined behavior, because they eventually turn into machine code after all. If the answer is no, then that means once a C++ program is compiled into machine code, the executable is a well-defined program.

This whole nasal demon garbage was a good hyperbole at the time to explain that, yes, undefined behavior is bad. But it's been taken to this extreme where people will use arguments like this to try and convince others that if your program has undefined behavior, then it could summon a nasal demon, because who knows what could happen.

In reality, that won't happen. In reality, a signed integer overflow can result in a meaningless program, or a security vulnerability, or many other bad things, but it doesn't mean that the compiled machine code is all of a sudden inventing new instructions at random that the CPU will happily accept. It doesn't mean that your program will turn your OS into a pac-man game. It doesn't mean that it's impossible to find the root cause of the issue and remove the undefined behavior.

In practice, undefined behavior means that your program is broken, but you can look at the compiled program and trace exactly what it does. Computers are machines, they behave predictably (for the most part). They fetch an instruction, execute the instruction, and read/store results to memory. If you look at the instruction and memory (the cache stored on the specific core that the processor is using), you can reliably predict what the CPU will do after executing that instruction.

And yes, multithreading exacerbates the effects undefined behavior and makes it more difficult to debug. But you can debug the issue, even if it means you have to look at the machine code directly.

So while, yes, a compiler can emit garbage when it encounters the example program you gave, using that as an argument for why undefined behavior is bad is dumb. Because in reality, compilers will do something that makes sense, and if it doesn't, you can just look at what it produced. In all the examples you listed, I'm sure that if you created a small example illustrating those situations, the compiled program would do what you expect it to. (Like in the case of having different default args, it will probably just throw an error like this[4]).

Sorry for the rant, it just annoys me that we can't discuss undefined behavior without somebody making an argument that doesn't matter in virtually every case. Undefined behavior is bad! But there are good, real, common examples that show why it's bad! Use those instead instead of talking about how compilers are technically permitted to spew trash when they encounter a program that looks normal, because I'd be very surprised if any modern compiler exists that does spew trash for a normal looking program.

This talk by Chandler Carruth seems pretty good on explaining the nuance of undefined behavior[5].

[0]: https://godbolt.org/z/zv4GhPK5E

[1]: https://godbolt.org/z/6obn7134G

[2]: https://godbolt.org/z/33cKcx5xs

[3]: https://en.cppreference.com/w/cpp/language/ub

[4]: https://learn.microsoft.com/en-us/cpp/error-messages/compile...

[5]: https://www.youtube.com/watch?v=yG1OZ69H_-o

Post reply on HN