{ Category Archives }
OJUG
Upcoming talks
I’ve got a few talks coming up in the next couple months:
March:
Domain Specific Languages - I’ll be talking to the Omaha Dynamic Language Users Group on March 6th. I will be focusing on the Groovy language, but may slip in some Ruby and Lisp.
Basic Spring - This talk will be part of the Omaha Java Users Group March 20th meeting. It will be a “nothing but Spring” meeting. Nick Larson will be talking about Spring MVC, whil I will focus on the fundamentals.
April:
This year I will be presenting at Infotec, the local Omaha conference for Information Technologies, put together by the local AITP association. I have one session and one tutorial:
Agile Java Web Frameworks - sort of an omnibus of the latest frameworks, and of course what a “agile web framework” is.
Introduction to Ruby on Rails - this will be a four, yes FOUR, hour tutorial using Ruby on Rails. I am so excited to be doing this! We will be building an application from scratch, covering most of the features in Rails.
Should be a fun couple of months!
Groovy-licious!
So, Groovy 1.0 is finally here! If you asked me a year ago, I would have said that I was just not interested in Groovy. I thought it was a dead language, and I had better things to focus on. It seemed like a great idea, but just not going anywhere. But, thanks to the committed team of developers, it has finally shaken off the vapors.
Scott Hickey, lead developer of the Groovy Eclipse plugin, has been gently pushing me to learn the language for a long time now. And, it has piqued my interest a few times, but never to the point of actually writing some code.
At our January OJUG meeting earlier this week, we had a group discussion about Groovy and how far it has come. I made a mental note to sit down and give it a go-around… kick the tires so to speak. And, yesterday I had the chance to sit down with Scott for lunch, and he went through the Groovy Eclipse Plugin with me. He showed me where things are at, and what I can do to help out.
And finally last night I sat down and wrote some Groovy. As with most languages, I started out with my favorite little program: Pegs. If you are not familiar with the game, it is basically a triangular board with fifteen holes in it, also in the shape of a triangle:
*
* *
* * *
* * * *
* * * * *
You start the game with one empty hole, and the rest filled with pegs. The object of the game is to jump a peg over another peg into an empty hole, repeating until there are no more moves left. Obviously the goal is to get down to just one peg.
Here is the code for the Board object (Board.groovy):
-
package pegs;
-
-
class Board {
-
private EMPTY = 0
-
private SET = 1
-
-
/*
-
pegs are set as follows (last row is 10 - 14)
-
0
-
1 2
-
3 4 5
-
6 7 8 9
-
0 1 2 3 4
-
*/
-
-
private pegs = [SET,
-
SET,SET,
-
SET,SET,SET,
-
SET,SET,SET,SET,
-
SET,SET,SET,SET,SET]
-
-
Board(starting_peg = 0) { pegs[starting_peg] = EMPTY }
-
-
-
return board
-
}
-
-
-
“””
-
${pegs[0]}
-
${pegs[1]} ${pegs[2]}
-
${pegs[3]} ${pegs[4]} ${pegs[5]}
-
${pegs[6]} ${pegs[7]} ${pegs[8]} ${pegs[9]}
-
${pegs[10]} ${pegs[11]} ${pegs[12]} ${pegs[13]} ${pegs[14]}
-
““”
-
}
-
-
-
]
-
-
-
}
-
-
}
-
}
-
-
}
-
-
class Move {
-
-
protected from;
-
protected to;
-
protected over;
-
-
Move(_from, _to, _over) {
-
from = _from;
-
to = _to;
-
over = _over;
-
}
-
-
}
This code hits a ton of features that differentiate Groovy from Java:
- Lines 4,5: Right away we see something strange. Where did the type go?
- Line 16: Whats going on here? Not only are we not giving a type for the variable, but we also are assigning it what looks like a list…. huh.
- Line 22: This must be the constructor for the Board class… but look! the method argument doesn’t have a type! and it allows you to set default value!
- Line 24: Ok, so where did the return statement go?
- Lines 25,26: Ok, Stop! Whats going on here? This is where it all starts to become gravy. So far we’ve see how Groovy simplifies our Java by getting rid of types here and there, and allows us easier creation of Lists, and the ability to ignore return statements. Now, we are seeing the Lisp nature of Groovy:
This method is returning the number of empty pegs on the board… but how? It is passing a closure to the findAll() method, which then iterates the list of pegs and calls the closure on each. The closure must (in this case) return a predicate (boolean), and only the positives are added to a list which is returned, only to have the size property actually returned to the caller.
- Line 31: Whats with the def keyword? Thats needed inside the methods to def a method scoped variable… I think there is more to it than that, but that is what I know so far.
- Line 32: Whats with the 0..14 business? Thats a Range. Like Python, Ruby, et al.
- Line 37: Yay! We have joins!
- Line 40: Three quotes? wtf?!?! This is the demarcation of a multiline string. Something I have wished and prayed for (and man I do not pray for a lot) since I first experienced XML. This alone makes me quiver. Yes, I said quiver.
- Line 41: ${pegs[0]}…. I see… its doing text replacement with the value from the pegs list… sweetness!
Everything else is pretty much either been discussed by the above, or is straight forward enough to not require too much more explanation.
In case you were interested, here is the test code. Groovy makes testing so much nicer than Java. This is not a great example, but imagine what the triple-quote feature can do for you…
-
package pegs;
-
-
-
}
-
-
}
-
-
board.makeMove(board.availableMoves()[0])
-
}
-
-
-
-
board.makeMove(board.availableMoves()[0])
-
-
board2.makeMove(board2.availableMoves()[0])
-
}
-
-
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
board.makeMove(board.availableMoves()[0])
-
-
}
-
-
}
The Board class does not really do much for you. It’s really just a state object: It gives you all of the information you need, but needs an external object to tell it whats going on. So, part of this project always entails writing a Solver to figure out all of the different winners and board states. Its a really simple Game Theory system that looks at all of the possible states of the board. So, finally, here is Solver.groovy:
-
package pegs;
-
-
winners = 0
-
boardCount = 0
-
-
println “\nStarting board(${peg})”
-
walkAvailableMoves(board)
-
}
-
-
-
-
boards[board.hash()] = board
-
boardCount++
-
moves = board.availableMoves()
-
winners++
-
}
-
-
moves.each { move ->
-
newBoard = board.copy()
-
newBoard.makeMove(move)
-
walkAvailableMoves(newBoard)
-
}
-
}
-
-
println “”
-
println “boards: ${boardCount}”
-
println “winners: ${winners}”
A little recursion to set the heart a-flight. Ooookay. As you can see, this is, as Bob Ross would say “just a happy little Groovy script”. (Sorry, we don’t have cable, so we are pretty much left with PBS). The only thing that may stick out a little more, and something that I did not mention above, is that there is not one semicolon in this whole script. This is typically the case with Groovy. The only time it is necessary is when you are putting multiple code statements on the same line.
Some thoughts
As indicated above, I was not a big fan of Groovy, and instead decided to go the Ruby Way. However, I think I have found the language I was looking for when I went to Ruby, and its called Scheme. Oops.. I um… Ah crap.
Seriously, Groovy is a great addition to the JDK. I was surprised to see many of the Rubyisms that I have come to love expressed in the VM that has inhabited my career for the last 7 years. I am really excited by the possibilities that adding Groovy to my repertoire will provide.
If you haven’t already, I suggest you go out and get the Groovy in Action book, and while you are at it, download the Getting Started in Grails book from InfoQ.
I have already decided what my first Grails project will be… I just hope I have enough time this weekend to get the ball rolling on it.
“an introduction to Ruby on Rails” presentation is up!
I had a great time talking with everyone about Rails last night at Omaha’s Dynamic Language Users Group. A big “Thank You!” to everyone who showed up! We had a record ~25 people there.
Thanks to Matt Payne for anticipating the crowd, and getting us a sweet room at UNO. The room had built-in cameras which allowed us to videotaped the whole thing. I must say it was kindof strange to be mic’d and videotaped… a new experience for me. Than you to Bob the A/V guy at UNO for making that all happen!
I have not had a chance to look at the tape yet, but I am hoping that one of my lucky-bastard friends with a Mac might be able to do a little post-production work on it and then I will push the video out on the site… or to be more Web 2.0-is YouTube.
But meanwhile, here are the slides, available in the following formats: HTML, PDF, and OpenOffice (ODP).
The HTML and ODP formats have the notes, where the PDF is just the slides.
Also, thank you to Harish over at BusinessWorks/IdeoLogicLLC for the kind words! He has also posted a few links that should be of interest if you want to persue Rails further.
Upcoming Speaking Engagements
I am going to have a busy summer. I have a number of speaking engagements over the next few months:
Omaha Dynamic Languages User Group
Date: June 6th
Presentation: Ruby on Rails
I will be giving an overview of Ruby on Rails to the Dynamic Language group. I hope to have time to learn RJS so that I can really focus on that technology.
Omaha Java User Group
Date: June 20th
Presentation: Java Performance Tools, Tips, and Tricks
Unless somebody else steps up and volunteers to present, I will be giving a preview of my No Fluff presentation in July.
Central Iowa Software Symposium
Presentation: Java Performance Tools, Tips, and Tricks
This is an extended presentation of what comes below. In addition to performance monitoring, I will be talking more about the hows and whys of performance.
OSCON 2006
Presentation: Open Source Performance Monitoring Tools and Tricks for Java
This is a survey of Open Source Performance Monitoring Tools for Java. It is only a 45 minute session, so it will go very fast. If you cannot make it to Portland (hey, I understand
), then take a look at my presentation for Bass & Associates… they will be similar.
Central Iowa JUG
Presentation: Integrating AJAX into the Enterprise using REST and ActiveMQ JMS
Right now they have me down for Performance Monitoring, but currently the plan is to talk about AJAX working in conjunction with ActiveMQ JMS and the REST protocol. I have a lot to do on this one still!
Wow. Every time I look at that list, I start freaking out about the amount of work ahead of me. But, I am really looking forward to the challenge. This should be a very exciting summer!