Doing What You Love
Recently I had an interesting conversation with a couple guys at my client site. One of mentioned he heard about my presentation at a recent user group and also saw my invite I sent out for an internal Domain Driven Design study group and asked “How come you like work so much?” The other guy then said “I think it’s something that is just different about Americans versus people from other countries… they’re workaholics man! I mean, I heard that Ryan always works weekends.”
I simply corrected them… yes, Ryan is a workaholic and in my opinion he is overexerting himself. But I don’t consider my programming, reading, and speaking that I do on the side as work; I just love software development and it’s something that has interested me, both from a technical and social standpoint. It just so happens that my job has me doing something that I love (although dealing with a mess of legacy code isn’t always enjoyable). There’s a huge difference between working all the time and doing what you like to do in your free time; and you won’t catch me “working” at work more than forty hours a week.
I think it’s important that people do what they love to do because at that point their job isn’t just something they do through the week while waiting for the weekend to arrive. One of the best stakeholders I ever worked with on a project was a guy from marketing and guess what he does in his free time? We were out at dinner once when he and the rest of the product owner team was in town he confessed what he does when he gets home from the gym after work: he plops down in front of the TV and watches recordings of commercials that were recorded throughout the day. He doesn’t watch any shows or movies… just the commercials. Another friend of ours is a math professor and she enjoys solving math problems in her spare time. I know I would go nuts if I spent my leisure time solving math problems! But it is what she likes to do and her job just happens to be related to what she likes to do.
Now, I don’t think that in order to be a productive developer (or even just a really good developer) you have to code in your free time all the time and this guy really misses the point. I definitely don’t think that companies should make it a requirement that they hire only people who code in their free time because otherwise they might miss some really good developers who just do what they like to do in their free time. But I think that someone who really enjoys software development and spends their free time improving their skills at their craft and doing it just for fun often happen to be much more remarkable.
Enjoying software development in your free time doesn’t always mean you’re going to really love your job. As Chad Folwer once pointed out, What Would You Rather Be Doing? However I think that when you do something you love you will find it fulfilling and sooner or later you really will either land the job you love or you will motivate radical changes at your current workplace to make enjoyable not just for yourself, but for the people you work with as well.
Are you doing what you enjoy doing?
Friday Scala Kata: Weekday Heptagram
Last week’s scala kata was a bit challenging as it required a bit more advanced scala knowledge than the katas I’ve done so far. Breaking from last week I’ve decided to head back to the basics and dream up a kata to help focus on some of scala’s language features versus a full blown program.

