
Swift Language Highlights: An Objective-C Developer’s Perspective - davidbarker
http://raywenderlich.com/73997/swift-language-highlights
======
afternooner
On containers, while it's entirely possible to constrain the type, it's also
possible to use AnyObject

    
    
        var example = Dictionary<Int,AnyObject>()
    

I'll miss the duck typing, but having bought my house off C# work, I can work
with this.

~~~
steveklabnik
The first time I saw this idea was in Rust, which calls its type Any. I
haven't seen the need to use it yet, but this seems like a decent case.

What other languages have this? How is it often used? I've never heard of a
similar type in, say, Haskell.

~~~
Xlythe
In Java, everything extends Object, so something like List<Object> will let
you put anything you want into it. I should play with more languages, I didn't
realize that was an uncommon feature.

~~~
steveklabnik
Oh, duh, of course that's true. For some reason "the parent class of every
class" is different than "a type explicitly for any type" in my brain.

~~~
noblethrasher
>For some reason "the parent class of every class" is different than "a type
explicitly for any type" in my brain.

Good, because types and classes are different things despite what languages
like Java and my beloved C# would have us to think.

~~~
brandonbloom
To clarify:

"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.

------
Roboprog
Did I read that right about the range operators: triple-dot (...) is like the
inclusive range that perl, python, ruby (etc?) denote with double-dot (..),
and in swift double-dot (..) is actually a special range operator that
excludes the upper limit?

If so, that seems backwards, and too late to fix :-(

(not huge, but unfortunate)

~~~
jacobolus
Python has much more sensible range operations (based on slice syntax for
array slices, or the arguments to the build-in 'range' function) that are
unrelated to this.

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.

~~~
andybak
First thing I looked for in Swift was support for Python's slicing syntax.
It's a shame they decided against using that.

