alvin's blog

Using Scala as a 'better Java'

A lot of people want to sell Scala as a functional programming (FP) language. That's fine, it certainly is, and FP has many benefits. But when I first started working with Scala I was just looking for a "better Java".

Personally, I grew tired of Java's verbosity. Ruby showed us a different way, and I loved it, but ... after a while I felt like many of my unit tests in Ruby wouldn't be necessary if the language had static types. I wished for a concise Ruby-like language with static types.

My Facebook timeline, March 3, 2013

I like how the Anchorage Daily News puts a photo of the front cover of their newspaper on Twitter most days, so I thought I'd try something like that, posting a photo of my Facebook timeline from time to time. I don't know if I'll keep doing this, but I'll do it at least once. Here's what my timeline looks like on March 3, 2013:

My Facebook timeline, March 3, 2013

One way Mac OS X lost its sexy

I just fired up my old 2006 MacBook Pro that runs Mac OS X 10.5.8, and it helped me realize why I don't like the Spaces feature in the newest versions of the Mac operating system: It used to be fun.

Favorite quotes from the book 'Clean Code'

I just went through my notes on the book, Clean Code, and thought I'd share what I thought were some of the best quotes and "lessons learned" from reading that book.

Scala Cookbook update (February 27, 2013)

In case you were wondering about the status of the Scala Cookbook, we continue to roll along in the review process. We've found some reviewers who are helping to review the more difficult (or specialized) areas of the book, including chapters on the Play Framework, Actors & Concurrency, SBT, and others. While they're tackling those chapters, I'm working through all the previous review comments.

Scala: Immutable collections of mutable data

Normally I just write about solutions, but I thought I'd take a moment today to write about something else. In this case I just wanted to note that it's possible to create an immutable List of mutable data in Scala. This scenario made me wonder, "What does 'immutable' mean?" Let's take a look.

As a first example, we'll create a Person class that has two fields, and the first field (firstName) can change:

Linux find command: find and copy files

I ran into a situation this morning where I needed to use the Linux find command to (a) find all the MP3 files beneath my current directory and (b) copy them to another directory. In this case I didn't want to do a cp -r command or tar command to preserve the directory structure; instead, I wanted all of the files to end up in the same directory (so I could easily import them into iTunes).

How to create a mutable Set in Scala

Scala Set FAQ: How do I create a mutable Set in Scala?

To create a mutable set in Scala, first determine the type of set you want. You do this because the mutable Set is actually a trait, and you need to determine which concrete implementation you want.

For instance, if you want a SortedSet of String, define it like this:

val names = scala.collection.mutable.SortedSet[String]()

Then you can add elements to the set later like this:

Scala - How to find the unique items in a List, Array, Vector (sequence)

Scala FAQ: How do I find the unique items in a List, Array, Vector, or other Scala sequence?

Use the distinct method. Here's a simple example using a List of integers:

scala> val x = List(1,1,1,2,2,3,3)
x: List[Int] = List(1, 1, 1, 2, 2, 3, 3)

scala> x.distinct
res0: List[Int] = List(1, 2, 3)

As you can see, res0 now contains only the unique elements in the list.

Apple's Jonathan Ive talks about Blue Peter and the design process

Very cool, Jonathan Ive of Apple discusses a television show named Blue Peter, and the process of design, while looking at designs from young children:

 

Syndicate content