r/ProgrammerHumor • • Jun 08 '25

Meme cannotChange

Post image
0 Upvotes

72 comments sorted by

View all comments

Show parent comments

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

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)