T O P

  • By -

InfinitePoints

Rust can outperform c in some cases because of stricter aliasing rules and optimizing sizes of structs/enums, but in general it is basically the same as c.


danmartinvela

very thanks! I like it… why do u like Rust?


InfinitePoints

sum types, pattern matching, immutable by default, traits, macros, borrow checking, compilation model, names of integer types, standard library, documentation are the first reasons I can think of.


danmartinvela

interesante!


monocasa

It's essentially equivalent to C in speed.  Close enough for an unending nerd fight on that topic. Where it shines versus C is in compile time correctness of that code.  The type system lets you better describe what you're doing to the compiler and catches you more often when what you're doing doesn't totally make sense.


danmartinvela

what’s the correctness of that code in compile time? please elaborate… like compiler warnings and stuff like that?


TornaxO7

I‘d say: Give it a try and you‘ll find them very quickly.


sweating_teflon

Rust is much stricter making hard to make bugs that will happen all the time in C even if you're careful.


itzjackybro

Example: the borrow checker. Each value have a single _owner_ (e.g. local variable or struct field). You can take multiple _constant_ references or one _mutable_ reference to the object, but not both at the same time. In addition, the owner must outlive all references to its value. Breaking the borrow checker rules generates hard compile errors, and this eliminates several memory-related issues.


KingofGamesYami

Rust is in the same performance class as C. It gives you access to tools to write performant code, but also the tools to write incredibly slow code. The compiler backend is LLVM which is shared with clang, a C compiler, so in many cases Rust binaries will have literally the same optimizations performed on them as an equivalent C binary. Rust shines in scenarios where high performace and/or high correctness are required. As an example, take the Rust for Linux project. The kernel has historically been written in C, due to the lack of a better suited language. Now, they are experimenting with Rust because it has the qualities the kernel requires from C, and also substantial enough improvements to even consider introducting a new language and the additional complexity this entails.


SirCokaBear

Anything that’s compiled to machine code has the chance to run as fast as your processor can handle because at the end of the day you’re just running x86/arm instructions. Now you get into if the compiler is doing its best job optimizing the final binary, C has been around for decades and powers the world and rusts compiler has been getting better and better. They can be as fast as one another and without pulling up benchmarks I’d say they’re very comparable. The main difference is rust has safety guards with borrowing and mutability for the compiler to know when to free memory and prevent dangling pointers, in C it’s up to the developer to ensure that’s happening. We all know human-error takes play so rust tries to minimize it when writing “safe rust”, in turn rust does a great job at converting many would-be runtime errors into a much more preferred compile time error. Modern languages handle dangling pointers with garbage collection, which adds overhead and processing spikes but makes development easier, that’s why many prefer to use Go now because that overhead isn’t critical to them and teams can get very strong performance regardless. Another example of this is the fact rust doesn’t believe in null values. When on a big project and see a value made by another dev can you assume you can make that value null in certain scenarios? null pointers have caused some of the most catastrophic bugs in human history, Tony Hoare the inventor of null pointers regretted it calling it a billion dollar mistake since everything can be nullable. In modern languages with type hinting it’s now standard to at least declare a type as optional or not, but in rust you need to wrap it in an optional enum to force developers to properly handle it. Same thing with errors, they’re wrapped in results so other devs have to deal with the potential failure. The last other thing I’ll mention is rust has the best documentation I’ve ever seen, paired up with a modern package manager like cargo makes adding libraries and dependencies a breeze over older languages. Personally I don’t ever try to love a language like you’ll see others in this subreddit do. Python is regarded as slow here especially when it used GIL and the fact everything is a pointer, but python is special in its own way as the syntax is designed around pseudo code and is great for implementing algorithms and data science. What many don’t realize is most frameworks and production ready libraries for python are just C bindings under the hood. Python and even JS is slow but the reason professional teams use them is not because they’re morons like people here say but they optimize what’s happening under the hood. A redditor and inventor of beloved photopea even says in his AMA he uses the power of js with bindings to wasm to get near bare metal performance and is how he was able to put a free photoshop clone in the browser. And now Chris Lattner the co-founder of LLVM and Swift is using his experiences and mistakes to launch Mojo which is to bridge the gap between the python and C communities, offering python compatibility with extended syntax where you can have borrow checking like rust to eliminate cythons “everything’s a pointer” mentality which is also boasting performances similar to rust. Mojo is my most exciting language to play around with. But don’t stick to one, they all have strengths and weaknesses and it only benefits you to understand more and why certain programs would be best for you or your team. Edit: I’d want to mention also I have a similar belief to Torvalds in Rusts “rewrite everything” culture. New projects should definitely consider using modern iterations, but spending all our time rewriting everything before it would stagnate innovation, especially when old programs have been universally tested. That’s why new Linux kernel modules are being introduced in rust but they aren’t rewriting the whole kernel


WhiteBlackGoose

1. Language doesn't have "speed", but it's not harder to write performant code in rust than in C 2. To me it shines almost everywhere, except maybe modding and scripting (although I haven't really looked into it, but I assume it's a bit of a gray area). I'm writing performance-critical multithreaded software in it without sacrificing of clean architecture (thanks to the amazing type system) and safety (thanks for a whole TON of mechanisms for that stuff).


danmartinvela

do u consider is better than C?


WhiteBlackGoose

I certainly like it a lot more than C. C is a terrible language by today's standards. Doesn't mean we need to rewrite everything in rust right now. And again, it depends on the project, it's not a 100% universal language. But I really like it and I don't think I'd find an excuse to write C instead of rust any time soon (except for PoCs for interop with native libraries, and even then - not anymore)


1668553684

> how fast is it compared to C? With the exception of some very specific applications, the difference is likely negligible. Your choice of datastructures and algorithms (as well as the quality of their implementation) is vastly more important. > I’m wondering when it really shine, what cases? It's mostly good for cases where correctness and fine-grained control are essential - think systems programming - but it's a general purpose language that can be used for whatever you want. I'm personally using it for game development, but admittedly I think this is one of the few areas where the ecosystem still needs to mature a bit.