Archive for the ‘Book Review’ Category

Book Review: DSLs in Boo

While I don’t spend a lot of time on the .NET platform anymore, I’m still a big fan of Boo. Having cut my teeth on Python many years ago, I’ve always enjoyed hip Pythonic languages and when Boo came out for the .NET platform way back when, I jumped on the opportunity to experiment with it and leverage it at client sites. What’s more, it’s no secret that I’m a fan of DSLs as I do find they can be quite powerful, for example, in leveraging natural language semantics that enhance the “user experience” such as with expressing intent.

Thus, when I had a chance to read Ayende Rahien‘s “DSLs in Boo“, I jumped at the opportunity, baby! Ayende does a great job of of introducing the notion of DSLs (interestingly, there isn’t a ton of literature here specifically about DSLs alone other than Martin Fowler‘s bliki and of course, Wikipedia) in the first chapter, specifically covering the various types of DSLs (i.e. internal, external, and he goes on to define graphical ones plus he reluctantly includes fluent interfaces). What’s more, he also explores why one would want to write an DSL. Here he covers a few reasons, but a quote stuck out regarding one particular reason, which is for expressing

rules and actions in a way that’s close to the domain and understandable to business people

This is, of course, the intent of easyb — that is, to express intentions in an easily understandable language that stakeholders can grasp.

After chapter 1, Ayende goes on to cover the basics of Boo, which, of course, would be needed should you want to actually create a DSL in Boo! It isn’t until chapter 4, however, that you start to get your hands dirty coding DSLs; nevertheless, I understand the need to introduce the various required concepts leading up to chapter 4. Thus, in chapter 4, a few high level examples are covered.

Later chapters go into some details about writing and maintaining DSL code; plus, in chapter 7, he unveils Rhino DSL, which is an open source project that facilitates authoring DSLs in Boo (Ayende, by the way, is a prolific coder — he’s all over the map in the .NET world). Chapter 8 finally covers testing a DSL, which I can attest as quite difficult but paramount to a DSL’s success and stability. He also goes on to cover versioning, which I found quite intriguing as backward compatibility is a double-edged sword.

What I find most interesting is the way in which a base language affects the resulting implementation of a DSL (i.e. the end result). That is, Pythonic DSLs still have the oft complained about “white-space issue.” For instance, here is a code snippet from the book for an order processing engine:

upon auth_denied:
  when preferred_customer:
       delay_order_until_payment_is_authorized "preferred customer benefit"
  when default_customer:
       cancel_order "no money, no order"

Note how the underlying language (Boo) forces the DSL to use spaces (rather than say brackets or def/do/end like calls), what’s more, underscores (i.e. _) are required so as to keep the compiler happy. It’s, in many ways, the same in something like easyb (which is, of course, backed by Groovy), which is essentially forced to use brackets and in one case, a comma like so:

given "a preferred customer", {
  //blah blah
}

Note how Groovy requires the DSL to include a comma between the description String and the Closure. Ruby, by the way, and in the case of something like RSpec, doesn’t have this requirement. For instance, in RSpec:

it "should return item enqueued" do
  @queue.enqueue("test")
  @queue.dequeue.should == "test"
end

Yet, notice the do and end! Needless to say, you can see similar influences in something like Scala too.

DSLs are interesting beasts and they’ve clearly affected productivity on various platforms (need I remind you that Rails is a DSL?). “DSLs in Boo” specifically explores DSLs on a specific platform, yet it’s still an interesting read. Because it’s my bag, I’m definitely looking forward to more books exploring DSLs as a main subject! All in all though, this is an interesting book regardless of your chosen platform. Can you dig it, man?

Book Review: Programming Scala

One more than one occasion, I’ve found myself yearning for a more functional paradigm that facilitates easier concurrency programming on the JVM. And while Erlang is an excellent platform for concurrency, it doesn’t run natively on the JVM; thus, the next logical choice is none other than Scala (yes, Clojure is a choice as well and I’m currently reading Stu’s tome, “Programming Clojure“!).

