After using Rust, C++ now gives me the ick
Can I replace java with rust?
I don't need to program, and haven't since college but Rust does intrigue me... It's odd how some of t looks like bash script in a weird way.
>>108261209Yes, if you want to replace your pee pee with an axe wound too.
>>108261230qrd
>>108261209yes pretty easily you'll finally start loving arrays again
I'm interested in learning rust just because everyone says it's difficult and it "forces you" to write good code, I want to know if this is real or just marketing.Probably will still stick to C for anything serious though
>OP is still being stuck at stage nhttps://www.youtube.com/watch?v=xt1KNDmOYqA
>>108261246Rust doesn't force writing good code, in fact, Rust code is often very bad.Only an expert C++ programmer willing to learn and make tradeoffs can write good Rust code that's both safer and not less efficient than equivalent C++
>>108261254>The borrow checker is just RAII!!!I'm afraid you're stuck in the -10N.Rust doesn't free you from writing shitty resources intensive code, however it does make it easier. Slices are fucking amazing the amount of zero copy code I've written is insane. Networking is so easy now
>>108261279Zero copy is a meme, also post code you useless retard, it's practically guaranteed that data between your code and network card is copied at least 3 times.
>>108261201Sepples and Rust are both overcomplicated, unreadable shit.Small, simple languages are better.
>>108261287>Zero copy is a memeThis is zero-copy code that would be a foot gun in c++/// Zero-copy parsing of network bytespub fn parse_payload( payload: &[u8], ) -> Result<(Command, &[u8]), ProtocolError> { ... }
/// Zero-copy parsing of network bytespub fn parse_payload( payload: &[u8], ) -> Result<(Command, &[u8]), ProtocolError> { ... }
>>108261317You didn't explicitly mark that those u8 slices have same lifetime so it is just as much of a "footgun" in Rust, I got burned by this before, Rust compiler didn't catch it. This is not better than in C++, if anything, it makes retards like you make such mistakes because they think that Rust compiler cannot have bugs.
>>108261299Rust and C++ are the same language.
>>108261230Saar
>>108261317Pretty much every language doesn't copy the backing buffer of an slice if you pass/return from a function. You've only ever been copying a struct that contains a length, cap, and a pointer to some memory, which is what Rust is doing here as well.
>>108261201>clangwho the fuck uses that corpo trash?
>>108261331You don't need to mark the lifetime you noob. The Rust compiler infers them. You only mark lifetime on structs these days, functions that don't have state don't need them
>>108261465not really. You're forced to use a buffer with a cursor in those langs and you have to manage the cursor and calculate the size.In c++ you would return a pointer and the length and you have manage both, if you decide to split the payload later you have to remember to update the length.With slices you don't have to worry about that. You borrow a portion of the buffer as if it's your own.In the example I gave you the wire format is [command][length][payload]I parsed the command, checked the length matches the payload length and then returned the command + payload slice as a result.
>>108261331dumb retard
>>108261201have fun with your gay legos
>>108261201This is not even a c++ issue. Its a malicious compiler issue. GCC and Clang have done immeasurable damage to computing.
>>108262198wrong, it's UB
>>108261201After using C#Both C++ and Rust give me the ick
>>108261201After using Rust, I no longer have a dick
>>108262228What UB is being invoked here?Also is it C++ specific because global objects or would this happen in C with printf, too?
>>108262462non terminating loops are ub in c++
>>108262462>cniles don't even know the standard>yet they say that Rust not having one is badpathetic
>>108261246>because everyone says it's difficult It's C++ with rainbow colored training wheels for retards and zoomers.
>>108262473I’m not against rust. Also, very few people are experts on the C++ standards (plural).But anyway I found https://stackoverflow.com/questions/76960441/benefit-of-inifinite-loops-without-side-effects-in-c-being-undefined-behaviorand it’s no longer undefined behavior in latest standards.
>>108262490>cnile reads stackoverflow instead of the standardI'm surprised you didn't ask an LLM
>>108262228"undefined behavior" is an excuse the compiler devs use to justify doing whatever. The standard is not a legal document to be picked apart by lawyers looking for loop holes, its meant to be implemented in good faith. GCC and Clang are not good faith implementations, they are malicious.
>>108262499The standard is behind a paywall :^) that being said, I have obtained it in the past and have read parts of it to help clarify things, but I have certainly not read all of it. That SO page links to relevant excerpts from the standard. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2809r3.htmlAs I’m reading this, it’s actually a really interesting question of how you define a trivial non-terminating loop. If you force the compiler to avoid a broad category optimisations here, you unnecessarily pessimise a LOT of code, especially GPU code. It even mentions Rust at one point had a bug relating to this optimisation. I wonder how Rust has solved this.
>>108261246Just learn typed functional programming. Haskell or Ocaml. That makes it impossible to write bad code, instead of taking the rust schizo option where you have a compiler that will allow code and a retarded inconsistent borrow checker that won't.
>>108262551dumb retard>>108262558>I wonder how Rust has solved this.Here is the Rust issue about this: https://github.com/rust-lang/rust/issues/28728Here is the commit that introduced the solution in LLVM: https://github.com/llvm/llvm-project/commit/2c74fe977daf8d1d4c8b64cdd6d3a9999a4b4655>Add an @llvm.sideeffect intrinsic
>>108262587lmao just from the tiny pfp I can tell “rust-highfive” is a tranny
>>108262652https://github.com/rust-highfive>Rust highfive robot>robotlmao just from this tiny post I can tell “Anonymous” is a dumb retard
>>108262660pardon me i suck cock
>>108261246>it "forces you" to write good code,It *forces you* to think about ownership and handling your errors.This can go both ways. If you get a barrage of false positive compiler/ borrow checker errors for stuff you are sure is safe, it might also desentisize you and make you call `unwarp()´ reflexively and copying structs very liberally and unnecessarily to make the borrow checker shut upthat said, I improved as a programmer by trying it due having to think deeply about ownership and how many assumptions I make when implementing a linked list in another language where rust forces me to spell them all out (or be lazy and copy everything)
>>108262470>non terminating loops are ub in c++jesus
>>108263569>dumb retard reads dumb retarded nonsense>believes itdumb retard
>>108263569>he wants his compiler to solve the halting problem as well as compile his code
>>108263590>halting problemIt's just an infinite loop you dumb N word.There is no problem
>>108261331based
>>108263687dumb retard, it's called lifetime elisionhttps://doc.rust-lang.org/reference/lifetime-elision.html>If there is exactly one lifetime used in the parameters (elided or not), that lifetime is assigned to all elided output lifetimes.
>>108263607while (true){ if (function_in_a_different_compilation_unit()) { break; }}optimize my anus
while (true){ if (function_in_a_different_compilation_unit()) { break; }}
>>108263452>due having to think deeply about ownership and how many assumptions I makeIsn't this just standard in languages with no GC.
>>108263718not a problem in rust:loop { ... }[\code]
loop { ... }[\code]
>>108263718ub is not caused by halting problem. instead c++ implementations assumes that loops are always terminating.
>>108261562C++ has std::span which is a slice. Spans aren't owning so you have to make sure whatever the span is looking at is still alive when you use the span but you only have to manage a cursor into the span, not the extents.
>>108263834wrong
>>108261201I appreciate C++ now more than ever, especially with LLM coding
>>108262587>Add an @llvm.sideeffect intrinsicThat's more or less how I've solved the problem in the C++ I write at work. It's a simple enough problem to solve.
>>108263718LTO just called. He told me you're a retard.
>>108263923I solved the problem by using Rust
>>108261562You guys don't do pointer arithmetic?
>>108261201Doesn't work on my machine, I just get an infinite loop. Clang 21.1.8 on Gentoo.#include <iostream>int main() { while (1) ;}void unreachable() { std::cout << "Hello world!" << std::endl;}
#include <iostream>int main() { while (1) ;}void unreachable() { std::cout << "Hello world!" << std::endl;}
endless loops stopped being undefined behavior in C++26
>>108261230
>>108261201>using RustI'd be more worried about the -ACK than the ick desu
>>108261279>zero copy>networkingEnjoy your TLB shootdowns, fucking retard.
>>108265250you have to pass -O3the ISO standard allows optimizing compilers to assume a loop with no side effects will terminate
>>108261317This isn't zero copy. You can't have zero copy networking unless you use a DPDK-compatible network card. Data is always copied once on the network card, once on the kernel and once on the userland program. If you use AF_XDP with eBPF or io_uring, you can pretty much eliminate one copy, at the cost of extra complexity, but you'll still have an extra copy.And the network card <-> kernel or kernel <-> userland copies are way more expensive than performing extra usermode copies, which you shouldn't be doing in the first place.That's the whole reason why userland network filters are so inefficient. Data has been copied three times before it can filter anything.If you use rust, you should really look into aya: https://github.com/aya-rs/aya
>>108263607>infinite loop>look insideit's finiteif your loop doesn't have a halting condition, then it's malformed in the first place. you're not even gonna pass static analysis when your halting condition can fail to trigger for some input.if your program is caught in an infinite loop, the only possibility for it to stop is to receive a signal (e.g kill), which will likely trigger improper cleanup, e.g if you had files to write to, socket to send a clean disconnect packet to etc.
>>108263753If you have an infinite loop in a pure function, and the caller of that function doesn't use the return value. Then the call can be eliminated as part of dead code analysis. Rust is very aggressive about that because it will parse the actual function's code to determine if it's pure or not.If your function does nothing, except loops for an eternity, then dead code analysis will optimize the code to a noop, even if you wanted that very long loop to act as a busy timer/delay. It's well documented in LLVM, and in general that's a bad use of loops. If you truly want an infinite loop, it should at least have one verifiable terminating condition, for instance a signal.
>>108263722Rust forces strict aliasing, i.e you may only have one mutable reference to another variable at a time. in theory that enables special optimizations (restrict keyword in C), but in practice it's really minimal. The main benefit is it prevents you from shooting yourself in the foot, like in C++ when you hold a reference to auto& ref = vector[7];then you mutate the vector and have a random chance of your reference becoming invalid, but 9/10 times nothing bad will happen.The way you solve that in rust, is that you store an index in the vector instead, or if you really need references and the data structure doesn't allow easy indexing, you wrap the value into Box/Rc/Arc. The language is designed so that whatever is shortest way to do something is usually the best way to it.
>>108268876>brain damaged cnile trying to justify this retarded shit
>>108268981Yet the only one sounding brain-damaged is you.
>>108261201Can somebody explain to me how the line gets printed? I get that the infinite loop is optimised away (dumb, but whatever), but how is the print statement run? It's in a separate function that's never even called
>>108269122https://godbolt.org/z/rexYM9381
i like rust because you can have tests right in the files you're testing. no more test sprawl
>>108261201>compiler detects waste of time code>removes itso whats wrong?
>>108269716it shouldn't call the function that isn't called