Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

“Parhelions, more commonly known as sun dogs or mock suns, appear as fuzzy rainbows or bright spots in the sky ‘dogging’ the Sun. You are most likely to see a sun dog in the morning or afternoon during the winter. Records of this phenomena date all the way back to the ancient Egyptians. Famous Ancient Greek philosophers Cicero and Aristotle even made mention of sun dogs.”

(I’m pretty sure I made the photo from Google image search results, but I don’t remember where I got that text. I posted this on Facebook on November 23, 2013.)

Photos of Parhelions (sun dogs)

The funny thing about writing the Scala Cookbook is that it started as a whim. I was just about to leave for a vacation at the beach, and right before I turned off the computer a thought flashed in my mind, “I should contact the people at O’Reilly about writing a cookbook for Scala.” I then had a doubt that they would actually do it, but I applied the “What the heck” rule — i.e., “What the heck, what do I have to lose?” — and sent the email.

I dug around the internet for a few minutes, found the correct O’Reilly email address, sent them a message, turned off the computer, and drove to the beach. While I was at the beach the publisher wrote and said, “Love it, send me a full proposal!”

So if you’re thinking about doing something, but are afraid or uncertain about doing it ... apply the “What the heck” rule, and give it a shot. :)

“Ever notice that 'What the heck?" is always the right choice?”

Quote from Nancy Davis, design by Robin Williams, in the book, The Non-Designer's Design Book.

Ever notice that ‘What the heck?’ is always the right choice? (Nancy Davis)

As a little mini-project I wanted to count the number of lines of source code in the Second Edition of the Scala Cookbook as compared to the First Edition. To do this I wrote the following Scala program/script to count the lines between the ---- and .... sections in the AsciiDoc files that represent the old and new versions of the book:

I like this quote from Leo Buscaglia: Take responsibility and grasp it. Don’t be a victim.

I’ve written it before, but Mr. Buscaglia was a significant, positive influence on my life. There was a lot of negative and downright mean programming going on in our household when I grew up — negative role models on both sides of the family — and Mr. Buscaglia was an extremely helpful antidote to that, helping me to see that not everybody was like my relatives.

Leo Buscaglia: Take responsibility

This is THE speed limit sign on the Dalton Highway in Alaska. If I remember right, this is the only speed limit sign you’ll see when headed north from Fairbanks heading towards Prudhoe Bay.

I started off driving about 50 mph, but then after realizing I was the only person on the road — an almost-entirely entirely dirt road — I drove as fast as conditions allowed, typically a little over 90 mph.

The speed limit sign on the Dalton Highway, Alaska

This tweet shows that the traffic jam trying to get to the outdoor hockey game at the Air Force Academy last night was a disaster. And in this tweet, a young woman demonstrates a Babe Ruthian swing.

“The meaning of ‘Hatha Yoga’ is Sun (Ha) and Moon (Tha), Yoga in which Sun is the soul and Moon is consciousness. Consciousness can be compared to a lens. Its inner surface faces the soul itself, and its outer surface comes in contact with the world. Inevitably a degree of grime attaches itself to that outer surface and obscures our vision. In fact it prevents us from seeing clearly what is outside, and it equally prevents the light of our soul from shining out. If our house is gloomy because the windows are dirty, we don’t say there is problem with the Sun; we clean the windows. Yoga cleans the lens of consciousness in order to admit the Sun.”

~ probably from the book, Light on Life, by B.K.S. Iyengar

Back on the first day of June, 2007, I moved to Talkeetna, Alaska, and just a few days after I moved into my cabin, a huge fire that was larger than cities like Louisville, Kentucky or Denver, Colorado, started to the west of Talkeetna. I took this photo at the top of the hill that overlooks Talkeetna.

Huge fire in Alaska (June, 2007)

“Yoga is the cessation of the fluctuations of consciousness. The still mind is by definition, pure.”

“Is this the end? Are we there yet? No. There remains the ego, the self, the known self, the impersonator of the Soul. He is the last actor to leave the stage. He lingers even for the very final hand clap of applause. What forces him off the stage? Silence, and retention of the breath.”

~ From the book, Light on Life, by B.K.S. Iyengar

A Rocky Mountain sunset, near Boulder, Colorado, November 24, 2016.

A Rocky Mountain sunset, near Boulder, Colorado

Here’s another photo of the Moon rising over the Atlantic Ocean, Virginia Beach, Virginia.

Moonrise over the ocean, Virginia Beach (#2)

Mama always told me not to look into the eye’s of the Sun ... sunrise in Virginia Beach, April, 2017.

Sunrise in Virginia Beach, April, 2017

“Karma means action and action motivated by compassion is good. To complain that what happens to you is just the result of your karma is lazy. Instead, confidently recalling the advice that, ‘You are your own master,’ you can change what happens by taking action.”

~ the Dalai Lama, on this Facebook page

If the Houston Astros want to do the right thing, they should just tell opposing batters what pitch is coming. For every at-bat during the season. If they can win the World Series that way, more power to them.

I can’t remember the name of the motel where I saw this, but this is a photo of a painting of sled dogs that I came across in Healy, Alaska, just north of Denali. (I remember the motel because I used to work with a nice guy named Carson, and a guy that could have easily passed as his twin brother worked there.)

Sled dog painting in Healy, Alaska

If you want to create multiple Scala Futures and merge their results together to get a result in a for comprehension, the correct approach is to (a) first create the futures, (b) merge their results in a for comprehension, then (c) extract the result using onComplete or a similar technique.

I originally wrote a long introduction to this article about how to work with the Scala Option, but I decided to keep that introduction for a future second article in this series. For this article I’ll just say:

  • idiomatic Scala code involves never using null values
  • because you never use nulls, it’s important for you to become an expert at using Option, Some, and None
  • initially you may want to use match expressions to handle Option values
  • as you become more proficient with Scala and Options, you’ll find that match expressions tend to be verbose
  • becoming proficient with higher-order functions (HOFs) like map, filter, fold, and many others are the cure for that verbosity

“You are destined to be together forever.”

“You are destined to be together forever”