Scala’s syntax is anything but similar to Java; what’s more, its constructs and its implementation of the actor model are all but alien to those programmers raised on a diet of Java; nevertheless, my friend Venkat does a superb job of clarifying the language with a cornucopia of examples and well articulated pages that, at least for me, revealed Scala in a concise and easy to grasp manner. And while there’s no shortage of freely available tutorials on Scala, I found Venkat’s writing as well as his examples much more approachable and practical to everyday issues (as opposed to more academia-like approaches).

Indeed, due to Venkat’s easy to read style, I’m already employing Scala on mission critical applications that rely on Scala’s implicit concurrency accommodations. In truth, I found the first half of his book indispensable in ascertaining how to actually program in Scala as its syntax is distinct from Java (although, I found myself more and more thinking that the authors have a fluency in Python — the concepts and syntax on many occasions are quite similar).

The book provides an excellent journey — it starts out easy — that is, the pace is helpful for the beginner as Venkat explores basic features, classes, typing, etc and then proceeds to some super interesting subjects like functional programming, Scala’s traits, collections, Java interoperability, followed by concurrency. Plus, he throws in the mix a chapter on using ScalaTest. Lastly, he puts everything together quite nicely with a nice example application for ascertaining stock prices (by which he demonstrates Scala’s impressive XML handling).

All in all, I enjoyed reading this book (as evidenced by the myriad highlighted sentences and example code) and indeed, working through the book gave me the extra confidence to embrace Scala quickly in a production environment.

Book review: Groovy Recipes

While Groovy can found existing in one jar file, it is a large platform with a plethora of features and tricks. In fact, Groovy in Action (for which I had the pleasure of participating in) weighed in at almost 700 pages. Consequently, Scott Davis’s Groovy Recipes: Greasing the Wheels of Java is a handy light-weight (roughly 250 pages) reference bag of tricks suitable for any Groovy developer’s desk (beginner to expert, baby).

Scott starts out answering the questions any beginner would ask — for example — how to use groovysh, groovyc, Groovy with IDEA (my preferred IDE!). He then proceeds to explain the core of Groovy — the syntax magic, operator overloading, and native collections to name a few goodies. Chapter 4 is particularly hip as it covers the tight relationship Groovy shares with Java, which always comes up when bringing the good news of Groovy to Java developers.

Scott spends two chapters covering XML — both parsing and creating it. If you haven’t seen Groovy’s XMLSlurper in action, you are in for a real doozy, baby! After that, Scott covers file tricks, the command line, and web services in Groovy– something that I’ve fully embraced Grails for. By far, my favorite chapter though is chapter 10 — Metaprogramming — which exposes the magic behind everyone’s favorite web framework: Grails. Metaprogramming is where Groovy really shines and this chapter is bound to wow a few hip souls.

The book finishes up with two chapters focused on Grails– while there are entire books written on the aforementioned subject, Grails can be covered at such a high-level quite nicely. In fact, in chapter 11 alone, you’ll have a working Grails application up and running!

All in all, my friend Scott does a wonderful job of distilling what’s a large copasetic platform into a practical bag of tricks appropriate for Java developers looking to jump into Groovy and even those in the Groovy community that need a quick reference nearby.

Book review: Beginning Groovy and Grails

I’m a big fan of writing as little code as possible and borrowing everything else. I’m also a big fan of Groovy. I recently had the pleasure of reading Chris Judd, Joseph Nusairat, and James Shingler’s hip “Beginning Groovy and Grails” and in short, I loved it! This book is all about borrowing a slick web framework (and a lot of plug-ins) and leveraging the power and simplicity of Groovy to build web applications quickly.

