Ya know the more I reflect on the languages I know the more I realize that outside of functional languages none of them really handle immutability well.

Consider that you want most of your objects to be immutable most of the time. Thats all well and good till you realize you want to be able to edit the objects in such a way that it creates duplicates that have some data changed but are likewise immutable.

This tends to stop working, almost entierly, once you get into subclassing. If you parent class has a method that returns a copy of itself with some data modified, this will break in children classes, since you want children classes to return instances of itself, not its parent.

Its not that you cant fix that, but the code gets very ugly very quickly. Generally you are forced to let the code handling the classes do the copying and editing itself, but that is pretty ugly too.

I have had this pattern problem in almost every OO language i messed with, Java, Ruby, Python, etc.

@freemo Eiffel language manages immutable types in a rather good way. They are called "expanded" in the Eiffel jargon, but you can think to them as "value" instead of "references/entities". So, you have no references to them, but only explicit values. The classic example is an INTEGER NUMBER, or a BOOLEAN or a POINT. You cannot change 5 in 10. 5 is a value.

@mzan Thats common for most languages actually where primitive are immutable and passed by value and all other types are passed by reference. This is true for Ruby and Java for example.

Different languages define primitives differently for example in Java strings are immutable but passed by reference so effectively the same as passed by value for these purposes. In ruby however strings are mutable.

@freemo .. only for sake of security. In Eiffel you can declare new expanden/value types (i.e. an RGB color, a 3D Point and so on), while in old versions of Java you cannot declare new primitive types. Soon, you can do the same also in Java.

Follow

@mzan I cant think of why i would need that for security really...

ยท ยท 1 ยท 0 ยท 0

@freemo ehm sorry, bad English on my side. I mean "only for being sure to be on the same page"

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.