For this week’s scala kata I decide it would be interesting to model the Weekday Heptagram. Conceptually the kata should be to take one of the seven Stellar Objects ( Saturn, Jupiter, Mars, Sun, Venus, Mercury, and Moon) and the hour of the day using the 24 hour scale and deduce what day of the week it is. For example, if it’s the 1st hour of the day and the stellar object is Saturn then it is obviously Saturday. If it is the second hour of the day and the stellar object is Saturn then it is Monday. See the table near the top of this page for additional examples to use for your specifications.
Other operations that could be useful include:
- identify the dominant stellar object for a given date/time
- given a day and hour what is the stellar object n hours from now
- given a specific day and hour, what are the stellar objects for that hour for the remainder of the week?
Hopefully this should be a fun little coding exercise.
Scrumbutts Abound
Lately I came across this posting on an agile related mailing list. I know that job postings on these lists are often a low hanging fruit for criticism, but I really just could not help myself.
THIS IS NOT A PM, but a SCRUM MASTER POSITION. The right candidate needs to have background as a technical lead in J2EE AND a recent background in management and/or Project Management
The Scrum Master will be responsible for managing the Scrum activities of 4-6 Java Developers. He/She will need to deliver quality software releases on time and within budget. This person will work closely with development staff to develop delivery plans, monitor and control development milestones, complete software designs and documentation, serve as the point of escalation to resolve technical issues, and will mentor and coach junior developers. They will be accountable for enforcing development standards and best practices, and ensuring the team is delivering on its commitments.
Required Skills:
* Proficiency with Microsoft Project
* Posses a good understanding of Project Management practices, plus good planning and organizing skills
* Be the right mix of management and technical skills, background and expertise
* Have 3+ years experience as a senior software engineer, technical lead, technical project manager, or software development manager
* Have proficiency with the JAVA language and in Web technologies
* Have experience with Test Driven Development practices and their implementation
* Possess strong written and verbal communication skills
Whatever.
You might take this post as saying I dislike Scrum and it’s not. My annoyance is all these high profile companies jumping on the bandwagon and renaming their project manager position as Scrum Master, hiring them by the buttload and teaching them the wonders of gnatt charts, microsoft project, and “managing the development staff” (aka watching over the serfs) and then dumping them onto the open market with freshly minted resumes listing Scrum Master as a position previously held.
Now when a company really does get serious and wants to adopt Scrum, they’ll search for a Scrum Master to help their teams out and hire one of these guys, further spreading the poison. Then said company will have disastrous results and either “learn that agile just does not work” and switch back to whatever process they had before or keep the course with a pseudo agile setup that will cause people to only complain about how much they hate agile.
What’s the solution to this mess? In my opinion “Fake Agile” is the biggest threat to our industry as only widens a certain problem and puts a nice doormat over it. ![]()
Using Innovation Games as Retrospective Activities
About a month ago I purchased Innovation Games off of amazon… partly because I have a strong interest in facilitating interactive activities to learn and solve problems (which is what we do with retrospectives) and partly because I heard some subtle buzz about it. When I saw that another person on the retrospective mailing lists tried a variation of one of the games as a retrospective activity, I decided to try the same on my team as well.
In a couple previous retrospectives one of the things that people noted they’d like to do differently is have a retrospective that focused on technical issues as most of the subjects we discussed were collaboration, team dynamics, etc (which is a good thing!), so this retrospective had a very technical focus.
Here’s the agenda I cooked together:
- Set the Stage / Agree to Kerth’s Prime Directive
- Speedboat
- Remember the Future
- Wrap Up with Three H’s
I started by welcoming everyone to the retrospective, gave an overview of the agenda and stated Kerth’s Prime Directive asking each person to agree to it.
I then moved onto the speedboat activity, drawing a speedboat on poster paper with waves, stating “we always want to move faster and let’s say that moving quickly is represented by a speedboat. Given our current system and tools, what are some of the anchors? That is, what are the things that slow us down?” I then drew some anchors from the boat, then some rocks along the bottom and continued “and further, what are some of the things in our codebase that don’t slow us down, but they’re a risk?” The team then spent the next 15 minutes jotting down issues related to design, code quality, etc. and posting them as anchors and risks and then we spent a quick 10 minutes discussing them in slight detail.
Moving on, I put a new poster paper up and told the team “Imagine that it’s June 2011. You just came into work, updated your working copy from revision control and get to work. What has changed that makes your life easier? What has changed to cut these anchors?” People placed several post-its up with changes that we often call “pie in the sky refactorings” that represented wide sweeping changes.
Once the posting died down I moved the post-its to the top of the page and drew a line across it and wrote June 2011 above it and December 2010 below it. “Now let’s think back six more months. What were some of the changes that took place that helped support these aspects of the system in June 2011?” Again another flurry of ideas that were closer to reality popped up. Now I drew another line and under it I wrote “June 2010″ and, with a few laughs from the group, stated “Now think even further back… what happened in June 2010 that allowed these changes as of December 2010 to come to fruition?”
More ideas, some even doable popped up. We had some small discussion and then finally, on a new poster paper I wrote “Right Now” at the top and asked “So, coming out of this retrospective, what can we do that will help us support these changes next month?” The ideas were small and simple to implement, along the lines of “replace Integers representing years with a Year object” and “remove dependency on BarFactory from FooRepository “.
We then wrapped up Three H’s… a quick survey of what Helped the retrospective, what Hindered it, and what people Hypothesized could improve it in the future. Overall we were quite pleased with the outcome and I’m interested in mixing in ideas from Innovation Games in future retrospectives.
St.Louis Java SIG Google Collections Presentation
Tonight I gave a presentation at the St.Louis Java SIG on Google Collections. Here is the presentation that I made with Prezi, but like always the presentation is much more effective in person as it mostly served as a visual aid to talking and live examples.
.prezi-player { width: 500px; } .prezi-player-links { text-align: center; }
If I really had to sum up my points from the talk, I’d say it was this:
- Immutability for the win!
- Explore the API
- MapMaker is SWEET
Friday Scala Kata: Solitaire Cipher