I used this book extensively to build three different Grails applications and I found that the authors essentially covered everything one would need to it successfully. The first three chapters cover the basics of Groovy nicely, then the book dives head first into Grails with 12 valuable chapters covering GORM, Services, and using various plug-ins. Plus they cover deploying Grails applications, Ajax, and even do some cool stuff with JasperReports. I really liked how they consistently built upon a sample application throughout the entire book– that made comprehending what was going on a bit easier as you, as the reader, didn’t need to re-understand the domain.

In particular, chapters 7 and 8 proved quite helpful as they cover both security and Ajax. I did find myself wishing that the Acegi section went a bit deeper — I ultimately found myself adopting a JCaptcha solution as it proved to be a lot easier; regardless, their in-depth covering of all things related to security broadened my knowledge of the options available in Grails. I ended up using some Ajax components not covered in their Ajax section; however, they do a great job of adding some slick features to an application they build from scratch throughout the book.

I was hoping the Web Services chapter would go a bit deeper as I’m hoping Grails can become a widely adopted option for building RESTful applications; nonetheless, they do a great job of adding the essential CRUD operations to their example application. Plus they tie everything together nicely in the last chapter– 13.

If you are looking to learn Grails quickly, because it’s my bag, I can’t recommend this book enough– it covers designing, building, and deploying a Grails web application and it does so by continually building upon an ongoing application. It doesn’t matter if you don’t have a command of Groovy either, as they do a great job in the beginning and throughout the book of demonstrating Groovy’s essence.

Book review: Programming Erlang

