Scala, Java, Unix, MacOS tutorials (page 108)

This is the Index entry for recursion in the third edition of Programming in Scala. :)

Recursion - see recursion (index entry)

Intelligence is something we are born with. Thinking is a skill that must be learned.”

~ Edward de Bono

Hey, waitress, pour me another cup of coffee,
Pop it down, jack me up, shoot me out, flyin’ down the highway,
Lookin’ for the mornin’ ...

~ Drivin’ My Life Away, Eddie Rabbitt

One thing about being named Alvin Alexander is that I’ve been called Al, Alvin, Alex, and Alexander by various people lately. I don’t mind any of them, but I laugh at Alex because I used that as a fake name when I traveled to Alaska in 2007 and 2010. (I was also known as Ken in Alaska.)

One thing about specifically being named Alvin is that when people are happy with me they call me Al, and when they’re unhappy they tend to yell, “Alvin!” I don’t know if that’s just a chipmunk thing or if everyone with a multi-syllable first name goes through it, but I’ve noticed that as well.

Famed programmer Joe Armstrong passed away this weekend. He created the Erlang programming language, based on the actor model, and without using Google, I’m pretty darned sure that Erlang had an impact on Akka, the very cool actor library for Scala. Here’s an article Mr. Armstrong wrote some years ago, titled, Why OO Sucks (OO as in OOP).

“We should think and feel over and over: ‘May the suffering that this being and many others are experiencing cease, along with its causes. I will do everything I can to free them from this pain.’”

That’s from this tweet by Tulku Thondup.

I have to be honest, I can’t feel this for my loud downstairs neighbor here at the Terracina apartments. The only nice thing I can currently pray for is for him to move. I’m trying to work on that, but when someone plays their music so loud that your floor vibrates and your kitchen range rattles, it’s hard to think about his suffering and pain. (Just being honest about how I feel today.)

April 20, 2015: In sad news, the Motherlode Lodge burned down in Hatcher Pass, Alaska. I used to drive past it 5-10 times each summer, and I always thought that if I had enough money I would have liked to re-open it, and I even discussed that possibility with several people. A little story and video is here on adn.com.

Motherlode Lodge burns down in Hatcher Pass, Alaska

I just started watching A Little Bit of Heaven, and of course the correct answer for Wish #3 is that you want to feel love.

I edited Chapter 6 of my new book whilst listening to Moon Baby by Godsmack. I’m not sure I can be held responsible for whatever ended up in that chapter. :)

A couple of things happened recently that make me feel like a piece of meat in the organ grinder of life. First, I was in talks with a publisher about publishing a book with them, and their contract began, “You grant to Us ... the exclusive right to ... sell and otherwise commercially exploit your Work.” I thought, “Well, I guess that’s what work is about, organizations exploiting your work for their commercial profit,” but their writing felt dirty and sleazy, like it was totally controlled by a scumbag lawyer or CEO.

Next, I live in the Terracina apartments in Broomfield, Colorado, and they were recently bought by a new company. With the old company everything here felt like a family, but when the new company bought the place they fired the previous staff, and with most of the new staff it feels like I’m just a number. When I walk in the office the reception feels like, “Number 232 ... you always complain that your kitchen range is vibrating because your downstair’s music is so loud, what do you want? We’re trying to make a lot of money here and you’re a troublemaker.” Twice the office manager has barely looked away from her computer monitor while talking to me.

Both situations remind me of the Bon Seger song, Feel Like a Number.

A cool thing about the Unix/Linux grep command is that you can show lines before and after a pattern match with the -B and -A options. As an example, I just used this combination of find and grep to search for all Scala files under the current directory that contain the string null. This command prints five lines before and after each null line in each file:

$ find . -type f -name "*.scala" -exec grep -B5 -A5 null {} \;

That’s good stuff, but it prints a really long list of lines, and I can’t tell the output of one file from another. To fix this, I put the following code in a file named helper.sh, and made it executable:

As seen in Santa Fe, New Mexico, in 2017.

My Indian name is 'Runs With Beer'

“I just want something beautiful, Mo.”

“We all want something beautiful, Willie.”

This land today, shall draw its last breath
And take into its ancient depths
This frail reminder of its giant, dreaming self
While I, with human-hindered eyes
Unequal to the sweeping curve of life
Stand on this single print of time.

This land, today, my tears shall taste
And take into its dark embrace
This love, who in my beating heart endures
Assured, by every sun that burns
The dust to which this flesh shall return
It is the ancient, dreaming dust of God.

When working from home, my preferred writing environment is to use a huge fixed-width font on a large monitor with a matte finish, and nothing else on the screen. I write my text using either Markdown or LaTeX, depending on what the output format is going to be. And Yoda and Meditating Guy make me feel a little less crazy when I’m talking to myself. ;)

My preferred writing environment

And in the category of “Strangest Things I Never Knew About Java,” I give you ... CAFEBABE.

CAFEBABE and Java class files

If you want to create a shell script so you can change between MacOS dark mode and light mode from the Terminal (Unix) command line, put this source code in a file and name it something like dark:

osascript -e \
'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'

Then make that file executable, and make sure it’s on your PATH. Now you can type dark to toggle back and forth between dark mode and the regular light mode:

$ dark

From looking at that AppleScript code you would think you’d need two shell scripts for this purpose, but for some reason that one command toggles back and forth between the two MacOS modes.

I generally have a pretty good feel for how Scala traits work, and how they can be used for different needs. As one example, a few years ago I learned that it’s best to define abstract fields in traits using def. But there are still a few things I wonder about.

Today I had a few free moments and I decided to look at what happens under the covers when you use def, val, and var fields in traits, and then mix-in or extend those traits with classes. So I created some examples, compiled them with scalac -Xprint:all, and then decompiled them with JAD to see what everything looks like under the covers.

I was initially going to write a summary here, but if you want to know how things work under the hood, I think it helps to work through the examples, so for today I’ll leave that as an exercise for the reader.