The Swifting Brain

I’ve just started learning Swift, and one of the best practices for understanding concepts and maintaining knowledge through both Swift and Objective-C is refactoring one language into another. You could take a simple line of code, a small program, or – if you have the time, a full blown project, and convert the code from one language to another. In this way, you begin to appreciate the perks of each language, and understand certain concepts behind Swift at a faster pace.

Swift is a very strict language, the compiler will not allow any forms of nil to pass through variables, unless the coder tells it otherwise – through the use of optionals. Though this may seem like a drawback at first, I have begun to appreciate the strictness. It allows for fewer bugs and crashes. Through the use of optionals, the coder can tell Swift that certain variables can be nil temporarily, and must later remember to instantiate it. Optionals can also tell the compiler that certain variables may or may not have a value in them. It is an incredibly powerful feature, but takes time to understand its nuances. A novice mistake that many beginner Swift coders make is abusing optionals to get by compiler errors, and then forgetting to assign values to those optionals, causing a cascade of crashes. Optionals deserve their own blog post.

Though Swift is still relatively new and unstable, it is quickly becoming my favorite programming language. The removal of the semicolon is just a small bonus, but I’m sure many coders will appreciate the added touch. Between my Objective-C and Swift codes, the latter does seem to look more elegant and readable. I look forward to the Swift journey, and am sure that I will be loving every minute of it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s