[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: images-20.jpg (35 KB, 626x490)
35 KB
35 KB JPG
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.
>>
>>108261209
Yes, if you want to replace your pee pee with an axe wound too.
>>
>>108261230
qrd
>>
>>108261209
yes pretty easily you'll finally start loving arrays again
>>
File: 1771928790945636.gif (937 KB, 498x224)
937 KB
937 KB GIF
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 n
https://www.youtube.com/watch?v=xt1KNDmOYqA
>>
>>108261246
Rust 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
>>
>>108261279
Zero 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.
>>
>>108261201
Sepples and Rust are both overcomplicated, unreadable shit.

Small, simple languages are better.
>>
>>108261287
>Zero copy is a meme
This is zero-copy code that would be a foot gun in c++
/// Zero-copy parsing of network bytes
pub fn parse_payload(
payload: &[u8],
) -> Result<(Command, &[u8]), ProtocolError> { ... }
>>
>>108261317
You 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.
>>
>>108261299
Rust and C++ are the same language.
>>
>>108261230
Saar
>>
>>108261317
Pretty 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
>clang
who the fuck uses that corpo trash?
>>
>>108261331
You 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
>>
>>108261465
not 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.
>>
>>108261331
dumb retard
>>
>>108261201
have fun with your gay legos
>>
>>108261201
This is not even a c++ issue. Its a malicious compiler issue. GCC and Clang have done immeasurable damage to computing.
>>
>>108262198
wrong, it's UB
>>
>>108261201
After using C#
Both C++ and Rust give me the ick
>>
>>108261201
After using Rust, I no longer have a dick
>>
>>108262228
What UB is being invoked here?
Also is it C++ specific because global objects or would this happen in C with printf, too?
>>
>>108262462
non terminating loops are ub in c++
>>
>>108262462
>cniles don't even know the standard
>yet they say that Rust not having one is bad
pathetic
>>
>>108261246
>because everyone says it's difficult
It's C++ with rainbow colored training wheels for retards and zoomers.
>>
>>108262473
I’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-behavior
and it’s no longer undefined behavior in latest standards.
>>
>>108262490
>cnile reads stackoverflow instead of the standard
I'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.
>>
>>108262499
The 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.html

As 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.
>>
>>108261246
Just 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.
>>
>>108262551
dumb retard

>>108262558
>I wonder how Rust has solved this.
Here is the Rust issue about this: https://github.com/rust-lang/rust/issues/28728
Here is the commit that introduced the solution in LLVM: https://github.com/llvm/llvm-project/commit/2c74fe977daf8d1d4c8b64cdd6d3a9999a4b4655
>Add an @llvm.sideeffect intrinsic
>>
>>108262587
lmao just from the tiny pfp I can tell “rust-highfive” is a tranny
>>
>>108262652
https://github.com/rust-highfive
>Rust highfive robot
>robot
lmao just from this tiny post I can tell “Anonymous” is a dumb retard
>>
>>108262660
pardon 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 up
that 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 it
dumb retard
>>
>>108263569
>he wants his compiler to solve the halting problem as well as compile his code
>>
File: 1771958100905282m.jpg (144 KB, 662x947)
144 KB
144 KB JPG
>>108263590
>halting problem
It's just an infinite loop you dumb N word.
There is no problem
>>
>>108261331
based
>>
>>108263687
dumb retard, it's called lifetime elision
https://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.
>>
>>108263607
while (true)
{
if (function_in_a_different_compilation_unit()) { break; }
}

optimize my anus
>>
>>108263452
>due having to think deeply about ownership and how many assumptions I make
Isn't this just standard in languages with no GC.
>>
>>108263718
not a problem in rust:
loop { ... }
[\code]
>>
>>108263718
ub is not caused by halting problem. instead c++ implementations assumes that loops are always terminating.
>>
>>108261562
C++ 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.
>>
>>108263834
wrong
>>
>>108261201
I appreciate C++ now more than ever, especially with LLM coding
>>
>>108262587
>Add an @llvm.sideeffect intrinsic
That'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.
>>
>>108263718
LTO just called. He told me you're a retard.
>>
>>108263923
I solved the problem by using Rust
>>
>>108261562
You guys don't do pointer arithmetic?
>>
>>108261201
Doesn'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;
}
>>
endless loops stopped being undefined behavior in C++26
>>
File: GxFQvw4XAAApfWb.jpg (99 KB, 1117x1080)
99 KB
99 KB JPG
>>108261230
>>
>>108261201
>using Rust
I'd be more worried about the -ACK than the ick desu
>>
>>108261279
>zero copy
>networking
Enjoy your TLB shootdowns, fucking retard.
>>
>>108265250
you have to pass -O3

the ISO standard allows optimizing compilers to assume a loop with no side effects will terminate
>>
>>108261317
This 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 inside
it's finite

if 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.
>>
>>108263753
If 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.
>>
>>108263722
Rust 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
>>
>>108268981
Yet the only one sounding brain-damaged is you.
>>
>>108261201
Can 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
>>
File: lol.jpg (542 KB, 3964x2704)
542 KB
542 KB JPG
>>108269122
https://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 it
so whats wrong?
>>
>>108269716
it shouldn't call the function that isn't called



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.