snippetjournal

– notes, snippet codes, and my journal

Immutability and Mutability

leave a comment »

Immutable
+ No thread locks
+ Fast read and lookup
– Bad for objects that highly mutable (increase memory usage every time it mutates)

Mutable
+ Fast for highly mutable objects
+ Low memory footprint
– Thread locks

Where you use immutable/mutable depending on the objects and pattern utilized. Functional and Math programming requires immutability on all objects to ensure consistency with parallel execution. Object Oriented apps rarely needs immutability since object is reused over and over with high mutability.

1 very clear example of mutability : Try playing games and imagine if all the objects is immutable, including interaction between objects (player on terrain, player vs player, gravity simulation, etc) and if this immutable, how do you deal with the number of objects generated every time it mutates.

1 example for immutability : Math calculation that can be break down and spread across multiple parallel threads (calculating/simulating)

http://www.kaskus.co.id/show_post/56611221dc06bd54638b4568/4041/-

Written by snippetjournal

December 4, 2015 at 7:47 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: