diff --git a/README.md b/README.md index 10fef22..6d27135 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ versions of the Go 1.x programming language will continue to compile and work as expected. ### 2.1. Immutable Fields + +*onokonem: do we really need the immutable fields in mutable struct? what for?* + Immutable struct fields are declared using the `const` qualifier. Immutable fields can only be set during the definition of the object and are then immutable for the entire lifetime of the object within any context. @@ -114,6 +117,9 @@ func main() { ---- ### 2.2. Immutable Methods + +*onokonem: should we rename this one to immutable receivers?* + Immutable methods are declared using the `const` qualifier on the function receiver and guarantee to not mutate the receiver in any way when called. They can safely be used in immutable contexts, such as within other @@ -137,8 +143,8 @@ func (o *Object) MutatingMethod() const *Object { // It's illegal to mutate any fields of the receiver. // It's illegal to call mutating methods of the receiver func (o const *Object) ImmutableMethod() const *Object { - o.MutatingMethod() // Compile-time method - o.mutableField = &Object{} // Compile-time method + o.MutatingMethod() // Compile-time error + o.mutableField = &Object{} // Compile-time error return o.mutableField } @@ -197,6 +203,9 @@ func ReadObj( ---- ### 2.4. Immutable Return Values + +*onokonem: do we really need the immutable return values? what for?* + Immutable return values are declared using the `const` qualifier and guarantee that the returned objects will be immutable in any receiving context. @@ -362,4 +371,4 @@ considered of higher priority compared to other previously mentioned topics. ---- Copyright © 2018 [Roman Sharkov](https://github.com/romshark) -() \ No newline at end of file +()