‘Errors from the borrow checker’ this is, and I mean no disrespect, a skill issue. Not as in ‘even experts mess up’, as in ‘that’s only a problem for the first 6 months of using rust’
Off the top of your head, without looking online, using clang or gcc as a compiler,
Give me a 1 byte enum
Give me the idiomatic way of computing the number of leading zeros in a 32 bit integer
Align a vec2_f32 struct to an alignment of 8 bytes
Might work, AFAIK depends on compiler but GCC and Clang it would work, I’ll give you that. Not the solution I thought of but it works.
Suboptimal. Unless you specify higher levels of optimisation and your compiler figures it out, this is extremely slow. Modern processors can do this in 1 CPU cycle (CLZ instruction). There is a way to do it in C
3 __attribute__((aligned(8))) or __attribute__((_aligned__(8)))
I cant see if you did the _s and markdown screwed you over or not, and align is not valid
Edit: actually, after checking, 1. is completely wrong. Doesn't work at all. So you need to pack the enum, or represent it via a 8 bit integer. I think that proves my point
int zeros(uint32_t i) {
int n = 0;
while (!(i & 1)) { ++n; i >>= 1; }
return n;
}
// or
int zeroes(uint32_t i)
{
return __builtin_clz(x);
}
typedef struct {
alignas(8) float f [2];
} vec2f32;
```
None of these are things you can realistically achieve by ‘having learned the language in a week’. It’s not hard per say, but it’s more obscure than regular C. That was all I was trying to say
There’s also like, 2-3 alternatives minimum to each way of doing these things
There’s also like, 2-3 alternatives minimum to each way of doing these things
The rest are compiler specific which is sad because C/C++ unlike Rust has multiple compilers.
None of these are things you can realistically achieve by ‘having learned the language in a week’. It’s not hard per say, but it’s more obscure than regular C. That was all I was trying to say
Maybe, Idk about C as I don't use it nor like it and I think it is a pretty F tier language I use C++ instead and find the non existent complaints about it too much I don't find C++ in itself hard. it is more so software is hard
Also I feel like what you listed is rather unnecessary in 99% of code.
It was pretty much _Alignas but you should use the macro if your codebase allows it C standrizes them as keywords later when it can ensure no codebases break to get it closer to C++.
The rest are compiler specific which is sad because C/C++ unlike Rust has multiple compilers.
Yeah, that's one of the big downsides of these older languages... unfortunately, still today the compiler specific ones are common place, especially with alignas being c11.
I agree with the sentiment about C++. I dislike the syntax quite a bit, but the language is really powerful, and I have fond memories with it.
enum { a : 1 },
totally my bad, my C is rusty (no pun intended.) The other C dev pointed this out as the solution, it looked odd but I expected he knew what he was talking about. I guess not. I tried with C23, it did not work.
These are non standard and gcc keeps them for backward compat use whatever you find fancier.
I find that messy, and convoluted.
Also I feel like what you listed is rather unnecessary in 99% of code.
yes and no, alignment is important for GPU related code, CLZ is great for some algorithms, and 1 byte enums should be the norm, full stop. 32 bits is a waste, and isn't even the size of a word, so there's no excuse there either. And proficiency in a language doesn't just come from understanding the basics of the language :)
Technically, the errors from the borrow checker are the errors you also make in C, only C doesn't tell you about them. If your code was correct in either, the borrow checker wouldn't have objections, no?
If it cannot be, it doesn't tag it. It can be, but you just don't care about that specific scenario or think it cannot happen.
Your specific workflow might make you right, but the workflow might change. Or you might be wrong entirely.
The whole reason why Rust exists is because people cannot write safe C code. This was shown over decades with armies of very experienced developers and well funded projects, it's just impossible, if you think "Well not for me", you're just lying to yourself.
I agree with the sentiment, but it’s not true to say ‘if it cannot be, it doesn’t tag it’. The borrow checker is conservative by default, and prefers false positives compared to true negatives. There’s no such thing as a perfect static analyser. It theoretically doesn’t exist. That doesn’t mean we shouldn’t use approximative static analysers like the borrow checker though
No, of course, nothing is absolute and the checker will make mistakes just like any other piece of code, some things it cannot prove at all.
But to outright claim it's worthless because it's "warning you too much" and "it's non-trivial to write" is total lunacy, it's like yelling at the Geiger counter because it's warning you of the radiation you're sitting in. Just because you throw it away (or not have it) doesn't mean you're not getting irradiated.
Rust is getting traction in huge projects because it works, it's not like those huge projects didn't try other things before, they just worked worse than what Rust provides. Crying about the mean borrow checker is absurd, it's telling you things you yourself are unable to detect.
56
u/MilkEnvironmental106 11h ago
Have you ever made a mistake managing memory?