DEV Community

loading...

Swift and the Evolution of Modern Programming Languages

bradleyblacksound profile image Bradley Black ・2 min read

In the modern tech world, there’s significant overlap among the key players. Google and Apple, for example, develop augmented reality technologies side-by-side. In fact, they share an AR API of the same name. However, instead of consolidating around this shared interest, a competition emerges. This approach can absolutely lead to great tech, but it creates a conundrum for developers. Big tech firms tend to frame their breakthroughs within their product ecosystem, and devote fewer resources to cross-platform support. As a result, developers who want the agility to work across all tech platforms often find themselves in a bind. One step towards Google, or Microsoft, is a step taken away From Apple, or vice versa.

Meanwhile, an interesting thing tends to happen to incumbent technology. Its creators become tasked with its maintenance and upkeep, and can focus less on innovation. Meanwhile, competing companies looking for a greater foothold have to push exciting ideas into the marketplace to compete. Inevitably, this dynamic swings interest away from the incumbent and they are forced to reconcile their out-moded approach with new demands. One example of this is Apple’s Swift programming language.

Swift aims to bridge the gap between Apple’s keystone Objective-C language and popular scripting languages like Javascript and Typescript. Objective-C’s run began in the 1980’s, and in 2014 Apple decided it was time to begin its inevitable phase out.

Like Javascript and Typescript, the code is structured in a way that reads naturally. Of course, there’s no shortage of proprietary flourishes to distinguish it from its competitors. But the structural similarities are clear.

Syntax

In Javascript, const and let lend different types of functionality to variables. In Swift, there is no const, and the variable let is actually more similar to the Javascript const. The only difference is its value can be declared after initialization.

Swift

Let greeting
Greeting = ‘hello world’
//cannot be changed
Enter fullscreen mode Exit fullscreen mode

Javascript

Let greeting = ‘hello world’
Greeting = ‘new greeting’
//can be reassigned
Enter fullscreen mode Exit fullscreen mode

String literals in Javascript and Typescript rely on backticks to create a string that can interpret variables. In Swift, this process is accomplished with a ‘\’ escape character followed by the variable name in parenthesis.

Swift

Let timelyGreeting = “Good \(timeOfDay)!”
Enter fullscreen mode Exit fullscreen mode

Javascript

Let timelyGreeting = `Good ${timeOfDay}!`
Enter fullscreen mode Exit fullscreen mode

Arrays in Swift and Javascript are identical

Var colors = [“red”, “green”, “blue”]
Colors[3] = “orange”
//valid in both Swift and Javascript!
Enter fullscreen mode Exit fullscreen mode

Summary

This is just a brief exploration of the reasons for Swift’s recent rise in popularity and the way the language interprets to Javascript and Typescript.

Discussion (0)

pic
Editor guide