refactor

Take time to think(!)

As a note to my future self: Take time to think!

*sigh*

Even at my advanced age, if I don’t think through an algorithm I can still waste an awful lot of time.

As an example I just started working on a complex algorithm for my Android football game based on the initial thoughts in my brain, and came to regret it. After recovering from that faux-pas I decided to write just a few simple notes like this to clarify my thoughts:

Scala best practice: Eliminate null values from your code

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 20.5, “Scala best practice: Eliminate null values from your code.”

Problem

Tony Hoare, inventor of the null reference way back in 1965, refers to the creation of the null value as his “billion dollar mistake.” In keeping with modern best practices, you want to eliminate null values from your code.

Scala best practice: Create methods that have no side effects (pure functions) alvin June 21, 2015 - 4:33pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 20.1, “Scala best practice: Create methods that have no side effects (pure functions).”

Problem

In keeping with the best practices of Functional Programming (FP), you want to write “pure functions.”

Making your Scala code more concise (and your intent more clear) alvin June 17, 2012 - 11:40am

I was trying to write some code last night while I was very tired, and while the code itself isn't difficult in any way, the thought process I went through demonstrates how your code can become more concise as your understanding of Scala evolves, so I thought I'd share the experience here.

While working on my Sarah application, I was rewriting the Brain class, and I started off writing a method that looked like this:

A Java “Extract Interface” refactoring example

Java Refactoring FAQ: Can you provide an example of the Extract Interface refactoring process?

While working on a Java Swing development project recently, I had written a couple of controllers (as in controllers from the Model/View/Controller pattern), and I was about to write some more, when I realized that if I refactored my Java source code I would have a much better design -- source code I code more easily maintain.

The pattern I saw repeated in my Java controller classes was that they all had similar method names, something like this: