Latest Posts | Archive

The Definitive Reference To Why Maybe Is Better Than Null

16 Apr 2013

This article is divided into two parts: Explanation and FAQ. The explanation shows the reasons why a bunch of people think Maybe is way more useful than null. The FAQ is a list of my responses to common arguments I’ve seen about the shortcomings of Maybe.

I’m going to try to not go overboard with details here - my aim is to make it accessible to as many programmers as possible, not to be as thorough as possible.



Tony Hoare, the inventor of null, has gone on record calling it his ‘billion-dollar mistake’. So what should replace it?

Maybe, at its core, is a construct that allows programmers to move null checks into the type system, so they can be enforced at com...

Read MoreComments

Seven Languages: Week 4 (Scala) - Day 2

10 Apr 2013

Day 2 of Scala focused on its functional programming prowess. Since this is the first time functional programming has been introduced in this book only the basics were talked about this chapter, and I’m already pretty familiar with those so this was an easy chapter for me.

The exercises were a lot shorter than the previous day’s, although me going overboard last time probably had something to do with that! Today the main exercise was a small task that makes sure you know how to use Traits, Maps, and read files.

My familiarity with the topics in this chapter and the shorter exercises both mean this will be a shorter post than last time.

(This article is part of a series of posts I am doing...

Read MoreComments

Representing Emptiness In Scala (with Null, null, Nothing, Nil, None, and Unit)

31 Mar 2013

There are a couple of explanations of these terms out there already, but my needs weren’t quite satisfied by them. Detail is great, but I wanted concise high level descriptions that explain what the primary purpose for each construct is and emphasize the ones you’re most likely to see in practice. This explanation is intended to complement ones with more detail, not replace them.


Scala’s null is the same as in Java. Any reference type can be null, like Strings, Objects, or your own classes. Also just like Java, value types like Ints can’t be null. Odds are you'll see this one.


Null is a trait whose only instance is null. It is a subtype of all reference types, but not of value types. It purpose ...

Read MoreComments

Seven Languages: Week 4 (Scala) - Day 1

28 Mar 2013

I have to admit Day 1 of Scala was a bit of a relief. Forcing myself to think through the perspective of Prolog was enlightening but still a bit of a struggle. It’s nice to come back to paradigms I’m familiar with again. Scala is a hybrid language, with great support for both object-oriented and functional programming, both of which I’m fairly comfortable with.

That’s not to say everything went smoothly however - danger lies in overfamiliarity. At first I was writing Java in Scala, then when I tried to fix it I realized I was now trying to write Haskell in Scala. Neither approach felt very good.

The beauty of Scala (in my eyes) is its flexibility and practicality. It pushes you towards immutability and is capable of very succinct functional code, but it also has that mutable imperative escape hatch, and a good set of tools for working with problems that suit code like that. It will...

Read MoreComments

Counting Powers of Two - A Neat Pattern

10 Mar 2013

A little while ago I was going for a walk and searching for something to occupy my mind for a while. Something that would take my mind away from other problems and give it a simple, solvable, repetitive activity to do for a while. I hit upon counting up by powers of two.

Why? I’m a programmer, and powers of two are important and prevalent numbers in this field. By this point 128, 256 and 512 seem like nice round numbers to me, and I wouldn’t mind feeling the same way about 65,536 and 131,072. Also, counting powers of two has the virtue of getting hard before getting boring.

As I counted I noticed a neat pattern starting at the higher numbers. I thought it was pretty cool and maybe e...

Read MoreComments

← Older posts
Content by Nick Knowlson: Google+