Go 1/2 Proposal: Immutable Types
19 points| romshark | 7 years ago
https://github.com/golang/go/issues/27975
Please be sure to check it out and feel free to join the conversation! Even if this feature is never introduced to the language specification - reading the design document will make you a better Go developer, that I guarantee!
original design document: https://github.com/romshark/Go-1-2-Proposal---Immutability
x0re4x|7 years ago
my humble opinion: how much would "Immutable Types" add to the language? How much complexity would it add? Things can already be made immutable from outside by hiding them in private variables/struct elements.
The question is: why did Go became successful without having "Immutable Types"? (or "Reference Types", ADTs too please?) Maybe those things are just frills, "nice to have" features.
Example like "type ImmutableMapAndKey const map[const * const Object] const * const Object" looks like really ugly Go to me... this is starting to look like C++...
https://www.youtube.com/watch?v=cQ7STILAS0M (why Golang is Sucessful by Creator of Golang Rob-pike)
P.S.: I wouldn't mind having "Immutable Types", "Reference Types", ADTs, etc. in Go. But not if it means abandoning simplicity of the language.
noncoml|7 years ago
romshark|7 years ago
Yes, you can hide state behind interfaces and opaque types, but you don't take into account, that the implementations of those types and interfaces need to be reliable as well. An interface with read-only types, for example, can declare its methods immutable enforcing an immutable receiver type on the implementing functions which makes sure that it's always correctly implemented and doesn't mutate its object for sure! A field can be declared immutable to make sure it remains immutable after the object is initialized, and so on. Immutable types allow you to better express your intentions when implementing something because in a month from now you'll be a different person too and you won't remember certain implementation details like "why you shouldn't mutate this inner slice in this struct" etc.
The whole concept is actually composed of 5 fundamental rules that are relatively easy to pick up. It also shouldn't be compared to C++ or even C style const qualification, because it's easier and safer.
frou_dh|7 years ago
https://en.wikipedia.org/wiki/Cliché#Thought-terminating_cli...