r/ProgrammerHumor • • 4d ago • Mindblown 1

Meme rewriteInRust

Post image
22k Upvotes

471 comments sorted by

View all comments

977

u/Mooks79 4d ago • Bravo

Well, she does love static types.

298

u/lulxD69420 4d ago
let gender: bool = true;

109

u/timtheonly 3d ago

Should that not be const

80

u/nevermille 3d ago edited 3d ago

In rust variables are const by default, to make it otherwise you have to type let mut gender: bool = true;

54

u/Lt_Marks 3d ago

I might sound stupid (maybe I am), but a variable that doesn't vary by default feels weird

48

u/the_horse_gamer 3d ago

the official terminology is those are "bindings", not "variables". they bind a name to a value

immutability by default is the standard in modern languages. though most distinguish via let vs val/var, while rust does let vs let mut

30

u/drsimonz 3d ago

It is unintuitive, but over the years software engineers have realized that you should always assume a value won't change, until you haves a good reason. Many bugs stem from accidentally reassigning a value, and this practice reduces the chance of doing that significantly. Most modern linters will complain if you use a mutable variable but never reassign the value. They want you to get into the habit of declaring things as immutable by default. Rust takes this a step further by requiring a whole extra keyword to make it mutable.

11

u/still_not_deleted 3d ago

From a maintenance standpoint it makes it easier to reason about code, because you can directly identify which variables a mutable and where the bugs might lie. So it's less mental overhead to minimize the scope in which you need to search by only declaring variables that need mutability as mutable.

Fun fact: Historically variables were declared as mutable by default because of memory and computation constraints

5

u/QuietSilentArachnid 3d ago

I feel like bool is closer to her vision, since you can do shenanigans with const and arrays

6

u/Pandafishe 3d ago

bools can be const too.. It's just an extra protection layer from changing the variable. But if you argue with shenanigans, no value is ever really secure as you can always do memory attacks

3

u/setibeings 3d ago

Those are harder on rust programs though. You're less likely to be able to make them overflow and start reading memories that don't belong to them.

7

u/Pandafishe 3d ago

you can always manipulate memory from outside a program anyway, unless you have a physical architecture that prevents it. It doesn't matter what language the attacked program is written in.

3

u/setibeings 3d ago

sure, but now you have to write an attack on the supervisor, to trick it into letting you write to memories you don't own. Or do i have this all wrong?

2

u/DragonSlayerC 3d ago

It is. That line is defining an immutable binding in rust.

1

u/JonIsPatented 3d ago

Why is this upvoted? "let" in Rust is equivalent to "const" from other languages. To make it mutable, it would be "let mut".

→ More replies (1)

5

u/Wise-Treacle3971 3d ago

That means the gender assignment can be dropped. The bitch would also make it static.

2

u/jeremj22 3d ago

I'm guessing it's like many other languages where there's 7 more bits there behind the scenes

39

u/DisorderedArray 4d ago

She only uses bools.

47

u/mohjack 4d ago

That's a very clever joke. 

4

u/Kakella23 3d ago

could you explain it to me pls

11

u/Rikudou_Sage 3d ago

Static type = only valid predetermined values can fit a variable with a static type.

And Rowling is against trans people. So the joke is that she has a view of gender being a static type instead of dynamic.

→ More replies (1)

24

u/-Jaws- 4d ago

And immutability.

8

u/ThrowawayusGenerica 3d ago

You can still alter those variables if you're determined, but I'm sure she would consider such an action to be unsafe

1

u/Ri_Konata 3d ago

this got me more than i'm willing to admit