As more-or-less a Ruby monoglot, this has never been clear to me... The answers to this question explain how type-safety functions in Swift (and generally, I am guessing), but doesn't answer 'why'? Surely there is some performance or security benefit, but what is it exactly? Or is the benefit purely the strictness of the value later on -- the developer has the benefit of knowing some function will definitely perform (.each on an Array, for instance) or when run.
What trade-offs am I unknowingly adopting when I do this in, say, Ruby
x = Float.new x = 3 x = "a" x = [a, "a", ['a'], {a: 'a'}] versus what benefits am I receiving in it's equivalent in Swift:
var v: String var x = 3 var y = "a" var z = [ a, "a", ['a'], ['a': 'a'] ] ?
Apologies if this is too basic or redundant -- I didn't find a similar question searching SO.