Today marks the second of three Consolidation Days during the 100 Days of Swift challenge. As I wrote yesterday, I am seeing tremendous value in this learning concept of reviewing the foundational concepts of the Swift programming language again before moving on to more advanced topics. Yesterday was simplistic enough reviewing things such as variables and constants. Many potential programmers might be able to skip this if they have experience with other programming languages. It becomes more a review of semantics rather than new information.
Day 2 of the review was slightly more important. Today started with a review of functions which are extremely important to developing efficient code. These are again similar to other languages so students may be tempted to skip this or go through it at a more rapid pace. You could probably get away with that but make sure you are clear about how things are called and named within functions otherwise you will find yourself troubleshooting things that should have been second nature.
The second half of Day 2 was in my opinion was warranted and should be carefully reviewed to make sure you have a solid understanding of the concepts. This latter half of the review consisted of several terms including Optionals, Optional Chaining, Structures and Classes.
These are all incredibly important and often times misunderstood or misrepresented by programmers. Optionals should be thought of as a safety harness for programmers where Swift makes sure that your code or in particular the modification of variables or results of functions contain the type of data you and the application expected so that it doesn’t crash.
In a simplistic sense, an optional allows a program to return an expected result or if there is no valid result return a nil. If left to their own devices, programmers sometimes forget about things not in the “happy path” where most errors or data deficiencies present themselves. An optional is Swift’s way of saying “I will give you a result but you probably should make sure it is accurate before you go assuming everything is working perfectly and check the data to make sure”.
When I first began learning about Optionals, it was frustrating. It almost felt as though Swift wasn’t trusting me. There were additional steps necessary to use the data coming back from a function (which is referred to as unwrapping the optional). I just wanted to get the data and move forward. But after working further with the language and seeing my share of code that didn’t always return what I thought it would; I have gained a new appreciation of the power of these constructs.
Structures and Classes are likewise extremely important allowing programmers to properly define objects and follow a more structured object-oriented approach to developing applications. So many who claim to be developers who profess mastery of these concepts end up only partially following the rules of object orientation. A review of how these are implemented within Swift is very useful and a great reminder that no matter what our level of experience, there are always things that you can learn to make you and your code better.
0 Comments