this post was submitted on 15 Nov 2023
149 points (100.0% liked)

Programmer Humor

421 readers
11 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
top 12 comments
sorted by: hot top controversial new old
[–] subignition@fedia.io 33 points 1 year ago

Definitely looks unsafe to me.

[–] jeffhykin@lemm.ee 29 points 1 year ago* (last edited 1 year ago) (1 children)

If you think that's good, then you're gonna love this "simplified" real code posted as a real issue on one of my Github repos.

Edit: updated link to address the stack-trace comment

[–] parlaptie@feddit.de 7 points 1 year ago* (last edited 1 year ago) (1 children)

That's not actual code though, it looks like some kind of trace. Notice the filenames at the end of each line.

The actual solution the issue opener there might be looking for is to disable C++ parsing, since it's not actually C++ code, it's just some text they pasted into VSCode and they're wondering why their editor can't handle it.

[–] jeffhykin@lemm.ee 2 points 1 year ago

Without thinking about it much, my understanding was that each line of the stack trace referred to a real line, even though the block as a whole wasn't a program.

But! because of this comment I went and checked the lines of those stack traces. And in fact, they're not real lines, just the C++ type expansion.

That said I've got a another half as bad example that is real so Ive edited the comment to point to that example instead.

[–] GissaMittJobb@lemmy.ml 12 points 1 year ago (1 children)

Since all of the expressions just wrap a None, I wouldn't be surprised if the transmutes basically get compiled to 0, making the assertion at the end assert_eq!(0 * 0, 0).

[–] tatterdemalion@programming.dev 8 points 1 year ago* (last edited 1 year ago) (1 children)

Nah these are the actual integer representations. Otherwise you would have Some(None) == Some(Some(None)) which is way too Javascripty for Rust folks.

[–] GissaMittJobb@lemmy.ml 2 points 1 year ago (1 children)

That's kind of wild, I double-checked and it's true.

Although I disagree with the second part, the Rust folks wouldn't care about the in-memory representation as long as the compilation is on point.

Looking closer at the final enum, I guess it's because there are nine possible cases for it, making the compiler pack it into 4 bits, with one number representing each? I checked and None is represented as 8, while 7 Somes containing a None is 0 and the full 8 Somes is represented by 1.

the Rust folks wouldn’t care about the in-memory representation as long as the compilation is on point.

Well I can't speak for everyone, but Rust is very intentional about supporting things like repr(C). At least some of us care a lot.

[–] vfye@toast.ooo 10 points 1 year ago

Peano arithmetic moment

[–] Fargeol@kbin.social 5 points 1 year ago (1 children)
[–] parlaptie@feddit.de 1 points 1 year ago

It's somehow inverted. If it was Peano, two would be represented by two Somes, not by six. I have no idea how this one works.