Mutability #2
Jomy10
started this conversation in
Syntax & language features
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Variables
Immutable variables will be declared using
let
. Mutable variables withvar
.Functions
Consider the following example:
someFunc
can be a static function, non-mutating instance function or a mutating instance function.There are multiple ways to express this.
For example, Rust takes the following route:
Swift takes the following approach:
Both approaches are explicit. What I like about the Rust approach is the explicit
self
as an "argument". This makes it very comprehensible that you should access the instance variables usingself.field
.Beta Was this translation helpful? Give feedback.
All reactions