This week’s scala kata is a favorite I’ve implemented before in javascript, Solitaire Cipher which was featured some time back as the first problem on the Ruby Quiz site.
I think there should be enough source material on those two links to get started. The true acid test is being able to shuffle a deck of cards, encrypt a message, and then decrypt it using the deck. Bonus points if you can send people encrypted messages that they can decrypt on their machine using your program. ![]()
Pascal’s Triangle Solution
Last night I completed this weeks Scala Kata to generate Pascal’s Triangle using a List of Lists. Although it works, I’d like to see if there is a better “scala way” to get it done. I’ve also discovered that List in scala is immutable so all those times I’m adding elements to the List I’m not really adding to it… I’m creating a new list and re-assigning it to the variable. I also see it’s going to take awhile to break free of the conditioning that java has put me through.
Don’t look if you still want to do the kata, otherwise take a gander and let me know how I can improve the internal design.
import org.specs._
object PascalsTriangleSpec extends Specification{
"Pascals Triangle Generator" should{
val generator = new PascalTriangleGenerator
"return a List with List(1) for 1" in {
val result = generator.generate(1)
result must be equalTo(List(List(1)))
}
"return List(1), List(1,1) for 2" in {
val result = generator.generate(2)
result must be equalTo(List(List(1), List(1,1)))
}
"return List(1), List(1,1), and List(1,2,1) for 3" in {
generator.generate(3) must be equalTo(List(
List(1),
List(1,1),
List(1,2,1)))
}
"generate to the 4th layer" in {
generator.generate(4) must be equalTo(List(
List(1),
List(1,1),
List(1,2,1),
List(1,3,3,1)))
}
"generate to the 5th layer" in {
generator.generate(5) must be equalTo(List(
List(1),
List(1,1),
List(1,2,1),
List(1,3,3,1),
List(1,4,6,4,1)))
}
"generate to the 6th layer" in {
generator.generate(6) must be equalTo(List(
List(1),
List(1,1),
List(1,2,1),
List(1,3,3,1),
List(1,4,6,4,1),
List(1,5,10,10,5,1)))
}
}
}
class PascalTriangleGenerator{
def generate(n:Int) = {
var triangle = List(List(1))
(2 to n).foreach( i=> triangle += createNextLayer(triangle.last))
triangle
}
private def createNextLayer(previous:List[Int]) = {
var list = List(1)
for(j <- 1 until previous.length){
list += previous(j)+previous(j-1)
}
list+1
}
}
Revisiting Factorials in Scala
In my earlier post I showcased doing a simple factorial code kata using scala and today as I was driving home from work I was thinking… isn’t there some way to dynamically add methods to an object so that I can just write 10! and have it compute the factorial?
The answer is yes, kind of. You don’t really define a new method that gets tacked onto an existing type, but rather define an implicit method that gets called to “implicitly” convert one type to another.
With this in mind, I cracked open the scala commandline and tried the following out:
class RicherInt(n:Int){ def ! = (1 to n).foldLeft(n)(_*_) }
implicit def intToRicherInt(n:Int) = new RicherInt(n)
6!
The result was res3: Int = 720. Woot! Now I tried it out by rewriting my specification to look like this:
import org.specs._
class FactorialSpec extends Specification{
"factorial" should {
...
"return 6*5*4*3*2*1 for n = 6" in {
(6!) must be equalTo(6*5*4*3*2*1)
}
}
}
To make this work I needed to import the implicit def rather than just have it lying around naked like you can on the commandline. So I created a AwesomeInt class and an object to hold the implicit method:
class AwesomeInt(n:Int){
def ! = (1 to n).foldLeft(1)(_*_)
}
object Converter{
implicit def intToAwesomeInt(n:Int) = new AwesomeInt(n)
}
and updated the specification to import the Converter object.
import org.specs.Specification
import Converter._
class FactorialSpec extends Specification{
"factorial" should {
...
"return 6*5*4*3*2*1 for n = 6" in {
(6!) must be equalTo(6*5*4*3*2*1)
}
}
And presto! All the examples in my specification passed. Perhaps my only nitpick is I wish I could figure out how to make the example read like the below for much cleaner, plain english looking specifications.
6! must be equalTo(6*5*4*3*2*1)
Friday Scala Kata: Pascal’s Triangle
This week’s Scala Kata was suggested to me by Tim Dalton. For a given number, build Pascal’s Triangle as a List of Lists starting from the top down.

Here’s some examples to illustrate:
Given n = 1, then the result should be List(List(1))
Given n = 2, then the result should be List(List(1), List(1,1))
Given n = 4, then the result should be List(List(1),List(1,1), List(1,2,1), List(1,3,3,1))
And so on. Can you generate a triangle to the 14th row as in the above graphic? How about the 30th row?
Scala Kata Triangle Words Solution
SInce it’s Friday I’ll post my solution to the previous Scala Kata, Identifying Triangle Words.
I started by specifying small functions that could be combined to determine whether or not a word is a triangle word:
import org.specs._
object TriangleWordIdentifierSpec extends Specification{
"letter to number converter" should {
"convert A to 1" in {
convertLetterToNumber('A') must be(1)
}
"convert a to 1" in {
convertLetterToNumber('a') must be(1)
}
"convert C to 3" in {
convertLetterToNumber('C') must be(3)
}
"convert c to 3" in {
convertLetterToNumber('c') must be(3)
}
}
"generate word value" should {
"return sum of each character for 'abc'" in {
wordValue("abc") must be(1 + 2 + 3)
}
"return sum of each character for 'sky'" in {
wordValue("Sky") must be(19 + 11 + 25)
}
"'ddd' should equal 4 + 4 + 4" in {
wordValue("ddd") must be (4 + 4 + 4)
}
}
"identify if word is a triangle word" should {
"sky is a triangle word" in {
isTriangleWord("Sky") must be (true)
}
"ski is not a triangle word" in {
isTriangleWord("Ski") must be (false)
}
}
}
Here’s the implementation. It’s rough, and I have learned a bit more about scala’s for loops since then but decided against refactoring the solution yet.
object convertLetterToNumber extends (Char => Int){
override def apply(s:Char) = s.toUpperCase.toInt - ('A'.toInt-1)
}
object wordValue extends (String => Int){
override def apply(s:String) = {
List.fromString(s).foldRight(0)((a,b) => convertLetterToNumber(a)+b)
}
}
object isTriangleWord extends (String => Boolean){
override def apply(word:String) = {
val wordVal = wordValue(word)
var result = false
for{i <- 1 to wordVal
t = triangleNumberFor(i)
if(t <= wordVal)
}result = t == wordVal
result
}
private def triangleNumberFor(n:Int):Int = (n*(n+1))/2
}
This identifies Triangle Words just fine, but the real test is to read words from a file and count the number of triangle words and verify it is correct on the project euler website. This requires reading in from a scala.io.Source… in the spec I used fromString but the actual I just used fromFile.
import org.specs._
class WordReaderSpec extends Specification{
"only 'bar' and 'sky' are triangle words" should {
val str = """"Fpp","Bar","sKy","Earth"
|""".stripMargin
var triangleWords = List[String]()
doBefore{
triangleWords = WordReader.readWords(scala.io.Source.fromString(str))
}
"identify two elements as triangle words" in {
triangleWords.size must be(2)
}
"return list with 'Bar' and 'sKy' in it" in {
triangleWords must containAll(List("Bar", "sKy"))
}
}
}
The implementation to this isn’t very effecient; the provided file from the site was a one line comma delimited file so I just read the whole thing in, stripped the quotes, split on the commas and passed each word to the IsTriangleNumber function. I’m sure this would bomb on a large file.
import scala.io._
object WordReader{
def readWords(source:Source):List[String] = {
var words = List[String]()
source.getLines.map(_.replaceAll("\"","").split(",")).next()
.foreach( arg => if(isTriangleWord(arg))words += arg )
words
}
}
That’s it. I liked this kata because this was the first REAL one I did with it and cut my teeth on some of scala’s concepts and used file IO with it for the first time. If you got some criticism or feedback please let me know… I’m looking to improve my skill anyway I can!
Lunch Scala Kata: Perfect Numbers
Today I met up with Tim Dalton to do some pair programming on a scala kata… partial because I wanted to exercise both my scala and pair programming skills, partially because I wanted to steal some of Tim’s expertise to help me learn scala better. Since lunches are usually crammed and I expected us to be pressed for time, I selected a simple code kata: finding perfect numbers.
So to start, I wrote the first example, 5 is not a perfect number:
object PerfectNumbersSpec extends Specification{
"Perfect Numbers" should{
"5 is not a perfect number" in {
IsPerfectNumber(5) must be(false)
}
}
}
Following the rule of doing the simplest thing to make it pass, we just returned false:
object IsPerfectNumber extends (Int => Boolean) {
def apply(n:Int) = false
}
Next we wrote an example of 6 being identified as a perfect number, in which I just returned n % 2 ==0. Since this felt like cheating, the next step was an example of numbers that are not perfect numbers in the range of 1 to 10:
"if its not a perfect number should return false" in {
(1 to 10).filter(_ != 6).foreach(n =>
IsPerfectNumber(n) must be(false)
)
}
My cheat of returning n mod 2 no longer worked, so I did the first thing that came to mind:
object IsPerfectNumber extends (Int => Boolean) {
def apply(n:Int) = {
if(n % 2 == 0) (1 to n / 2).foldLeft(0)(_+_) == n else false
}
}
All examples passed, so I took my turn to writing the next example:
"28 is a perfect number" in {
IsPerfectNumber(28) must be(true)
}
to which Tim showed off his scala skills by converting my previous code to the following:
object IsPerfectNumber extends (Int => Boolean) {
def apply(n:Int) = {
(1 to n / 2).filter (n % _ == 0).foldLeft(0)(_+_) == n
}
}
For the scala impaired, that creates a range of numbers of one to n divided by two, filters it out to find only the divisors, then calls foldLeft which adds all of the divisors together. The example passed, so we added a couple more checks to be sure and it all went well. Here’s the specification in it’s entirety:
import org.specs._
object PerfectNumbersSpec extends Specification{
"Perfect Numbers" should{
"5 is not a perfect number" in {
IsPerfectNumber(5) must be(false)
}
"6 is a perfect number" in {
IsPerfectNumber(6) must be(true)
}
"28 is a perfect number" in {
IsPerfectNumber(28) must be(true)
}
"496 is a perfect number" in {
IsPerfectNumber(496) must be(true)
}
"8128 is a perfect number" in {
IsPerfectNumber(8128) must be(true)
}
"if its not a perfect number should return false" in {
(1 to 500).filter(!List(6,28,496).contains(_)).foreach(n =>
IsPerfectNumber(n) must be(false)
)
}
}
}
It was definitely a fun experience and we finished the kata fairly quickly (I think 20 minutes or so). I’m planning to do a few more scala kata lunches! ![]()
Learning Scala: Factorials and foldRight
This morning I started my day off with another problem to learn scala better with and I wanted to only devote 30 minutes max to it as we had a busy day ahead. With this in mind, I did a simple factorial kata that I’ve done multiple times before in other languages to practice recursion. So I started off with the first spec:
import org.specs._
class FactorialSpec extends Specification{
"factorial" should {
"return 1 for n = 1" in {
Factorial(1) must be equalTo(1)
}
}
}
Of which I just returned n. I then wrote the next example which passed out of the box and finally wrote two more examples I knew would make me solve the problem.
class FactorialSpec extends Specification{
"factorial" should {
"return 1 for n = 1" in {
Factorial(1) must be equalTo(1)
}
"return 2 for n = 2" in {
Factorial(2) must be equalTo(2*1)
}
"return 6 for n = 3" in {
Factorial(3) must be equalTo(3*2*1)
}
"return 6*5*4*3*2*1 for n = 6" in {
Factorial(6) must be equalTo(6*5*4*3*2*1)
}
}
}
The first surprise I had was that scala apparently doesn’t have any ternary operator so I tried the following solution:
object Factorial extends (Int => Int){
override def apply(n:Int) = {
n * (if(n > 1) apply(n-1) else n)
}
}
This was fine and all, bit I decided to read around a bit more and see what features in scala I could apply to change this. FoldRight and foldLeft appeared to be right up my ally:
object Factorial extends (Int => Int){
override def apply(n:Int) = (1 to n).foldRight(1)(_*_)
}
foldRight works like this… it takes each element moving to the right for each one and, starting with the base number (in this case 1) multiples it to a running result (indicated by the second _). So for 4 this looks something like this:
1*1 = 1
2*1 = 2
3*2 = 6
4*6 = 24
Very interesting. There’s also a shorthand notation for foldLeft and foldRight, but so far I have decided against using it as it makes it look like code only some mathematical genius could understand.
EDIT: Okay, looks like I had it wrong. foldRight starts from the tail of the collection and works its way back while foldLeft starts from the head of the collection and works its way to the end.
Friday Scala Kata
As part of my quest to learn and understand scala better I’ve committed myself to doing a weekly kata and thought it’d be fun to spin it as kata I could share the problem each friday with a follow up of a solution the following week (and even better, allow others to participate too).
I began this morning by searching the the Project Euler site for interesting problems and decided that Identifying Traingle Words would be a good kata to start with.
The kata sounds simple… convert each character in a word to it’s corresponding number value (e.g. 3 for c, 5 for e, etc), sum them together and the word is considered to be a Triangle Word if the sum is equal to a number in the sequence of triangle numbers.
Good luck! Feel free to post solutions here (but try to link to http://gist.github.com for code samples as my blog comments don’t current format code samples).
Finding Good Problems for Code Katas
Today one of our “product owners” (or at least close to that role within the organizational structure) overheard me discussing my recent code kata with someone and he linked me to an interesting site full of all kinds of mathematical problems to solve: http://projecteuler.net/.
Now if I ever find myself wanting to do a code kata and have no idea where to stat I can just take a gander at their problems page. ![]()
Follow up on the Scala Prime Factors Kata
So my fellow OCIer Tim Dalton took up my challenge to find me the “scala way” of implementing the solution in a nice one liner. I changed the example in the spec to allow a result of a list with 1 in it instead of an empty list to get rid of the conditional… the result was tasty.
Also goes to show there’s still a lot more for me to learn about scala.
(for (i <- Stream.range(2,n/2); if n % i == 0 ) yield (i)).headOption.map{x => x :: apply(n / x)}.getOrElse(List(n))
He also quickly followed this up with a 2.8 compatible version as well:
object GeneratePrimeFactors extends (Int => List[Int]) {
override def apply(n:Int) = (for (i <- Stream.range(2,n/2); if n % i == 0 ) yield (i)).headOption.map{x => x :: apply(n / x)}.getOrElse(List(n))
}
Scala Prime Factors Kata
So recently I started committing myself to understanding scala better and a perfect way of doing this is to start practicing different code katas in the language. So early this morning I started the day by doing the Prime Factors Kata in scala using specs to drive development and sbt to build run tests. The thing I really like about sbt is you can run ~test and just like ZenTest file changes triggers all the specs in the project to be re-ran.
Overall my solution was pretty simplistic and comes from a java developer’s understanding of scala. I spent 30 minutes on it and shared the result on github under scala-prime-factors. Feel free to criticize to your heart’s desire and let me know of better ways of solving this… I keep feeling like there must be a simple scala one liner that I just don’t know about.
For those who are lazy, here is the spec:
import org.specs._
class primeFactorsSpec extends Specification {
"should generate empty list for 1" in {
primeFactors.generate(1) must be equalTo(List[Int]())
}
"should generate a list with 2 in it for 2" in {
primeFactors.generate(2) must be equalTo(List[Int](2))
}
"should generate list with 3 in it for 3" in {
primeFactors.generate(3) must be equalTo(List[Int](3))
}
"should generate a list with 2 and 2 in it for 4" in {
primeFactors.generate(4) must be equalTo(List[Int](2,2))
}
"should generate a list with 2 and 3 in it for 6" in {
primeFactors.generate(6) must be equalTo(List[Int](2,3))
}
"should generate list with three 2s for 8" in {
primeFactors.generate(8) must be equalTo(List[Int](2,2,2))
}
"should generate list with two 3s for 9" in {
primeFactors.generate(9) must be equalTo(List[Int](3,3))
}
}
And here is the terrible looking solution:
object primeFactors{
def generate(n:Int) = {
var x = n
var factors = List[Int]()
for(i <- 2 to n)
while(x % i == 0 && x/i > 1){
factors += i; x/=i
}
if(x > 1)
factors += x
factors
}
}