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

Last night I was reading the classic old book, The Pragmatic Programmer, and came across this definition of DRY, an acronym that stands for Don’t Repeat Yourself:

“Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.”

That’s well stated, especially after a recent experience in which I found some code where I created an “Add Widget” dialog in a different way than I created its related “Edit Widget” dialog. I created the main pane of the dialog the same way, but I managed the details of the two dialogs that contained that pane differently, and I realized what I had done when I decided to make the dialog resizable. When I discovered what I had done, I refactored the code so both the Add and Edit dialogs were created by a single method.

“Every action in our lives touches on some cord that will vibrate in eternity.”

~ Edwin Hubbel Chapin

As a short note, here’s some Scala source code that shows how to write a foldLeft function using recursion:

After yesterday’s Scala nested Option + flatMap/for example, here’s another example of plowing through nested Options with flatMap. First, start with some nested options:

val o1 = Option(1)
val oo1 = Option(o1)
val ooo1 = Option(oo1)

Here are those same three lines, with the data type for each instance shown in the comments:

Here’s a little fun with Scala functions, including the use of andThen and compose:

scala> val add1 = (i: Int) => i + 1
add1: Int => Int = <function1>

scala> val double = (i: Int) => i * 2
double: Int => Int = <function1>

scala> val addThenDouble = add1 andThen double
addThenDouble: Int => Int = <function1>

scala> addThenDouble(1)
res0: Int = 4

scala> val doubleThenAdd = add1 compose double
doubleThenAdd: Int => Int = <function1>

scala> doubleThenAdd(1)
res1: Int = 3

(Inspired by the book, Functional and Reactive Domain Modeling, and my own book, Learning Functional Programming in Scala.)

If you come here for the Scala, I’m sorry that I haven’t posted much here lately. I have my next medical procedure coming up on January 29th, and then my body decided to have a cold and then the flu.

“Developing the habit of mastering the multiple models which underlie reality is the best thing you can do.”

~ Charlie Munger

If you own a copy of Functional Programming, Simplified, and would like to report any bugs, I started this Github repo so you can do that. Just report your bug under the Issues tab.

Legend has it that Bodhidharma sat facing a wall for nine years. I’m going to sit facing my faux fireplace on my new cushion (known as a zabuton, which was a Christmas gift this year).

New meditation cushion (zabuton)

Today’s word of the day is reticent. Per Google, it means, “Not revealing one’s thoughts or feelings readily. ‘She was extremely reticent about her personal affairs.’”

“If you try to drive through Canada in the winter with those tires you’re going to end up as a statistic.”

~ A RCMP person, after looking at my car, March, 2011. They were very close to being right, as I got stranded for five days.

As a note to self, I used code like this in a Scala + JavaFX application to add a ContextMenu to a TableView:

LinkedIn’s engineering blog post has this article about how they use the Play Framework and Akka show online “presence indicators.”

I keep running into Maslow’s Hierarchy of Needs lately, so I thought I’d share that Wikipedia link, and this image, which was created wikimedia.org user FireflySixtySeven.

Maslow's Hierarchy of Needs

I updated my Scala Flat File Database project so it now handles newline (\n) characters. The solution isn’t perfect, but it’s a start, and makes the approach much more usable. (I didn’t need this functionality until today, so I didn’t know it was a problem.) I also updated it to work with Scala 2.12.

From The Verge, “General Motors plans to mass-produce self-driving cars that lack traditional controls like steering wheels and pedals by 2019.”

My phone says I have 18 songs by the Cranberries and Dolores O’Riordan. Some of the favorites are Zombie, Linger, Dreams, Electric Blue, and War Child. RIP, Ms. O’Riordan.

I just heard about the book Live to Forgive this morning. The introduction on Amazon says it all: “In Live to Forgive, former ESPN producer Jason Romano walks readers through his personal journey of forgiving his alcoholic father. Through sharing his own story, Romano invites readers to enter into their own messy journeys of forgiveness-to fully feel their pain, evaluate their pain, transform their pain, and ultimately forgive those who caused their pain. The only route to freedom and peace is forgiveness.”

Live to Forgive (book)

“In my whole life, I have known no wise people (over a broad subject matter area) who didn’t read all the time — none, zero. You’d be amazed at how much Warren reads — and at how much I read. My children laugh at me. They think I’m a book with a couple of legs sticking out.”

~ Charlie Munger, talking about Warren Buffett and himself