Author of "Groovy Recipes" & TDD Expert
Scott Davis is an internationally recognized author and speaker. He is passionate about open source solutions and agile development. He has worked on a variety of Java platforms, from J2EE to J2SE to J2ME (sometimes all on the same project).Scott's books include Groovy Recipes: Greasing the Wheels of Java, GIS for Web Developers: Adding Where to Your Web Applications, The Google Maps API, and JBoss At Work.
Scott is the Editor in Chief of aboutGroovy.com, a news and information website that tracks the latest developments in Groovy and Grails. He also writes a regular column for IBM DeveloperWorks -- Mastering Grails.
Scott is a frequent presenter at national conferences (such as No Fluff, Just Stuff) and local user groups. He was the president of the Denver Java Users Group in 2003 when it was voted one of the top-ten JUGs in North America. After a quick move north, he is currently active in the leadership of the Boulder Java Users Group. Keep up with him at http://www.davisworld.org.
Presentations by Scott Davis
Refactoring into Testability
"This code is simply too hard to unit test." That is a common refrainwhen dealing with software that hasn't been expressly written to be
testable. In this section we look at "untestable code"
and explore various ways to make it more testable. What you'll come to
realize is that "untestable code" is really another way of saying
"poorly architected code." We'll demonstrate simple, common-sense
strategies that solve both problems.
Mocking 101
Modern dependency-injection (DI) frameworks like Spring and Guiceemphasize the flexibility of an interface-driven design. By
programming to the interface instead of the implementation ( List x =
new ArrayList() ), you are well on your way towards easily mocking out
behavior for testing purposes (i.e. swapping out implementations
behind the scenes). This is the hallmark of a loosely-coupled
application, and we'll use it to our advantage to dramatically ease
our testing duties. Testing individual classes in isolation is
important, and writing concrete mock objects is one way to achieve
this goal.
Real World Test Driven Design
Everyone has their favorite excuses for not writing unit tests: "Ittakes too much time", "It's not my job", "But it compiles!" In this
presentation we talk about the importance of testing, and how the act of
writing your own unit tests leads to better architected code.
Scott Davis (Musings on Java and Open Source)
What's so funny about Java, OS X, Peace, Love, and Understanding?
Wednesday, August 1, 2007
Every time I see a live show at the Denver Botanic Gardens, I think to myself, "This time I'm gonna blog about it." Then I get home and get distracted with other things. (Given the long silences at this URL, you are well aware of how easily I'm distracted...) After a Botanic Gardens show I almost always sit on the back patio, have a nice glass of wine, and try to stretch out the vibe of the evening just a little bit longer. That doesn't happen after other shows. Just Botanic Garden shows.
The venue itself is nearly perfect. As the name implies, you are surrounded by unspeakable beauty. It is a grassy amphitheater that seats just over 2,000 people. Being outside on a perfect Colorado night -- watching the sun go down early over the Rockies, listening to the cicadas accompany the band later -- is something that can only be experienced. Words hang hollow on the page in comparison.
Red Rocks is another local natural amphitheater. No one should die before seeing their favorite band play Red Rocks. But it is different. Deeply different. Shows there are events -- loud rock spectacles. Shows at the Botanic Gardens are intimate.
Just tonight, Patty Griffin marred an otherwise enjoyable set by playing three opening songs in rapid succession, and only then offering up a meek, "Hello [pause] Denver. Thank you for having us to this beautiful venue [pause], the Denver Botanic Gardens." At Red Rocks, that sort of stilted, scripted greeting is expected. ("Hello Cleveland! Are you ready to rock?") At the Botanic Gardens, you just expect more.
Like the time that Jewel forgot the second verse of a song. She stopped -- embarrassed -- and asked the audience for help with the lyrics. After she blew the third verse, she just quit. "Wow -- it wasn't the right night for that song, was it?" What in any other venue would've been a travesty, was greeted by applause and laughter at the Botanic Gardens. Here we want the performer to talk to us, interact with us -- not simply sing at us. The songs are nice, but as Garrison Keillor discovered, spoken words are just as well received as long as they are sincere.
Nearly every show at the Botanic Gardens is a sell-out. Since the "seats" are the blanket you spread on the grass surrounding the four-sided stage, reserved seating is a luxury that doesn't exist there. There is a comfortable ritual that we settle into for every show. The doors open at 6pm, but to get a seat in the front quarter of the stage you need to be in line by 4pm. Sometimes K draws the short straw. Sometimes I do. The loser has to stay at home. The winner gets to sit in line with a book (her) and a beer (me) waiting for the civilized rush into the park.
Once the blanket is spread, out comes the picnic and the wine. You can buy boxed dinners there (smoked salmon and mixed field greens), but it is always more enjoyable eating your own food. Prosciutto and brie. Fume Blanc. Sometimes a dessert from Whole Foods, other times a home-made Rice Krispie treat. It doesn't matter -- it all tastes better there.
You have an hour until the opening act starts. Tonight it was Scott Miller. If you can only buy a single disc of his, make it "Are You With Me?" The raw acoustic set -- a red guitar, three chords, and the truth -- fills the stage better than a full band. Less was certainly more when Patty braved the stage by herself for several songs. Her band was talented, but she connected best when she was up there by herself. She visibly startled herself by stomping on the floor in time with the song and actually hearing it.
The only exception to this "less is more" rule might have been Wynton Marsalis' set with African drum master Yacub Addy and Odadaa. The 20 (?!) piece Lincoln Center Orchestra shared the stage with another 6-8 African musicians. It was like nothing I've ever heard before. Chris Botti put on a helluva show, but hearing the unmic'd call and response of Wynton's band took the cake.
And then, before you want it to, the night ends. The Denver Botanic Gardens are nestled in a tony residential neighborhood. Like a sullen adolescent, it has a curfew of 9:30pm. Its big brother Red Rocks has no such (unfair) limit. You're tired and ready for bed after a Red Rocks show. In contrast, even after a 30 minute drive home from the Botanic Gardens, you're not quite ready to call it a night. So you sit outside on your back porch, sipping a nice glass of old vine Zin, trying to stretch out the vibe of the evening just a little bit longer. One of these days, you'll actually write about it...
Thursday, May 3, 2007
I was doing some spring cleaning on my hard drive this morning ("rm -Rf *" -- no, NOT in my home directory...). As an afterthought, I did a "ls -al" to verify that, indeed, everything was gone. To my surprise, there were a couple of StuffIt droppings left behind. ".$$ StuffIt Temp 1143648937" Big 'uns, too. Almost a gig worth of dead air. Them files needed killing.
Strange, though, that they wouldn't die. "rm -Rf *" is the command-line equivalent of "slash and burn, take no prisoners". I was the owner of the files, yet couldn't delete them. Perhaps it was a permissions problem. "sudo rm -Rf *" foiled my all-powerful alter ego, Root, as well. Apparently these files were laced with kryptonite.
The leading "." makes the directory or file hidden, but it shouldn't tattoo it to my hard drive. I'm pretty sure that it was the dollar signs that was slipping bash a mickey. Surrounding the file name in single quotes didn't help -- "rm -Rf '.$$ StuffIt Temp 114364'". Neither did letting the bash shell tab-complete the file name -- "rm -Rf .\$\$\ StuffIt\ Temp\ 114364". This was really beginning to harsh my mellow.
So, I pulled out the big guns. TinkerTool, among other things, gives Finder x-ray vision. It is, refreshingly, a free utility in a sea of $20 Mac add-ons. The very first checkbox on the very first tab of the utility is what I needed -- "Show hidden and system files". Once Finder could see 'em, Finder could delete 'em. Odd that the GUI came through when the CLI failed, but I'm not asking questions.
As TinkerTool rode off into the sunset, I heard him mutter under his breath, "I love the smell of Napalm in the morning." Me too, TT. Me, too.
Monday, April 30, 2007
Groovysh is one of my very best friends. Unfortunately, he is a bit hard of hearing. Here is a typical conversation:
Me: rpintln "Hello"
Gs: Eh?
Me: pintln "Hello"
Gs: Beg pardon? Speak up, Sonny.
Me: println "Hello"
Gs: Ahh -- why didn't you say so? "Hello"
As you can see, the problem is clearly with Groovysh. I type the same thing three times, and Groovysh's hearing loss impedes our communication. (That is the only logical explanation...)
On Windows, you can just hit the up and down arrow keys to recall previously typed commands. On the Mac, this is one of the few things that doesn't "Just Work." Here are the steps you can take to get readline support enabled in Groovysh on the Mac.
Step #1:
This space left intentionally blank. (Stupid Windows -- gloating is much more fun when it is at
Step #2: Install Readline
If you have MacPorts installed, you can type "sudo port install readline"
Step #3: Install Java-Readline
Download the pre-compiled binary, unzip it, and place the two resulting files (libJavaReadline.jnilib and libreadline-java.jar) in /Library/Java/Extensions. (For the brave-hearted / those with too much time on their hands, full build instructions are available here.)
Step #4: Install Groovysh-Readline
Download groovysh-readline.jar and place it in ~/.groovy/lib. If you don't have a .groovy directory in your home directory, create one. (Don't forget the leading "." -- this makes the directory hidden in Unix.) Anything in the lib directory will automagically be added to your classpath when you run groovy from the CLI.
You can create a .groovy directory under your home directory on a Windows box as well. The proper directory is c:\Documents and Settings\your-name-here. Of course, if you're on a Windows box you won't need to drop groovysh-readline.jar in there since command history is already enabled. (Stupid Windows, making me look bad...)
Step #5: Run Groovysh in All of Its Readline-Enabled Goodness
Type "groovysh". Type "println Hello". Type "go". Hit your up arrow and tell Groovysh "Hello" again. Your command-line history is saved between sessions in a plain-text file named ~/.groovy/groovysh.history.
Step #6: Give the Next Windows User You See the "Stink-Eye"
It may also help to mutter under your breath, "You may have won this battle, Windows-Boy, but you'll never win the war." When they look at you quizzically, wave your hand dismissively and say, "Never mind. Your blind allegiance to the Dark Empire will be your undoing in the end." Then whisper conspiratorially to your Mac, "That's right, my Precious. They don't understand you like I do. They don't
Epilogue
Linux users should be able to follow similar steps to get readline support enabled in Groovysh on their platform. (No, it doesn't work there natively, either. Laugh it up, Windows-Boy...) The only thing that will change is Step #3. You'll need to compile Java-Readline for your platform.
Saturday, April 21, 2007
Due to the load the comment-spammers were placing on this server, I've had to turn off comments for now. Thanks, dudes, for really harshing my mellow. At some point, an intelligent spammer might come to the conclusion that choking the server that they're trying to deface isn't exactly a sustainable policy. I'll turn comments back on as soon as I can find a better solution for keeping out the riffraff. In the meantime, please enjoy what the Apple Dictionary/Thesaurus has to say about "riffraff":
riffraff |rif raf|
noun
disreputable or undesirable people : I don't think they talk to riffraff off the street.
ORIGIN late 15th cent.(as riff and raff): from Old French rif et raf 'one and all, every bit,' of Germanic origin.rabble, scum, good-for-nothings, undesirables, lowlifes, hoi polloi, the lowest of the low;
'Nuff said.
Friday, April 6, 2007
I live and die by tab completion on the command line. Normally I use it to quickly navigate to deep directory structures. Rather than typing in the full path to something like "~/tmp/minneapolis/bookstore/grails-app/domain", I type "cd ~/tmp/min[tab]/b[tab]/g[tab]a[tab]/d[tab]".
Now that I spend most of my time in TextMate doing Groovy and Grails development, that little tab key is getting a workout. TextMate offers bundles for both Groovy and Grails that allow you to tab-complete your source code. Once the bundles are installed, I type "hm[tab]" instead of "static hasMany = [items:ClassName]". Note that this isn't really the same as the ctrl+space code completion you get from the Groovy/Eclipse plugin -- TextMate bundles just dump boilerplate code to the screen. But, quite honestly, I find myself spending less and less time in a full-blown IDE these days. IntelliJ still gets fired up for my increasingly rarer Java development, but the agile little TextMate editor is closer in spirit to the agile little Groovy language. (I am, however, eagerly awaiting IntelliJ 7 and its strong new support for Groovy and Grails. Since Groovy and Java mix together so well, I have ctrl+space envy whenever I'm working on a mixed project.)
Recently, Doyle of DoyleCentral.com posted an entry titled "Grails Tips and Tricks" that contained this intriguing little snippet: "If your [sic] on NIX and use bash/dash or some variant I have created an auto-complete feature that is quite handy for the command line."
Now, it seems, I can tab complete grails commands like "grails create-domain-class". You have
So, here are the step-by-steps to get bash-completion running on your Mac.
Step #1: Buy a Mac
(That joke just gets funnier the more I tell it...)
Step #2: Install MacPorts
MacPorts is an apt-get-like tool for OS X. (Apt-get for Ubuntu, port for OS X -- easy breezy.) It allows you to quickly install Macintosh ports of popular Linux/Unix utilities. Utilities like...
Step #3: Install bash-completion
...bash-completion. Typing "port info bash-completion" says it all: "Brings programmable completion to bash like those pesky zsh users have had for years." Type "sudo port install bash-completion" to install it.
Step #4: Tweak Your .bash_profile
In your home directory, there is file called .bash_profile. This is where you can put all sorts of interesting little nuggets like environment variables and aliases. One line is "alias m=mate", so that I can type "m ." to pull up an entire directory of source code in TextMate. Another block of code looks like this:
### Grails GRAILS_HOME=/opt/grails PATH=$PATH:$GRAILS_HOME/bin export GRAILS_HOME PATH
This, of course, is what allows me type in "grails" at the command prompt. BTW, I keep multiple versions of Grails in /opt using their fully-qualified directory names: grails-0.3.1, grails-0.4.1, grails-0.4.2. I then symlink "grails" the version I want to make active: "ln -s grails-0.4.2 grails". (I use the same trick for Groovy, Java, Ant, Tomcat, JBoss, Geronimo... it allows me to keep the environment variables static and flip them based on a single command-line tweak.)
To enable bash-completion, copy this block into .bash_profile:
### BASH Completion
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
fi
To make sure that these changes take effect, type "source .bash_profile" or simply exit the terminal window and fire up a freshy.
Step #5: Download and Scatter the Grails Bits
Doyle posted a tarball that contains two magic files. Copy grails_commands to /opt/local/etc/bash_completion.d/. Copy command-list to $GRAILS_HOME.
Step #6: Enter Grails Nirvana
Here we go...
- cd tmp
- grai[tab] cr[tab]a[tab] bookstore (grails create-app bookstore)
- cd b[tab] (cd bookstore)
- grai[tab] cr[tab]d[tab] book (grails create-domain-class book)
- m . (mate .)
- add the interesting bits to /grails-app/domain/Book.groovy
- grai[tab] r[tab]a[tab] (grails run-app)
- visit "http://localhost:8080/bookstore" in the web browser of your choice
That, my friends, can only be called tabalicious.