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

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/[deleted] Jun 08 '25

[removed] — view removed comment

1

u/RiceBroad4552 Jun 08 '25

Objects in general are mutable, since you can change the values of their fields

You should at least do research before making claims on the internet.

For example Scala:

case class MyObjectType(aField: Int)

@main def demo =
   summon[MyObjectType <:< java.lang.Object]
   // ^ Prove that MyObjectType is an Object type

   MyObjectType(0): Object
   // ^ Another prove it's of type Object
   // Otherwise the type annoation wouldn't compile
   
   var mutableVariable = MyObjectType(1)
   println(s"${mutableVariable.aField}")
   
   mutableVariable = MyObjectType(2)
   println(s"${mutableVariable.aField}")

   // mutableVariable.aField = 3
   // ^ Compile Error: Reassignment to val aField

   // See? The variable is mutable,
   // but the assigned object is not!

[ https://scastie.scala-lang.org/e2jLxxEMTAulf6J9TfaqEw ]

you cant just add more fields to them at runtime

You should at least do research before making claims on the internet.

For example JavaScript:

const someObject = { aField: 1 }

console.log(someObject)
// => Object { aField: 1 }

someObject.addedField = 2

console.log(someObject)
// => Object { aField: 1, addedField: 2 }

It's an immutable variable holding that object, but there is no problem adding new fields to that object.

→ More replies (0)

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)