Swift Language Highlights: An Objective-C Developer’s Perspective
raywenderlich.com
raywenderlich.com
var example = Dictionary<Int,AnyObject>()
I'll miss the duck typing, but having bought my house off C# work, I can work with this.What other languages have this? How is it often used? I've never heard of a similar type in, say, Haskell.
Good, because types and classes are different things despite what languages like Java and my beloved C# would have us to think.
"Object" as in Java is a type for any tagged box type. Primitives, such as "int", don't derive from Object, but can be promoted to a corresponding boxed type, such as "Integer".
The story is a little more complex in C#, where ValueType derives from Object and "value types", both primitive and user-defined, are truly subclasses of Object. Types not derived from ValueType are considered reference types.
In languages where genericity is supported, you don't need a common base class with a pre-defined set of methods, as you can give type constraints.
Java could also have done it with interfaces, but those were the days OO was becoming mainstream and interface (component) based programming wasn't yet well understood.
http://stackoverflow.com/questions/6479444/is-there-a-type-a...
Int is always Int instead of thinking about int and Integer. Scala handles boxing when the JVM requires it, but it is invisible to the programmer.
If so, that seems backwards, and too late to fix :-(
(not huge, but unfortunate)
Ruby (and coffeescript, and perhaps perl) uses a..b to indicate a closed range (i.e. including b), or a...b to indicate a half-closed range (not including b). Swift seems to do the opposite. My guess for how ruby (or predecessors) came up with this was by copying bash (or sh?), which has only the .. version.
To be honest, the .. vs. ... distinction is really confusing and error-prone, and a bad bit of syntax to include in any language, period.
* the Swift operators makes a surprising amount of sense (where Ruby's make very little): the longer operator yields the longer range and `0..10` yields a range of length 10. Think of it like this: the "center": dot is the range itself, the left dot includes the left bound, and the right dot includes the right bount. Thus `..` is "range with left bound included` and `...` is "range with right bound included"