DEV Community

Cover image for Pitch me on Swift
Ben Halpern
Ben Halpern

Posted on

Pitch me on Swift

Continuing the series! Feel welcome to dip in and weigh in on a past question.

Let's say I've never used Swift before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.

Oldest comments (12)

Collapse
 
warwait profile image
Parker Waiters

If you absolutely hate Objective-C, you may just love Swift 😅

Collapse
 
swiftui_dev profile image
swiftui_dev

Swift is really easy to start with if you’re new to development. You can also built great iOS/MacOS/WatchOS and TVOS apps with it. It’s also your only option if you wanna build native iOS Apps.

Collapse
 
mrgoonies profile image
mrGoonies

A fairly simple language to learn due to its simplistic syntax and features, although it is focused on native development for the Apple ecosystem, it can be run outside of Apple and we can work on the server side with the Vapor Framework. :)

Collapse
 
scrolllock profile image
Scroll Lock

If you want to develop for Apple devices, it's basically either Objective-C or Swift. Objective-C was introduced in 1984, Swift in 2014. Swift has many modern concepts and is being actively developed, Objective-C is in the past.
The question whether do you prefer Swift is actually not about language itself, but is about whether do you develop apps for Apple hardware. If you do - then use Swift, but if you work in other domain (let's say web or backend development) - choose something else as Swift has very limited adoption outside of Apple world.

Collapse
 
dillonmce profile image
Dillon McElhinney

Swift is a strongly typed and compiled language, which gives you some fairly robust guardrails against a whole class of bugs. You never get an unexpected null value. A function will never return a String when you were expecting an Int. Basically what TypeScript does for JavaScript only built in at the language level. And because it is compiled, you can get some surprisingly accurate error messages about what you're doing wrong and often you can get one or more suggestions on how to fix it.

So you get a bunch of benefits from the type system, but it doesn't have a lot of the downsides of most statically typed languages. It has excellent type inference so in many cases you don't have to declare the type. It has a solid generics system and virtually everything is designed around a hierarchy of protocols so you can easily reuse logic between types. If you use it long enough you'll probably run afoul of the type system at some point, but in many cases this is a good sign that you're headed down a rabbit hole and you should rethink your logic/architecture, because there is a better solution to the problem you're trying to solve.

Swift is incredibly extensible/customizable. You can create custom operators. You can rename types. You can extend any type. You can provide custom logic for checking equality (==) between two items of the same type, or two items of different types. You get sensible defaults, but at almost all levels of the language if something doesn't work the way you want it to, you can hook in and change it (this applies to the Swift language, not necessarily Apple's frameworks for iOS/MacOS/etc)

And best of all, you don't have to care about any of this stuff if you are new to Swift or new to programming in general. A helloWorld program in Swift will look virtually identical to one in JavaScript. As you learn, have questions, and want to try things you can learn about a given topic and add it to your repertoire

Swift is fun to read. Code in Swift can be very concise and clear. You can see everything you need to know, and it isn't cluttered up with stuff you don't care about. Semi-colons are unnecessary. White-space mostly doesn't matter so you can lay out your code in a way that is clear. You have separate argument and parameter labels in functions so you can write signatures that make sense at the call site and in the implementation. swift.org/documentation/api-design...

Swift has a great community. It is a relatively young language that is still changing and growing over time. Improvements are constantly being made. There are many people out there who love to learn and tinker and teach about what they are learning. It is, at least from my experience, a very encouraging community full of people who are trying to do and be better. Who want to see people succeed. Who are willing to offer help/mentorship/guidance/etc to new folks and people trying to get started.

And, so you don't think I'm blinded by my love of Swift, there are definitely still some rough edges. Strings for instance are handled in a technically correct way, but the interface is really hard to understand without doing a couple hours of reading about characters and Unicode and whatnot. Not super beginner friendly. The asynchronous/concurrent code story has been pretty rough until very recently and the kinks are still getting worked out. And SwiftUI, which is a common framework for new people to pick up right now as it is intended to be simple to learn and use, is a great facade that hides a lot of barely working complexity. It uses many of the complicated language features and works great until something breaks and then you get nonsensical error messages.

Collapse
 
gualtierofr profile image
Gualtiero Frigerio

Nice reply and I agree on the fact that Strings manipulation is one of the worse aspect of the language.
The only downside I see is that the development of the language is driven by Apple so you end up with features that are necessary for some specific frameworks, like SwiftUI that required the introduction of Result Builders for example and although you can write server stuff with it is mostly confined to Apple platform.
In the end, like it a lot especially compared to Objective-C. I started iOS development more than 10 years ago and the codebase I worked on are improved a lot since the introduction of Swift.

Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

There is only one real pitch,
If you want to make a nice app for Apple ecosystem, Swift is way to go.

I have recently worked with vapor, which is a swift language web framework, and my experience with language was amazing. It is a nice balance of modern features like kotlin, with a familiar architecture of c-like languages.

Syntax of Vapor, in my viewpoint, felt a lot closer to JS in code syntax, but other team members swore that language structure is closer to C in general.

Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

Also like to point out, that language itself is available on all platform, I was using manjaro while working on that project. So interested students can learn the language itself even if they don't have an apple system for making ios and mac apps.

Collapse
 
andrewbaisden profile image
Andrew Baisden

It is a modern programming language for building anything Apple. The bar of entry is low and you can even learn it on an iPad through the Swift Playgrounds app.

Collapse
 
rigelcarbajal profile image
Rigel Carbajal

I like Python and Swift languages, both for Server Side, Swift is much more than Apple applications, you can do backend (Vapor Framework) or Scripting in Linux, not only macOS haha.

Collapse
 
annakirst profile image
Annakirst

Can anybody tell which language like and why ? black magic spell to break relationship

Collapse
 
richardbray profile image
Richard Oliver Bray

I wonder if Ben will ever do one of these pitch me's for Haxe?
It's not a super popular language bit ot has a strong community.