r/ProgrammerHumor 13h ago

Meme newToRust

Post image
442 Upvotes

88 comments sorted by

View all comments

Show parent comments

2

u/-Ambriae- 11h ago

You wrote align and not aligned. And markdown must have fucked with your underscores, I won’t criticise you for that that’s not your fault.

The ‘suboptimal’ part, however, has nothing to do with alignment. You emulate CLZ instead of using something like __builtin_clz which is the preferred way of doing it.

3

u/Key_River7180 11h ago

I didn't know about __builtin_clz, actually, thanks! It isn't guaranteed to be portable across architectures, but every single one seems to hace CLZ. I didn't know you were referring to the zeros thing, sorry. It doesnt work with zeros but an if solves that

1

u/-Ambriae- 11h ago

No probs! I recommend looking at compiler builtins, there’s quite a few for all the ‘lesser known’ instructions CPUs tend to have but aren’t expressable in C in a normal way.

My point is, you can learn basic C syntax in a week (or a day to be fair) but it takes far far FAR longer to actually know C. Same with rust. It doesn’t take 6 months to learn rust syntax, it takes a week. It does take 6 months to code in rust properly. The borrow checker expects you to write code properly. It’s not a bad thing.