Gaining Closure

by | February 8, 2019

Gaining Closure

Jeff Summers

February 8, 2019

Relationships are hard. They take a lot of work. In the beginning it all seems like rainbows and unicorns. Birds are singing, clouds dance across the sky and love is in the air. But soon reality sets in and you realize that the one you are in a relationship with is more complex than you had first imagined. You thought you were both on the same page. It was as though you could finish each other’s “sandwiches” (hey, you know you are having a good day when you can somehow slide in a reference from the movie Frozen without using the phrase “let it go”).

You start to notice a few cracks in the relationship. Those goals you thought you had in common don’t completely line up like you expected. Those sandwiches you were finishing for each other were not what you made and left an odd after taste. Suddenly, when you pass things from one to the other you are getting back completely different signals.

In today’s disposable society your first inclination is to toss this relationship aside and look for someone else. You were raised with the notion that for every prince there is a princess and you just so happened to mistake Mr. Wrong for Mr. Right when your emotional defenses were down.

I would challenge that you should not give us so quickly. Perhaps he is Mr. Wright you just need to invite Mr. Clean over to take the rough edges off of him. But that never is the answer is it? Asking someone to change to become perfect for you should not be how things work. Instead it is a matter of mutual compromise.

While it is quick to point out the other’s flaws; the first step should be to look in the mirror and assess your own life to see if perhaps you should be the one to first change. We get so comfortable in our own routines that we sometimes forget that when you find that someone special, they are that way because they are trying to make you a better person. This was the epiphany I came to while sitting in front of the computer late one-night and. Made all the difference in the world.

Closures can bring happiness as well as they can despair and despite what Elton John says, sorry doesn’t always seem to be the hardest word. So after a little introspection and wiping a few tears from my eyes I vowed not to give up on us baby as so eloquently sung by David Soul who was the original Detective Kenneth Hutchenson on Starsky and Hutch.

Perhaps I just didn’t understand the importance of Closures. According to Apple, they are self contained blocks of functionality that can be passed around and used within your code. They can capture and store references to constants and variables. In fact, they are quite eloquent handling all the memory management for you.

The frustration around these Closures is also their greatest strength. They act like functions but have their own special nuances kind of like your crazy Uncle Phil who you love as a family member but no one wants to see what’s under that ugly sweater he wore to the family Christmas party.

In their most simplistic form, closures are not hard to understand. You can assign something to a constant or variable and call it as if it were a function. But how are they different you ask? Well let’s start with a real world example.

Frank gives Betty an instruction to stand on her left foot. Betty hears the instruction and lifts her right leg to stand on her left foot. That instruction from Frank to Betty is a function.
Betty writes her phone number on a piece of paper and hands that piece of paper to Frank. The piece of paper is a variable. Frank writes, “Put your hands in the air like you just don’t care!” on a piece of paper and hands it to Betty. Betty reads the instructions on the piece of paper and puts her hands in the air like she really doesn’t care. The instruction as passed on the piece of paper is a closure. Sounds simple enough doesn’t it?

Programmatically, let’s use an example of saying Happy Birthday.

Let birthday = {
Print(“Happy Birthday!”)
}
birthday()

The example looks a little like a function except instead of declaring it as a function using the key word func, instead we used a constant called birthday and set it to curly bracket (the beginning of a closure) followed by an action (in this case printing Happy Birthday!) followed by closing the closure with an end curly bracket. To execute it you just type the name of the constant followed by open and closed parenthesis. The result is the message printed back.

If things were only that simple we would all understand closure but like life it can be more complicated meaning that you can pass parameters to a closure and you can return values from a closure. You can call a closure from within a function and you can return a closure as a result from a function. And if a closure is the last thing a function calls there is a whole series of short cuts called “trailing closure syntax” that you can use to save keystrokes. You can even use shortcuts for parameters within closures and utilize variables within functions when the variables are not anywhere else but in the function calling the closure. It can seriously make your head spin.

But like anything of value, closures are worth learning. They have immense power and as Spiderman’s Uncle Ben taught us, with great power comes great responsibility. So I suggest you put in the time to learn about closures. Paul Hudson has some great tutorials on them in Day 6 and Day 7 of the 100 Days of Swift. Or there are several good tutorials about Closures within the Swift documentation from Apple.

Share this Article

Posted by Jeff Summers

Author, technologist, and baseball aficionado specializing in information technology and developing new and creative ways to interact with the world around us. My goal is to extend the boundaries of what is possible and find ways to make the world a better place while having fun.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Stay Connected

Search

More Articles

Pace Layered Architecture Categorization

Change is inevitable. Today’s computing environments are constantly in flux from internal and external forces that put demands on the systems and necessitate changes to maintain its value stream. Technology currency is a constant struggle that organizations must...

TBM, Another Holy Grail?

Technology Business Management or TBM as a term was coined around 2012 although many of the concepts making up this framework have been around for almost as long as there has been IT. In its simplest form, TBM represents the integration of business, technology, and...

Visionary or Dreamer?

Thinking back over your life you’ve met and worked with countless personality types. You have been a part of teams that struggled to complete simple tasks and the work felt meaningless. Perhaps your goal in these times was to just trudge through the mud hoping the...

Archives