A language that doesn’t affect the way you think about programming is not worth knowing.
~ Alan Perlis (American computer scientist, and the first winner of the Turing Award)
What Is This Essay All About? 🐙
Glad you asked! For one thing, this won't be a boring treatise on some obscure aspects of the Go programming language—we don't do boring stuff here in our Programming Digressions digs—as I value your time and intelligence far too much. For another, I want to keep the fun in there as we go about tackling diverse subjects while providing substantial value to you 💰
This time around, we're going to explore exactly what it is that enables Go to pass what I'm going to call the Perlis test—"A language that doesn’t affect the way you think about programming is not worth knowing"—with flying colors 🏁
Yo, what exactly is that impish-looking octopus doing up there in the pic? Hold on, hold on, everything will become clear in short order (Hint: Programming languages do not exist in a vacuum; they are relevant only to the extent that they serve a great goal. On top of that, how can 296 million years of evolution be wrong? Or ever wonder how IoT is evolving like an octopus? Go straight to Item # 11 below—"Bringing Go To The IoT World"—if you just can't wait to find out what this is all about!) 🐙
And, of course, read on if you are intrigued. Oh, and should your dear heart so desire, feel free to think of this essay as a sequel to the one which had appeared some moons ago, the far more prosaically-named prequel The Go Programming Language 🙊
With that, here's a rundown of what's coming your way today, right now, in fact:
- Duck Typing 🐓
- Duck Typing Redux 🗿
- Paradise Regained 🎭
- Of Object-orientation And The Platypus 🐌
- Calming Down To The Soothing Rhythm Of… Unit Testing! ⛵
- If You Fall, I Will Catch You, I'll Be Waiting ⚾
- Whew, Sprawling Hierarchies No More 🚧
- Go, Your Own Way 🏄
- The Widening Gyre Of Concurrency 🚅
- Go's Got Concurrency 👻
- Bringing Go To The IoT World 🐙
- Persistence In Go 💰
- Go Can Be Sweet 🍯
- Go Can Be Baffling (To The Uninitiated) 😱
- Let Beautiful Designs Emerge 🌹
- What About Recursion? 🌀
- Things Explainer: You're Kidding Me, Right? 📣
- Things Explainer: Redux 📕
- Go Forth And Smell The Roses 🌹 🌹 🌹 🌹
- Deep, Yet Simple 🐳
—Reader: Good things don’t last forever, now do they?
—Akram: Um, would you care to elaborate?
—Reader: Well, for one thing, you hadn't written for a while—at least we didn't see anything posted around here—and for another, we all reckoned that even if you (Heaven forbid) ever decided to resume your writing, you would come back remediated and share something sensible.
—Reader [continues without missing a beat]: Yet here you are again, this time displaying a laptop (yeah, as in the pic down there) under siege by the tentacles of an impish octopus! And what about those two rodents scurrying across on the other side of that laptop, for crying out loud?
—Akram: Oh, allow me to explain: (1) That adorable octopus is nothing less than a splendid reminder of how the Internet of Things (IoT) is evolving like the millions of years of evolution whereby we got the octopus, and (2) Those two—I think you called them, um, rodents—are none other than close cousins of the Go gopher, yay!
—Reader: Okay, this time you really lost it. Bye.
—Akram: Wait!!! Come back, I promise you're gonna love this essay.
—Reader: Yeah right, and I'll be a monkey's uncle.
—Akram: Ahem, humor me for just a few…
(As you may recall the premise at the outset—"A language that doesn’t affect the way you think about programming is not worth knowing—I've taken the liberty of calling this "our mind-bending adventure", and with good reason to back it up, as you'll soon see!)
1. Duck Typing 🐓
So our adventure begins—as many adventures invariably do—early one morning in a sleepy suburb where we find ourselves in the home of a programmer (Yeah, try selling this adventure setting for a movie script!) Yep, as you'll conclude from the happenings in the picture above, our perky programmer is about to sit down at the breakfast table (his lugubrious laptop and the oracular orchid waiting for him) 🌸
But oh my! We already got some creatures scuttling about the programmer’s laptop: One octopus, and two gophers, all three with designs on the apple square center. What’s up with that, we all collectively wonder... 😲
Not to worry, though; all becomes clear as soon as we spy the bash logo plastered to the laptop lid, right below the apple. But of course we knew it: Basically, the programmer is a gopher, right? 🐀
Well, we are getting warmer (and it’s pretty early on a weekend morning anyway) as it dawns upon us—such brilliance, oh my!—that our programmer must have lately been been writing programs in the Go programming language. Which brings me to ask the crucial question: "We're all ready for duck typing, right?" 💻
2. Duck Typing Redux 🗿
How about a half-decent definition of whatever this "duck typing" thing is anyway? Glad you asked, as I've got a fabulous definition that can be found—along with a ton of other good stuff—in a fine book by William Kennedy, Brian Ketelsen, and Erik St. Martin. Using the springboard of good old interfaces, the three co-authors of Go in Action (Manning Publications) enlighten us like so:
Interfaces allow you to express the behavior of a type. If a value of a type implements an interface, it means the value has a specific set of behaviors. You don’t even need to declare that you’re implementing an interface; you just need to write the implementation. Other languages call this duck typing—if it quacks like a duck, then it can be a duck—and Go does it well. In Go, if your type implements the methods of an interface, a value of your type can be stored in a value of that interface type. No special declarations are required.
My hope here is that you are warming up to my choice of this essay's name (which is, ahem, Further Adventures In Go Land, in case you didn’t notice). But that's only half of the story: Truth be told, I had seriously considered naming this essay: “Go bash the C Shell”.
Can you even imagine the kind of reception that would have created in the audience, given the swirling mists of confusion already enveloping us. But reason prevailed, and here we are, with an essay that's got a far more prosaic title (namely, Further Adventures In Go Land).
(As for our jaunt into "Go Land"—and it's tight (linguistic) connection with yet another awesome product from the minds at JetBrains—we simply don't have room in this essay for catering to that…)
All fine and well, you say, but what’s up with that spoon-billed duck above?
Glad you asked: Our resident programmer—him of the sleepy suburban house—is coming down to his breakfast table and about to make everything as clear as mud, um, daylight, I meant to say! 🌞
Duck typing can be a beautiful thing, especially in programming; actually, only in programming (I have yet to see a duck doing any kind of decipherable typing. 🐒 Hmm… Come to think of it, I have heard of the phenomenon—one commonly afflicting us technology types—known as chicken scratch. But I digress) 🐓
3. Paradise Regained 🎭
It turns out that our programmer was pondering exactly that—duck typing and stuff like that—when he spied his favorite cereal on the table. Needless to say, the cereal had to be wolfed down first before we got anything out of the programmer (Hasn’t anyone told him just how overrated nutrition is? I mean, it’s right down there with sleep. But I digress again). Soon enough, though, our rejuvenated programmer has rubbed his eyes, and is awake enough to give us the scoop on duck typing 🐸
It goes something like this...
Yo, so in case you haven't noticed, Go does not offer inheritance or sub-typing. But guess what? We do have interfaces, yay! Any and all functions that implement the methods of an interface thereby automatically satisfy the interface contract (This is done implicitly, with nothing additional to be done on the programmer's part). Enter duck typing: "If it walks like a duck and quacks like a duck, then it's a duck." 🐥
Allow me to quote on this very subject from the canonical book on Go programming, again in the context of—you guessed it!—our beloved interfaces construct:
How cool is that? 😎Many object-oriented languages have some notion of interfaces, but what makes Go’s interfaces so distinctive is that they are satisfied implicitly. In other words, there’s no need to declare all the interfaces that a given concrete type satisfies; simply possessing the necessary methods is enough. This design lets you create new interfaces that are satisfied by existing concrete types without changing the existing types, which is particularly useful for types defined in packages that you don’t control.~ Alan A. A. Donovan, Brian W. Kernighan (The Go Programming Language — Addison-Wesley)
Noted Go programmer Lex Sheehan has aptly remarked in his fine book on bringing the functional programming paradigm to the practice of Go—yep, this is where the "Paradise Regained" subtitle above comes in—by leaning on the inimitable uniqueness that Go's design brings in its wake, which is, frankly, a cornucopia of (design and implementation) possibilities that were simply not possible before it arrived on the scene:
When I discovered Go, it was like paradise regained; A return to simplicity with added benefits of concurrency, networking, great development tools, first class functions as well as the best parts of OOP.
~ Lex Sheehan (Learning Functional Programming in Go — Packt Publishing)
4. Of Object-orientation And The Platypus 🐌
And what do we have on our hands now? Readers are like: Whoa, are we getting into the platypus metaphor with which early adopters of object-orientated programming got indoctrinated (more like pummeled)? Akram, Akram, we know you all right, so don’t you even think of pulling a fast one on us! 🎃
Okay, relax, here's all that's going on, as we find ourselves being enlightened by Tim Budd, a fine and upright professor of Computer Science at Oregon State University:
Imagine a big old class hierarchy—yep, one of those sprawling ones that seem to invariably inhabit the land of object-orientation—that includes people, mammals, and, most of all, Phillip the platypus who lives at the zoo 🐊 🐄 🐻 🐼 🐸 🐫 🐃 🐎 🐍 🐌
Well, Phillip the platypus presents a problem for our simple organizing structure. I clearly know that mammals give birth to live children, for example, and Phillip is certainly a Mammal, and yet Phillip (or rather his mate, Phyllis) continues to lay eggs 🐣
To accommodate this, we need a technique to encode exceptions to a general rule. We do this by decreeing that information contained in a subclass can override information inherited from a parent class 👪
Most often, implementations of this approach takes the form of a method in a subclass having the same name as a method in the parent class, combined with a rule for how the search for a method to match a specific message is… 👀
Hey, relax, I was just trying to make a point that human cognition, more precisely how much we can keep in our head at any given time without losing track—anyone up for a slight detour into the intrigues of the mental construct that psychologists glibly refer to as "working memory"?—and the ways in which certain programming constructs and paradigms can tax that ability (of "working memory", that is) 🙉
Enter the Go programming language in all its unadorned simplicity and sheer power… 💪
5. Calming Down To The Soothing Rhythm Of… Unit Testing! ⛵
In his best efforts to get the readers all calmed down (after that nerve-wracking brush with Phillip the platypus showing up in the inheritance hierarchy), the programmer has everyone sit around—you guessed it—his (not round, but rectangular) programming table. Then, asking everyone to take 10 deep breaths, he deftly pulls out his copy of the canonical Go book. Needless to say, the mere sight of the book's tasteful cover has a remarkably soothing effect on the jangled nerves of the ragtag group 😻
On top of that, no sooner does our programmer plunk down his copy of The Tao of Microservices—its cover adorned by an illustration of the benevolently meditating beatific Emperor Reigen of Japan, the 112th emperor of Japan—than there is hushed silence. Time for yoga, everybody! 💁
Wait, yoga can wait… First, though, we're going to chat a bit about—you guessed it—unit testing. After all, it all starts with testing—unit testing that is—so let’s go there… 🚕
As noted Go programmer Mat Ryer rightly notes in his online post on 5 simple tips and tricks for writing unit tests in #golang:
Test-driven development is a great way to keep the quality of your code high, while protecting yourself from regression and proving to yourself and others that your code does what it is supposed to.
One more pointer while we're on the topic of unit testing in Go: We can ideally put unit tests in the service of teasing apart design decisions themselves! For the very best on that, I do not know of a better resource than this one: Growing Object-Oriented Software, Guided by Tests (by Steve Freeman and Nat Pryce — Addison-Wesley Professional)
(It’s example code is heavily in Java, but the ideas are universal and timeless) ⏳
6. If You Fall, I Will Catch You, I'll Be Waiting ⚾
Ah, nothing like having a safety net to catch us when we fall, time after time—hey now, catching and hauling in some fish isn’t too bad either (I’ll confess that those tilapia taste the best, if that's what those fishermen are hauling in!) 🐡
Yo, but what about my tidy inheritance hierarchies with objects all neatly nestled in their cozy containers? Glad you asked, because that’s where we go next 📦 📦 📦 📦 📦 📦
7. Whew, Sprawling Hierarchies No More 🚧
Great things are not done by impulse, but by a series of small things brought together.
~ Vincent van Gogh (the one and only Dutch Post-Impressionist painter)
I mean, what's there to not love about the philosophy of achieving great things—including the creation of great designs in software—through "a series of small things brought together"? I will go out on a limb and say that this is the whole Go philosophy: Composition is king 👑
See those tidy little organic cups in the pic above, fungal spores or whatever they are? Dare I ask, Do you find yourself re-creating equally, um, intricate hierarchies in your software designs and feel at times like tearing your hear out? Well… I think that it's high time for us to revisit (and do something about the implications of) our assumptions about what flies—and what doesn't—in the multi-core world which we now inhabit.
Yep, it's no coincidence that functional programming has taken off in our industry 🚀
I've already written at length on this topic, so here I will merely point you in the direction of a couple of resources that will help you:
There was an Old Man with a beard,
Who said: “It is just as I feared!
Two owls and a hen,
Four larks and a wren
Have all built their nests in my beard.
~ Edward Lear (from his Book of Nonsense)
8. Go, Your Own Way 🏄
Actually, speaking of owls…
Groan, we need more coffee, you all say. And I'm like, does this place look like a Starbucks or something? We are all morning larks here; sorry, all you owls out there 🐣
A word to the wise, in somewhat sheepishly pointing out the criticality of where the "comma" is placed, or not—as in there "Go, Your Own Way" or as it's missing here in "Go Your Own Way"—we get totally different outcomes. Shall I elaborate, or will I be, heavens forbid, questioning your fine intelligence? 🎓
But first, what's going on here? We… We hear these refrains 🎼
I have climbed highest mountain
I have run through the fields
Only to be with you
Only to be with you
~ U2 (Lyrics from I Still Haven't Found What I'm Looking For)
I'd drive a thousand miles
Haul a trailer of tears
Just to see you smile
And as the dawn appears
At the edge of the night
There's still a light that gleams
Beyond my wildest dreams
~ Mark Knopfler and Emmylou Harris (Lyrics from Beyond My Wildest Dreams)
And as for this sleep-deprived owl driving a thousand miles—that's Mark Knopfler and Emmylou Harris who appear elsewhere in another essay—sheesh, let's not even go there!
Actually, now that I think about it, with the era of self-driving cars dawning upon us, we could have our owl simply sit behind the steering wheel (more like perched on it!) in a car and be chauffeured a thousand miles 🚕
That would do it: Hey, now how about that?
Where I was going with all that was simply this: I have a hunch that the Go programming language will come to play one role or another in helping make self-driving cars in reality.
But I digress🚶
9. The Widening Gyre Of Concurrency 🚅
Turning and turning in the widening gyreTell you what, let’s all collectively digress before resuming our adventure in earnest: And what could be better than regaling in a marvelous poem or two by W H Auden?
The falcon cannot hear the falconer;
Things fall apart; the centre cannot hold;
Mere anarchy is loosed upon the world.
~ William Butler Yeats (from his inimitable poem The Second Coming)
A sentence uttered makes a world appear
Where all things happen as it says they do;
We doubt the speaker, not the tongue we hear:
Words have no word for words that are not true 🎭
~ W. H. Auden
As noted Go programmer Katherine Cox-Buday has cogently argued in her fine book entitled Concurrency in Go: Tools and Techniques for Developers (O'Reilly Media), the key thing to keep in mind is that
…cloud computing also presented many new challenges. Provisioning these resources, communicating between machine instances, and aggregating and storing the results all became problems to solve. But among the most difficult was figuring out how to model code concurrently. The fact that pieces of your solution could be running on disparate machines exacerbated some of the issues commonly faced when modeling a problem concurrently. Successfully solving these issues soon led to a new type of brand for software, web scale.
(And hey, to all of you who didn't immediately write me off for using that seemingly fanciful subtitle, I thank you for placing your trust in me!)
10. Go's Got Concurrency 👻
Okay, so here is the programmer’s best effort to convey the essence of concurrency—in Go or, for that matter, in any other programming language you care to name (Provided, of course, that the given language has support for concurrency. I mean, concurrent FORTRAN? Gimme a break) 🙉
For the final word on how to approach concurrency during the practice of Go programming, I refer you again to
Concurrency in Go: Tools and Techniques for Developers (O'Reilly Media) by Katherine Cox-Buday
11. Bringing Go To The IoT World 🐙
You knew that the octopus—more like the octopi as in the pic above—with whose tentacles we had a close brush earlier was going to pop up (again) unannounced, anytime. And so it is that you're going to find an octopus sprawling about in the background of the homepage for this incredible open-source project whose latest version is based on a Go implementation:
I happen to be a committer) 🔨
Here's the scoop—meanwhile I just caught myself drifting to visions of Baskin-Robbins ice cream scoops there for a few moments!—lifted straight from the EdgeX home page, a place where you can find plenty of other cool details as well 🍦
At the heart of the project is an interoperability framework hosted within a full hardware- and OS-agnostic reference software platform to enable an ecosystem of plug-and-play components that unifies the marketplace and accelerates the deployment of IoT solutions.
I’m also excited about the branding for EdgeX Foundry, which, in the great tradition of the Linux penguin, the Docker whale and other open source projects, features a “spirit” animal, namely an octopus. Why? Simple. Aside from being wickedly cool to look at and one seriously well adapted creature, the octopus is a living, “breathing” example of edge computing.
Here’s what I mean: every octopus has not one brain, not two, not three or even four, but nine brains total, one in each tentacle and a central brain in the head. Suction cups act as sensors that feed “data” into the tentacles’ brains, which are coordinated (to the best of researchers’ knowledge) by the central brain in the octopus’ head. That’s a lot like a distributed analytics architecture stretching from the edge to the fog to the cloud—and exactly what IoT and EdgeX Foundry are all about!
12. Persistence In Go 💰
You’ve got to doggedly keep at it. Persistence—no, not that kind of persistence—is the name of the game when it comes to grokking the Go programming paradigm. I mean, just check out that bird gnawing away at a… bicycle seat, goodness gracious! Yo, bird, you don’t have to be that destructive either! How much nutrition does that bicycles offer, for crying out loud? (This coming from a diet-conscious, nutritionally-aware programmer) 🍔 🍕 🍟 🍰 🍭 🍩 🍪
My thinking in this area—as it applies to Go—is currently evolving. Yep, you guessed it: this section is under heavy construction until further notice 🚧
As a prelude (to the heavy construction underway), though, I won't stop you from checking out the following two engaging resources
13. Go Can Be Sweet 🍯
This is how sweet and free of fear
I feel now in myself. Beyond opinion and judgment, undistracted by guilt,
I am walking strong and steadily home,
not timid or uncertain,
with my eyes splendidly clear,
all one pearl of gratefulness, no fear.
~ Jelaluddin Rumi (in the translation by Coleman Barks entitled The Essential Rumi — Published by HarperOne)I knew it, I just knew it: One of you smart Alecs (or Alexas) out there can—at this very moment—barely restrain herself from pointing out our programmer’s, shall we say, propensity for doughnut consumption (I am on my knees here, begging you to please not check out my ramblings on Kafka at the preceding coordinates) 😰
But we’ve got you covered; just check out the M&M bounty above (And no, this has nothing to do with Eminem, okay? I've already had enough with people not warming up to the loveliness that is the poetry of the one and only W H Auden: Dare I add that, yes, you're right, this essay is semi—autobiographical, so there!) 🎭
And yes, Go can be sweet 🌹
14. Go Can Be Baffling (To The Uninitiated) 😱
What in the world—actually more like, what on the branch—is that? Is that a bird of paradise or something? I dunno. Do I look like an ornithologist? But with its head gingerly tilted to one side, it sure looks baffled 🐝
Anyhow, once you get the lay of the land of Go—for example the notion that the package is the unit of encapsulation or the philosophy to share by communicating instead of communicating by sharing—programming in Go can be dead simple 💀
No more bafflement, I say: I recommend that you check out this fine resource 💰
15. Let Beautiful Designs Emerge 🌹
Simple can be harder than complex; you have to work hard to get your thinking clean to make it simple.
~ Steve Jobs
16. What About Recursion? 🌀
Yes, what about it? 😉
A bit exhausted from all this intense talk, we decide to take a break from our adventure: We head for that inviting sofa in the corner. But, wait a second, the impish octopus—and the two gophers—are still in close pursuit of us. Sheesh, can’t seem to shake them loose, dude!
All is not lost, though: Check out that enterprising Matryoshka doll standing upright, and that, too, right next to the glorious bash logo (Man, this doll’s got style, and good taste, I’m telling you!) 🏄
Barely have we finished sizing up the situation than we spy some shrubbery ambling down the banister just above the sofa… 🌿
Oh my, this is no time for taking a breather. I know, I know—I hear you say— just tell that to the dreamy, porcelain-encrusted dude in the pic below! 😴 He's either in a ruminating reverie or else thinking deep thoughts on concurrent design solutions (in the Go programming language of course).
My thinking in this area—as it applies to Go—is currently evolving. Yep, you guessed it: this section is under heavy construction until further notice 🚧
17. Things Explainer: You're Kidding Me, Right? 📣
What we really need is someone to make sense of all this, and explain away in simple terms: You guessed it, Things Explainer to the rescue. Imagine...
So let’s turn to exactly that, which is coming up by way of the next pic...
This section, meanwhile, is under heavy construction until further notice 🚧
18. Things Explainer: Redux 📕
Explaining Metaphysics to the nation–But what, you ask, is that DVD—is that really Out of Africa?—doing there, jostling cheek to jowl with our trusty Things Explainer. Once again, glad you asked...
I wish he would explain his Explanation 😉
~ Lord Byron (from Don Juan: Dedication)
As it turns out, this section, too, is under heavy construction until further notice 🚧
19. Go Forth And Smell The Roses 🌹 🌹 🌹 🌹
Every rose has its thorn
Just like every night has its dawn
Just like every cowboy sings his sad, sad song
Every rose has its thorn
~ Poison (Lyrics from Every Rose Has Its Thorn)So here we are in the end, smelling like roses; see, didn't I tell you, this was going to be an adventure with a happy ending? But you haven’t yet talked about some of the more intricate aspects of Go, I hear you say. And right you are (as always, I tell myself, over and over again, that the customer—you, dear reader—is king), because around here, you get to call the shots, now and forever 🎯
That’s my stance anyway. So there.
Speaking of roses—and yes, every rose has its thorn—a thorn had been gnawing at my side: Anyone recall the conversation, apocryphal or not, at the outset when we had found ourselves eavesdropping on a lively dialog involving a recalcitrant reader and yours truly? Maybe it was just a pipe dream after all 💸
Yo, why would I make such an assertion like that? Here's why, it's readers like you who keep me going—an Energizer Bunny I am not, so I, too, need some motivation from time to time:
You can't start a fire sitting 'round crying over a broken heart
This gun's for hire
Even if we're just dancing in the dark
You can't start a fire worrying about your little world falling apart
This gun's for hire
~ Bruce Springsteen (Lyrics from Dancing In The Dark)
You're the best, thank you! 💎
20. Deep, Yet Simple 🐳
That's how I'm finding Go to be. To put that into, context, check out this quote—Oh, I love this quote 💝
You are lucky you have such a deep interest in nature, and even if you find it is much more complicated and difficult to understand than you thought, when you learn more about it, it is also in certain ways more simple and beautiful than what you can imagine.
~ Feynman, Richard P. Letter to student Charles E. Tucker, April 1967 (from The Quotable Feynman — Princeton University Press)
Look, I don’t stand a chance against that dude, not even if I pull out my best gangsta sentences... When it comes to competing with the mighty Go gopher, I’m already sober, reminding myself as I do of the sage advice that👺
If at first you don’t succeed, try, try again. Then quit. There’s no use being a damn fool about it.