bitjammer
(Ashley Garland)
1
An open question for you.
What are the current language features of Swift that stand out to you most in your mind?
Think about something that you found especially unique and/or beneficial, something you just feel everybody ought to hear about when seeing Swift for the first time regardless of their experience.
No matter what it is, it would be really interesting for me to see what about Swift touched you in a positive way from your experience and not what you think others want to hear. Don't worry, this is not a quiz!
10 Likes
Jae
(Jae Kong)
2
Codable.
Protocols, Extensions, Concurrency and many other stuff are all nice but there are tons of languages that supports something similar with somewhat similar usability. But Codable, I haven't seen something that is this easy to use and safe to use at the same time!
4 Likes
ahti
(Lukas Stabe 🙃)
3
Maybe too simple, and you can't not hear about it when starting Swift, but I constantly miss it in other languages: Argument labels on almost all parameters.
It just takes away so many moments of "ok, just gonna check the declaration again to remind me which parameter at this call site is which", especially when browsing unfamiliar code on something like github or somewhere else without tooling to quickly show the signature/docs.
40 Likes
This is perhaps unfair since I help maintain it, but I think the post-UTF8-rewrite implementation of String is one of the more interesting contributions Swift has made to the world. I'm not aware of any other language that attempts anything close to its level of ambition. There are, admittedly, reasons why nobody else has attempted this model (for example, random access indexing being O(n)), but I personally think the benefits are so compelling that over the next 5-10 years we'll see more new languages going down this path.
29 Likes
bitjammer
(Ashley Garland)
5
Too simple? Not at all! Besides, there is no such thing, especially with programming languages :)
Mordil
(Nathan Harris)
6
The two examples I always give to programmers of other languages:
Argument labels and enums.
Enums having the ability to be represented as Strings or Integers makes them more capable than plain C enums, and the ability to go further to have associated data payloads means building highly expressive state machines with the help of the compiler.
15 Likes
toph42
(Topher Hickman)
7
The enum is my answer too, and I’d like to point out something not everyone is aware of. If your custom type is expressible as a literal and you use that literal to define the raw values you can make your custom type the raw value type of an enum.
9 Likes
It's one of the original features: Optionals and the mechanisms of optional chaining. Replicated now in even dynamic languages, that single feature drove home the idea of "fully specified" code vs. code with "unspecified results", and has probably been the single most impactful "safety" improvement in terms of the code I've written.
21 Likes
My vote goes to overall usability and dev friendliness. It's the most beautiful language out there while still being type safe.
Occasionally I go back to C++, and Rust (which I love with all my heart), and they both burn my eyes and fog my mind until I adapt. It's never the other way around.
7 Likes
AutoDiff
Swift is the only language with built-in differentiation for gradient descent optimization. Everywhere else, you have to re-implement it from scratch (Python TensorFlow, PyTorch, DL4S, etc.).
7 Likes
idrougge
(Iggy Drougge)
12
-
guard clauses
- dot notation.
Both serve to make your code so much succinct, and it is something I always miss when dabbling with Kotlin.
And yes, argument labels are indispensable. A lot of languages have labeled constructors for structs, yet they eschew them for functions, even though those functions may be convenience constructors.
12 Likes
tera
13
Features that made SwiftUI possible.
1 Like
Really just that ability to make a domain-specific language out of Swift like Regex string processing using function builders or building ML models out of structs and calls to gradient using trailing closures.
2 Likes
My fave bits: Totally optional abbreviations: Skip the closure label, skip the return, skip the parameters, skip the braces, or use them all if you need a high degree of readability.
The result builder stuff is awesome.
No semi colons unless you need 'em.
The top level can be a script if ya wanna, making Swift a potential great system script language replacement.
3 Likes
I am especially pleased with algebraic data types, especially recursive
enums, and binding pattern matches. They have let me write algorithms
for a symbolic calculator and a tree-shaped data structure in a
straightforward way.
I also appreciate named function arguments.
Dave
1 Like
icanzilb
(Marin Todorov)
17
Hey Ashley
I always thought Apple's guidelines to writing semantic Swift code are unique: Swift.org - API Design Guidelines I feel that Swift has become a very complex language that ought to be difficult to pick up as a beginner. If authors adhered more to these guidelines above, it could make it much, much easier to understand even for people who are just starting with the language.
6 Likes
This is perhaps unfair because I worked on it, but I hope the next generation does better. Don't lazily bridge in a different programming language's string, it's not worth it. 
16 Likes
AlexanderM
(Alexander Momchilov)
19
I think my favourite thing is the not “holy” nature of built in types, and the fact that you can write extensions on them
Why should I not be able to write 123.squared()? “Because it’s a primitive value.” … “so? Hold my beer”
17 Likes
- Enums with associated values
- Property Wrappers
So simple yet so powerful!
6 Likes