πŸ”₯ Poll: Which features of Swift stand out most to you?

I like a lot about Swift, really a lot, but probably my top 2 are:

  • progressive disclosure, more of a philosophy than a feature, but a philosophy behind many Swift features, allows to start simple and gradually include more complex mechanics in your code, and makes learning and teaching Swift a breeze;

  • easy-to-use, ergonomic value types, and the focus on value semantics are, to me, the most important Swift features by far, they completely changed the way I think about software engineering in general, and they make Swift stand out among languages that seem superficially similar but are in fact profoundly different, like for example Kotlin.

9 Likes
  1. Protocol conformance via extensions for existing types.

  2. Result builders.

3 Likes

The fact that it runs everywhere , is compiled, and is a cleaner language than either Rust or C++. For high productivity and manageability at scale, it competes with Java while being easier to deploy.

Love the new concurrency and actor stuff!

3 Likes

Upon true reflection on the question, the real star feature of Swift is, unequivocally, this community. Our collective care for the language, help for each other, and stewardship for its future makes us absolutely the best thing about Swift.

11 Likes

So absolutely true. I have not seen this level of expert, authoritative, polite, fast support anywhere else.

(I wish there were some way to take whatever makes Swift Forums so effective and do the same elsewhere.)

4 Likes

Yeah, the signal/noise ratio reminds me of the earlier days of usenet news (comp.sys.next.programmer and related feeds specifically). The active participation of the language core team and other experienced users from both Apple and others (ranging from Indies, academia all the way to other industry players) is a key asset without a doubt. It's definitely one important factor for us.

5 Likes

First class support for optionals and error handling are the two things that stand out the most for me. Especially the latter makes you think β€œthis is so obvious, how come no other language came up with this syntax before Swift?”. The fact that at the same time it managed to bridge legacy (i.e. Obj-C error handling) as well in such an elegant way still amazes me to this day.

5 Likes

Value semantics, specifically the fact that the mutability of an instance of a struct depends only on the variable it's assigned to (whether it's let or var).
This is what enables all swift data structures to avoid having to offer a mutable and a non mutable variant, which is amazing, and something unique to Swift among the mainstream languages if I'm not wrong.

1 Like

Only if we aren't counting C++ as mainstream. Although Swift still does it better. :P

2 Likes

Indeed, looks ok in C++:

struct Foo {
    const int x = 0;
    int y = 0;
};

struct Bar {
    const int x = 0;
    int y = 0;
    const Foo foo1 = Foo();
    Foo foo2 = Foo();
};

void test() {
    const Foo foo1 = Foo();
    Foo foo2 = Foo();
    const Bar bar1 = Bar();
    Bar bar2 = Bar();
    
    foo1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    foo1.y = 1; // ❌ Cannot assign to variable 'foo1' with const-qualified type 'const Foo'
    foo2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    foo2.y = 1;
    bar1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    bar1.y = 1; // ❌ Cannot assign to variable 'bar1' with const-qualified type 'const Bar'
    bar1.foo1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    bar1.foo1.y = 1; // ❌ Cannot assign to non-static data member 'foo1' with const-qualified type 'const Foo'
    bar1.foo2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    bar1.foo2.y = 1; // ❌ Cannot assign to variable 'bar1' with const-qualified type 'const Bar'
    bar2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    bar2.y = 1;
    bar2.foo1.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    bar2.foo1.y = 1; // ❌ Cannot assign to non-static data member 'foo1' with const-qualified type 'const Foo'
    bar2.foo2.x = 1; // ❌ Cannot assign to non-static data member 'x' with const-qualified type 'const int'
    bar2.foo2.y = 1;
}

We can still love it even if it's not unique!

2 Likes

Absolutely enums. They've massively changed how I build a lot of code and there's almost nothing bad about them.

Flipping things slightly, I could say that protocols also stand out a huge amount, but mostly because they form the bulk of the "hate" part of my love-hate relationship with Swift :stuck_out_tongue:

3 Likes

enuuum.

enum is enum, even if its rawValue is Int. Or if it's not RawRepresentable it's only enum. I missed this very much when I'm in the other languages.
More specifically its strictness and safeness.

2 Likes

I'd say enums, but IMHO they should be more ergonomic, e.g.:

enum E {
    ...
	case a(x: Int, Int)
}

var e = E.a(x: 1, 2)
let v = e.a // this is of type `(x: Int, Int)!`
e.a.x = 100 // change associated value field by name
e.a.1 = 200 // change associated value field by index
if let v = e.a { // optional binding
	v.0 ...
	v.y ...
}
let isA = e.a != nil
3 Likes

Just want to give a big thank you to everyone for the interesting responses so far. There’s no time limit here, so feel free to share if you haven’t already!

5 Likes

The overall effort to keep Swift syntax the most concise possible is the thing I love the most!

My favourite thing about swift is actually the core team. Not only are they excellent at jumping in to support users, but they are also very good at looking past community bias' through feature evolution and taking a very pragmatic approach to how swift should evolve over time. Sometimes there are issues with transparency but I believe that is due to being hamstrung by Apple policies rather than them not wanting to be open about certain things (it must drive a few of them crazy).

If we are talking about the language itself, my vote goes (like some others on this thread) to enum, I really miss its flexibility when moving to other languages.

3 Likes

There are a few, but the one I find myself missing most often in other languages is the extension system. Of the languages I work in, Swift is the only one that allows you to define static extensions on anything (or at all for that matter) and even define extension initializers. I also find the extension block syntax the most intuitive.

2 Likes

Yes, although it could be even better.

the flip side of this is it makes it immensely difficult to build source/documentation tooling for swift (compare with languages like java where the tooling is far ahead of ours). we also have a problem with so-called β€œdark API” that’s completely un-documentable and un-indexable (see explanation here), and i’m not sure if there exists any parallel to that problem in any other language.

it’s possible that this is one of the factors that has slowed uptake of the swift language among large organizations.

Custom operators.
It can make code much cleaner. I use it for vector and matrix : very nice to be able to write :

let dotProduct = vector1 β‹… vector2  
let crossProduct = vector1 ^ vector2
let squareRoot = √( number)
4 Likes