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

I am without form, without limit
Beyond space, beyond time
I am in everything, everything is in me
I am the bliss of the universe
Everywhere am I.

~ Ram Kir

A friend of mine was a devout yoga practitioner, and even studied under B.K.S. Iyengar. Right before she passed away, she began to cry tears of joy, and said, “All is one, all is one.”

Last week I started a This week in Scala page, and I’m going to see if I can do another one this week. Without further ado:

I’m currently writing my new book, Functional Programming, Simplified (Updated for Scala 3) directly in LaTeX, and this is my “LaTeX cheatsheet” that I keep open all the time so I can copy and paste the LaTeX stuff I need while I write.

Note that I don’t use any LaTeX formula stuff, so most of this is pretty basic LaTeX stuff, though there are a few custom commands/functions that probably won’t make sense to anyone unless I share some more details.

Here’s my current LaTeX cheatsheet:

I don’t know if I’ll keep this going or not, but I was looking for a way to monitor “What’s new in Scala,” so I thought I’d create a “This week in Scala” page. Here’s what’s new the week of January 15-21, 2023:

On the personal front:

As a “note to self,” I like some of Shinzen Young’s sayings/analogies/metaphors in the first core lessons of the Brightmind app. The ones that come to mind are:

  • Try to listen to your mental talk in your head just like it’s a sound in nature, like listening to a bird. In this way, “you” can observe the thoughts in your head as the fly by, without getting attached to them.
  • In regards to your awareness, you can think of it in two different ways: (a) aiming your attention at a spot/area, or (b) hugging a friend.

For more details, check out the Brightmind app.

In December, 2022, in Winchester, Kentucky, the Clark County Public Library Board of Trustees took up the matter to potentially ban a book in the library they oversee. The book is an award-winning LGBTQ+ memoir that was already located in the Adult section of the library, but that wasn’t enough for the “conservative” trustees. While the library has many other sexually-explicit books (think Fifty Shades of Grey), the trustees singled out this one book, eventually voting that this award-winning book “is restricted to individuals over 18 unless a parent or guardian gives written consent.

I was going to share my opinion on censorship when I saw the quote in the image I shared (from this article): “Censorship is like a forest fire. It begins with a single ember, and if it is not extinguished at the outset, it becomes a raging conflagration that consumes everything in its path.”

Book banning in Winchester, Kentucky

These are my abbreviated notes (Cliffsnotes) from watching the talk, What Functional Programming Can Learn From Object-Oriented Programming, by John De Goes. As a warning, the notes are incomplete, and just a reminder to me of some of the best and most important parts of the talk.

Relatively early on he notes that there are multiple ways to do Scala, but only one way to write Go code. This is both a pro and a con.

How about a simple functional programming book written with this style:

No monads.
No monoids.
No functors.
No category theory.
Just some Java & Scala code.

Robert Martin’s tweet about writing a new simple functional programming book (in Clojure) was shared with me here, and I like his initial wording on not worrying about monads, monoids, functors, and category theory. (I believe it was Eric Torreborre who shared a similar sentiment some time prior to this, that functional programming should be taught separate from category theory.)

I said almost the exact same thing five years ago in the beginning of my book, Functional Programming, Simplified, and then in Learn Functional Programming Without Fear I show how to start with Java/OOP code and slowly transition to a functional programming style with Scala/FP examples. Both books focus on simple, pragmatic functional programming source code examples, without getting lost in FP theory.

No monads. No monoids. No category theory. Just FP code.

Last night — December 18, 2022 — I started the process of updating my best-selling book, Functional Programming, Simplified. With this update the book is being updated to cover Scala 3, ZIO, and Cats Effect — none of which existed when I wrote the first edition of the book!

I’ll write more about this over time, but for now, click this link to learn more about Functional Programming, Simplified (Updated for Scala 3).

Functional Programming, Simplified: Updated for Scala 3!

As you might guess from looking at this collection of book covers, I LOVE writing about things like Scala and functional programming, but it pays about 1/10th of what programming does. To try to make it affordable to stay in the writing business, I’ve created this Patreon page. Any support is greatly appreciated 🙏 and will help keep me in the writing business.

Patreon page to support Alvin Alexander’s writing

I like what John De Goes shares in this talk about how to combine the best of FP & OOP. The “best of” portion of the talk starts about 36 minutes into the talk, which is where that link starts.

FWIW, I share almost all of the same information in my book, Functional Programming, Simplified, though I will admit that I probably don’t articulate it quite as well as his speech. (That being said, I wrote the book over five years ago, and it also includes some decent examples of domain modeling and code organization with Scala, FP, and OOP.)

Combining the best of FP and OOP with Scala

As this image shows, my new book — Learn Functional Programming Without Fear — goes from object-oriented programming (OOP) to functional programming (FP) and the IO and ZIO data types in about 167 pages. Furthermore, the book also includes a simple 13-page “Introduction to ZIO” at the end, with six small ZIO examples. If you’re an OOP developer who’s interested in FP, learning FP (and ZIO) has never been faster or easier!

New book: From OOP to IO and ZIO in 167 pages

If you’re interested in functional error handling in Scala (Option, Try, Either, etc.), there’s a nice discussion at this Github pull request.

There are a few quotes that are well worth sharing for anyone interested in functional error handling in Scala. First, all of Martin Odersky’s introduction is terrific background material on the topic, so I’d start with that.

Later, Adam Warski shares this statement, which I think is a terrific summary about functional error handling with ZIO:

Many weeks after its release, my new book — Learn Functional Programming Without Fear — is still a #1 best-selling functional computer programming book on Amazon.com, as of December, 2022. I hope it will be a great Christmas/Holiday 2022 book gift for the computer geek in your life!

Number 1 best-selling computer programming book

Because of my formatting needs, and my desire to release new chapters every week — just like a series of blog posts — this is the first book I’m writing directly in LaTeX rather than Markdown or Asciidoc.

(And if you’re interested, click here to find out more about the book.)

Writing a book in LaTeX

Here are two great quotes on programming, data modeling (domain modeling), algorithms, and design that I was just reminded of, thanks to this Twitter question:

Linus Torvalds: “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.”

Fred Brooks: “Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowchart; it'll be obvious.”

If you’re a computer programmer who’s using object-oriented programming (OOP), and:

  • you want to learn functional programming (FP), and
  • you want to learn FP as fast as possible (without functors, monads, and all the other category theory), then
  • the 7-step process shown in this image is the fastest path I know.

If you should also want a guidebook on your journey, my new best-selling book, Learn Functional Programming Without Fear, can help guide the way. At the time of this writing, the eBook is currently just $10 and the paperback is only $20.

(You’re also welcome to respond to my LinkedIn post, which is where this image comes from.)

OOP: How to learn FP the fastest way

As an update before getting into the original article (below), I’ve come to think of the Scala filter method being spelled as the British filtre, and then I think of this acronym, which helps me remember how filter/filtre works: “Find In List Then Retain Each.” So basically filter means retain.

I know that’s a little hokey, but it works for me. And now, here’s the original article:

As part of my personal ongoing battle with the meaning of the filter method in functional programming languages like Scala, I decided to create add a keep method to the Scala List class using the Scala 3 extension method approach, like this:

As a brief note, to help make Scala and functional programming completely free to anyone who wants to learn, I recently created a Kickstarter project for just that: to create free Scala and functional programming training courses. See that Kickstarter page to learn more about this effort.

Kickstarter: Free Scala and functional programming training courses