Concurrency is hard. A language’s implementation of concurrency concerns can make the challenge of dealing with concurrency even more difficult or a bit easier. Case in point: Erlang. Erlang is a hip functional language, developed by Joe Armstrong of Ericsson in the 1980s that explicitly facilitates concurrent programming by enabling distinct parallel processes (as opposed to threads) which communicate via message passing (rather than shared memory). Thus, in Erland, there are no locks or the need to declare synchronization as there is no notion of shared memory, like there is in Java (or C#, for that matter).

The question then remains for those who are Java developers: why should I care? For starters, because it’s my bag, it is undoubtedly interesting to see how Erlang is so vastly different than everyday Java. Not only is the language functional in nature (like Haskell), but it’s also type-less (that is, types are inferred at runtime like with Ruby, for instance). Because the language was built for parallel computing, it does some interesting things that have correlation back to Java– for instance, in Erlang, all variables are essentially final once declared. Thus, Erlang doesn’t support mutable state. As anyone who’s ever coded in Java knows, mutability, while intrinsically supported by Java, can easily create nefarious defects, even in non-threaded code.

But I think the author, Joe Armstrong, does a great job of stating why one should care about Erlang. In chapter 1, a rhetorical question is posted asking “what all this about?”– Joe’s response sums it up quite nicely:

It’s about programming a distributed concurrent system without locks and mutexes but using only pure message passing. It’s about speeding up your programs on multicore CPUs…it’s about designing methods and behaviors for writing fault-tolerant and distributed systems. It’s about modeling concurrency and mapping those models onto computer programs…

All in all, I enjoyed this book– I certainly learned an interesting language that has a long history of production use. It’s a big book (500+ pages including documentation) and I did find myself skipping a few chapters here and there– for instance, there is an entire chapter devoted to a custom database developed for Erlang (my thought being that if I need a database for an Erlang application, I’ll use a language bridge to leverage an everyday RDBMS).

Learning a new language is always helpful, man; in fact, I took my own advice, as I wrote years ago, those that learn new languages:

travel the IT world more freely than do monolinguists (sure that they can apply their skills in any environment), and they also tend to better appreciate the programming language called home, because among other things they know the roots from which that home is sprung.

Next language to learn? Scala, baby!

Book review: Test Driven .NET Development with FitNesse

The Framework for Integrated Tests serves as an copasetic mechanism for bridging the gap between those that write requirements and those that turn those requirements into code– the beauty of defining business rules in tabular format (either through HTML, Word documents, and even Excel files) and auto-magically wiring that data with application code is no Siren song, but an accelerating force for high speed development teams living in the Age of Aquarius. What’s more, combining FIT with a wiki was a brilliant move and the resulting tool, FitNesse, brings together the power of FIT with a collaborative mechanism for building test suites and capturing requirements (and even stories) by leveraging the ubiquity of a browser.

While FitNesse has been leveraged by some, it, in many ways, baby, has suffered from a lack of in depth documentation– indeed, even Mugridge and Cunningham’s hip “Fit for Developing Software: Framework for Integrated Tests” book barely scratched the surface of FitNesse, thus leaving some teams in the dark as to how to effectively employ it. Luckily, with the publication of Gojko Adzic‘s “Test Driven .NET Development with FitNesse” any lingering questions developers may have are now answered.

Because it’s his bag, Gojko does an excellent job of taking an application from inception to production, all the while building on technique after technique for defining FIT tables and running them with FitNesse. He does a hip job of making the case for the complementary nature of unit testing (in this case NUnit) and acceptance testing with FitNesse; what’s more, even though the programming domain is .NET, this book peels away enough of the covers of FitNesse (which is, of course, written in Java) to make it useful for anyone looking to employ the tool, man.

If you find yourself curious about FitNesse or are looking for ways to leverage domain experts more effectively, then I highly recommmend picking up a copy of “Test Driven .NET Development with FitNesse“– when you finally set the book down, you’ll find yourself a much smarter person! Dig it?

Book review: Generating [hip] Parsers with JavaCC

Before the age of Disco, I once found myself in need of obtaining specific data elements from a series of log files generated by a large order processing system. Essentially, a chain of copasetic state machines would log their status while they processed various aspects of an order– line items, billing, notification, etc. It turned out that the log format was uniform– it followed a format that enabled one to understand who was writing, when it was written, and why. As you can probably imagine, the folks in operations would monitor these logs and when problems arose, they’d ping development.

Invariably, a hip developer would ssh onto a production box and literally tail -f said log file and watch things progress (in real time). Some developers were more savvy and would pipe the contents into a grep command looking for error messages, but ultimately, it varied from person to person how they’d actually assess the situation.

I, indubitably being of the lazy disco type, wanted to press a button (or run a simple command) and receive a report when I found myself in the hot seat. Of course, this problem has been solved the world over and I had to do it my way because I’m a developer so I started investigating parsing libraries and ran across, what was at the time, some WebGain documentation on JavaCC. Unfortunately for me, I didn’t have the attention span to figure things out and eventually went the regex route via Jakarta’s ORO library.

Tom Copeland’s “Generating Parsers with JavaCC” has, without a doubt, shown me the error of my ways all those years ago. His masterpiece on JavaCC serves as the reference for this handy library– indeed, a major portion of this book documents every detail of generating parsers by clearly unveiling the particulars of tokenizing, parsing, error handling, and even testing JavaCC parsers, just to name a few. I particularly enjoyed the chapter on JavaCC’s JJTree preprocessor as it tied in a lot of the details, for me personally, of writing custom PMD rules.

Indeed, now that DSLs are all the rage these days (I’d go so far as to label them hip, baby), “Generating Parsers with JavaCC” can easily enable adventurous types to assemble mini-languages (and obviously parse and handle them via JavaCC). Because it’s his bag, Tom does a great job in chapter 11 of enumerating a few examples of doing so, in fact. What’s particularly amusing for me is that he shows an example of parsing Apache’s web logs.

I was eventually able to keep on truckin’ by running a single command to receive a detailed report of various goings on in the order processing application I mentioned earlier– my trippin’ little utility made heavy use of regular expressions and served its purpose well enough. But, after reading “Generating Parsers with JavaCC” I realize that my job could have been a bit easier had I just relied on JavaCC to do the heavy lifting of parsing the application’s log files. You can bet that if I find myself in a similar situation in the future, you’ll find me coding away with a well marked up, heavily worn copy of “Generating Parsers with JavaCC” by my side. Give this groovy book a read– you’ll find yourself smarter for it.