scala

Tutorials about the Scala programming language.

How to write Akka Actors: An example video game

Way back in 2013 — before my first fake heart attack followed by learning that I had thyroid cancer — I thought I was about to go “back to work”, and I decided to try to write another visual demo of Akka Actors before I went back to work. I gave myself 10 hours to write something, and at first I decided to just create some bubbles that would move about randomly on screen. But I got that working so fast that I decided to do something else.

Eventually I came up with the idea of a little “kill the bubbles” game, which turned into a “kill the characters” game. This video shows how it works:

Scala for/yield examples (for-loop and yield examples)

I just found some notes from when I first began working with Scala, and I was working with the yield keyword in for loops. If you haven't worked with something like yield before, it will be helpful to know how it works. Here's a statement of how the yield keyword works in for loops, based on the documentation in the book, Programming in Scala:

“Hello, Scala” - A swift introduction to a scalable programming language alvin February 18, 2018 - 10:15pm

I wrote the Scala Cookbook for programmers looking for solutions to common Scala problems, and then wrote Functional Programming, Simplified for programmers looking for a simple way to learn functional programming. A few months ago I decided to finish my Scala trilogy and write a book for programmers who don’t know Scala and want a quick introduction to it. With that, Hello, Scala was born:

Hello, Scala

In Defense of OOFP (Alex Nedelcu) alvin February 13, 2018 - 6:11pm

Alex Nedelcu has a good article titled, In Defense of OOFP, in which he writes about Scala, OOP, FP, and the Scala collections classes.

Scala idiom: Prefer immutable code (immutable data structures) alvin February 7, 2018 - 10:50pm

(I originally wrote this blog post in 2012, and it seems like it has held up well over time.)

One great thing I’ve learned from Scala and functional programming over the last few months is this: 

Make your variables immutable, unless there’s a good reason not to.

“Immutable” means that you can’t change (mutate) your variables; you mark them as final in Java, or use the val keyword in Scala. More important than you not changing your variables is that other programmers can’t change your variables, and you can’t change theirs.

A Scala shell script to insert text before a matching pattern

I don’t remember exactly why I wrote this Scala shell script, but if I remember right I was having a problem getting sed to work properly, so I wrote this little script to insert an Amazon Kindle “break” tag before each <h1> tag in an HTML file:

A Scala “Word of the day” shell script alvin February 5, 2018 - 3:39pm

I have a 19" monitor on the counter between my kitchen and living room, and it’s powered by a Raspberry Pi. I use the Linux Phosphor screen saver to show a scrolling “news and stock ticker” on the display, which I’ve programmed to show news from several different sources (Atom and Rss feeds, along with other news and data sources). An old version of the display looks like this:

My Raspberry Pi news ticker display

Today I added a new “Word of the day” feature to the display, and as with all of the other code, I wrote a Scala shell script to generate the output.

Functional Programming, Simplified at Amazon alvin February 5, 2018 - 2:52pm

Hmm, someone is trying to sell a copy of Functional Programming, Simplified for $84.67 plus $6.99 shipping on Amazon. Not sure what that’s all about ... I recommend buying a new one from Amazon.

JavaFX: How to handle keystroke combinations without a menu/menubar alvin February 4, 2018 - 3:44pm

I can confirm that this code works as a way to handle/capture keystroke combinations in JavaFX without having to use a menu/menubar: