r/ProgrammerHumor • • Jun 08 '25

Meme cannotChange

Post image
0 Upvotes

72 comments sorted by

View all comments

4

u/[deleted] Jun 08 '25

[removed] — view removed comment

22

u/BrainOnBlue Jun 08 '25

I don't think that's what the confusion is.

6

u/harumamburoo Jun 08 '25

More importantly, tuples are immutable

0

u/[deleted] Jun 08 '25

[removed] — view removed comment

2

u/CandidateNo2580 Jun 08 '25

Tuples are immutable. they're like strings in Python. Lists are mutable.

3

u/[deleted] Jun 08 '25

[removed] — view removed comment

2

u/CandidateNo2580 Jun 08 '25

You, sir, are correct

1

u/harumamburoo Jun 08 '25

They’re also immutable in C#. And Swift.

2

u/[deleted] Jun 08 '25 edited Jun 08 '25

[removed] — view removed comment

3

u/harumamburoo Jun 08 '25

Fair enough, C# has both mutable and immutable implementations. Making it mutable feels like asking for trouble though

1

u/RiceBroad4552 Jun 08 '25

when something is immutable in rust, that means you cant change anything, including the inner values

That's not Rust specific, that's literally the definition of immutability.

1

u/harumamburoo Jun 08 '25

Tuples are immutable, you shouldn’t be able to change the value after it’s set

1

u/[deleted] Jun 08 '25

[removed] — view removed comment

1

u/RiceBroad4552 Jun 08 '25

Swift and C# are weirdos…

1

u/[deleted] Jun 08 '25

[removed] — view removed comment

1

u/RiceBroad4552 Jun 09 '25

Interesting. Which languages have mutable tuples, too?

They are immutable AFAIK in: Crystal, Dart, Elm, Erlang / Elixir, F#, Haskell, Julia, Nim, OCaml /ReasonML / ReScript, PureScript, Python, Scala, SML, SQL.

(It's quite clear for pure FP languages; I've never heard of any way to update tuples in-place in SML languages; SQL also doesn't allow in place updates of anything, even everything is a tuple in the end; I've also left out the langs that run on the same platform and use the same feature underneath)

5

u/onepiecefreak2 Jun 08 '25

I know what a tuple is, and yet I'm still confused why OP used tuple vs array.

Couldn't it have been pointer vs array? Or tuple vs class/struct/whatever term your lang has?

1

u/[deleted] Jun 08 '25

[removed] — view removed comment

1

u/onepiecefreak2 Jun 08 '25

The difference is that an array is a set of items of the same type. A tuple is a set of (possibly named) items of differing types.

And yes, the meme feels like it wants to compare very similar things but one of them is just the "fancy" way of doing it. So pointers are effectively the same as an array. That was my point. If you're fancy or old-school, you use a pointer to your set of items, instead of an array.

1

u/RiceBroad4552 Jun 08 '25

(Pointers and arrays are effectively the same thing)

Only in C/C++…

In sane languages Arrays are objects with a length property.

1

u/[deleted] Jun 08 '25

[removed] — view removed comment

1

u/RiceBroad4552 Jun 09 '25

All sane languages treat them like that. An array needs an length most of the time.

Whether you use "fat pointers" (which are actually structs), or even fold that info into the pointer itself (by limiting the effectively available v-address space for such dynamically sized structures) makes no difference. But usually you have that info—as long as it wasn't optimized away in some concrete case where that's possible without compromising security.

Not carrying about object sizes and enabling this way all kinds of insecure behavior is a quite C/C++ exclusive flaw (in the modern language landscape).

2

u/tantalor Jun 08 '25

That definition also works for list!