What is the characteristic of Swift

Swift: 10 compelling language features

by Hubert Schmid from 2014-06-29

Like any new programming language, it also brings Swift some features that set it apart from other languages. Still, there is one important difference to languages ​​like Ceylon, Clojure, Darts, Go, Kotlin, Scala and as they are all called: Due to the clear positioning of Apple too Swift the latter will very likely soon be one of the most widely spoken languages ​​overall. Correspondingly stands out Swift characterized less by innovative and experimental features than by a clear mainstream focus.

The following list shows ten outstanding features of Swiftdesigned to support software developers in their actual tasks. Some of the features can also be found in a similar form in languages ​​such as C #, C ++ and Java. But in this combination they are new and groundbreaking for contemporary software development.

  1. Almost an old shoe, but unfortunately it is still not a matter of course Type inference for local variables. Undoubtedly, there are many cases where an explicit type specification helps readability - what Swift also supported - but in most cases less is simply more.
  2. Consistently sets Swift on Properties instead of member variables. The so-called Getter and Setter methods become superfluous, which makes a significant difference, especially for Java developers, who typically have a particular tendency to do so.
  3. Contrary to the name, most of the local variables are now used for immutable data. Programming languages ​​support this with key words such as and, which are often omitted for the sake of readability. Swift turns that around and puts on Immutability-By-Default. For example, parameters must be explicitly marked with in order to be able to change them in the body of the method, and methods of value classes can only change the state if they are declared as.
  4. Often you want to summarize a few attributes without defining a new class. Swift supports this through in the language built-in tuples, whereby the elements can optionally be named. It is particularly interesting to use a method as a return type to simulate several return values.
  5. To avoid the Nile pointer problem, the type system differs from Swift between references that can be (optional) and those that always refer to an object. These are accompanied integrated optionals a special instruction as well as several operators in order to implement the most common concatenations briefly and concisely.
  6. In addition to literals for numbers and strings, Swift also Literals for arrays and dictionariesThe latter in particular visibly improves readability compared to variants without language support.
  7. Swift supported named parameters, i.e. when a method is called, the name of the parameter is also specified. It is noteworthy that the specification of the name when calling up can be mandatory and is also required for all parameters except the first without any further action.
  8. As Enumeration with Associated Values Swift denotes a data type that is most closely related to Case classes is comparable in Scala. It enables variant formation over unrelated data types including support for Pattern matching. In other programming languages, however, the inheritance mechanisms are often violated for variants.
  9. In particular, C ++ has the deterministic de-initialization popularized, which can also be found in Swift finds again. It solves the problem finally and try-with-resources equally simple and reliable - and without shifting responsibility to the user of the class.
  10. In Swift classes can be added without changing the code Class extensions expand. This applies to both methods, properties and protocols. This is insignificant for self-developed code - but it is essential for the integration of third-party libraries.

The list contains just a few of the many features of Swift. But the direction is clear: agility with sustainability, pragmatism instead of dogmatism and generalization instead of specialization. Overall power Swift a very good impression. The only question that remains is whether it will also be used outside of Apple's platforms.