News for hackers. Stuff that matters.
Re:Swift as a C Language REPL by hhas01 on Friday January 03, 2020 @10:59AM (#21946995)
Correct. `let` = constant binding, `var` = variable binding, and except for top-level (global) declarations they are always block scoped.

BUT, there is a gotcha: this “constantness” only applies to the name-value binding, not to the value itself. Thus you can still mutate the content of a let-bound value when that value is a class or class instance. Which kinda defeats the point of having the let/var distinction in the first place. C’s `const` may have its priorities backwards, but least it does what it says on the tin.

(And let’s not mention what a PITA Swift gets when you want to work with the contents of complex nested struct-based collections in a language that doesn’t have native pointers/references. Again, it makes C look good.)

There are no comments on this comment yet.