Attack of the Killer Parentheses: ‘Clojure in Action, 2nd Edition’ – #bookreview

Clojure in Action, 2nd Edition

Amit Rathore and Francis Avila

Manning – paperback

Clojure seems to be afflicted with a measles-like outbreak of parentheses, and it generally just looks strange to many software developers. And there’s a good reason for that, as this book’s two author point out in their recently released second edition.

“Clojure’s syntax is derived from its Lisp roots: lots of parentheses. It’s alien to most developers with experience in languages with Algol-inspired syntax like C, C++, Java, Python, Ruby, Perl, and so on.”

But Clojure also is an intriguing and powerful choice for many software development projects, Amit Rathore and Francis Avila insist. Clojure is “a functional Lisp on the JVM” (the Java Virtual Machine), and: “It is impossible to separate the Lisp, functional programming, and JVM features of Clojure. At every step they play on each other and tell a compelling software development story….”

I have been tinkering with Clojure on the side, at random spare moments, for more than two years, using a disorganized approach of looking at web postings, building and modifying simple projects that others have posted, and sometimes looking at Clojure how-to books as time permits.

From my perspective, Clojure in Action, 2nd Edition fills a beginner’s need for a friendly, well-organized approach to learning the language and putting it to work effectively. Developers already working with Clojure can benefit from having this book, too, as a handy reference. It covers a lot of ground, using reasonably short paragraphs and offers many short code examples to illustrate its key points.

Clojure in Action, 2nd Edition “assumes no prior experience with Lisp or with any functional programming language,” the authors emphasize. “It starts out with the absolute basics and slowly layers on the different features of the language in  a way to make it all fit together in an intuitive way. It takes a first-principles approach to all the topics, first explaining why something needs to be done a certain way, and only then talking about the Clojure way.”

Clojure is not a language for absolute beginners. The authors assume “you’re familiar with an OO [object-oriented] language like Java, C++, Ruby, or Python, but no background in Java, Lisp, or Clojure is required.” They also assume you have downloaded Clojure and gotten it working on your PC. You can read more about Clojure and download it here.

This expanded 2nd edition states that it covers the “new” features of Clojure 1.6. Of course, Clojure already is up to 1.8, but I have tried many of the code examples at various points in the book and have not encountered problems while running 1.8.

Si Dunn

Advertisements

Groovy in Action, Second Edition – A hefty how-to guide newly updated for Groovy 2.4 – #programming #bookreview

Groovy in Action, Second Edition

Dierik König and Paul King, with Guillaume Laforge, Hamlet D’Arcy,
Cédric Champeau, Eric Pragt and Jon Skeet

Manning – paperback

Groovy in Action, Second Edition, is not light reading. Indeed, the printed book weighs nearly three and a half pounds and has 880 pages. But it is great reading for anyone who wants to learn, or get better at, the increasingly popular Groovy scripting language that works very smoothly with Java. Indeed, Java’s creator, James Gosling, has hailed Groovy’s “smooth and efficient” integration with Java and called Groovy “an effective implementation language in its own right.” He also has praised the Groovy in Action book as “a clear and detailed exposition of what is groovy about Groovy.”

The Second Edition‘s two main authors and five assisting authors are members of the Groovy core team. And their book spent a lot of time being reviewed and tested by readers in the Manning Early Access Program (MEAP) before it was formally released. So it likely has a better preparation record than many programming books currently on the market.

Groovy in Action‘s front flap indicates that the book covers Groovy 2.4. Groovy recently was up to version 2.4.3, but the programming language has maintained a good track record for supporting backward compatibility. Indeed, I tested random selections of the book’s code samples using version 2.2.0 and its Groovy Console, and programs compiled and ran without problem.

However, if you own the first edition of Groovy in Action, you likely will want to upgrade to the new book. It is, the authors state, “a full rewrite,” with several new chapters, plus  “a few hundred additional pages of genuinely new content.” (And yes, I am upgrading my Groovy installation from 2.2.0 to 2.4.3.)

Despite its heft, the book is nicely structured and easily approached. And its many code examples are mercifully compact, for the most part, and available online, if you prefer. (I actually enjoy keying reasonably short code examples into the Groovy Console.)

The 20 chapters are organized into three major parts:

  • The Groovy Language
  • Around the Groovy Library
  • Applied Groovy

“The Groovy Language” introduces the reader to the language’s basics: its “syntax, grammar, and typical idioms,” plus how to use dynamically typed Groovy as a static language, if desired. The “Around the Groovy Library” reference section focuses on such topics as working with builders and the Groovy Development Kit (GDK), as well as Groovy’s support for database programming and the handling of JSON and XML. And “Applied Groovy” looks at “typical uses cases for Groovy,” including “a thorough exposition of how to use Groovy for test automation,” how to put Groovy to work on multi-core machines in concurrent programming situations, and “using Groovy for domain specific languages.”

In short, there is no shortage of useful content in Groovy in Action, Second Edition.

Si Dunn

——————–
Get Groovy in Action, Second Edition here, at no extra cost.
——————–

Java 8 in Action – Ready for lambdas, streams and functional-style programming? #bookreview

 

Java 8 in Action

Lambdas, streams, and functional-style programming

Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft

(Manning – paperback)

 Java 8, we were sometimes assured, would just be Java 7 with a few slick new (or past-due) features added.

Actually, now that it’s here, Java 8 represents “the biggest change to Java in the 18 years since Java 1.0 was released,” the three authors of this fine new book point out.

Of course, news of “big changes” seldom sits well with developers who have spent countless hours learning and getting comfortable with one particular version of a programming language.

And many coders and companies will continue sticking with Java 7 for a while longer, because it still works. But the adoption pace for Java 8 keeps picking up. So, to misquote an old sci-fi slogan, resistance soon will become somewhat futile.

Lambdas, streams, and functional-style programming capabilities are Java 8’s headline additions. And there are some other major and minor additions, as well, including default methods and a new Date and Time API.

Java 8 in Action does an excellent job of introducing these new capabilities, and the book offers many short code examples and other illustrations to show how to put the new Java 8 capabilities to work.

Indeed, short (and shorter!) code is one of the hallmarks of Java 8. “In Java 8 you can write more concise code that reads a lot closer to the problem statement,” the writers emphasize. To illustrate that point, they offer a five-line example of verbose Java 7 code and follow it with a one-line Java 8 code example that accomplishes the same thing. Other examples also drive home the coding efficiencies that Java 8 can offer.

Lambdas, also known as anonymous functions, enable you to skip writing method definitions that will only be used once. The authors note that “passing code is currently tedious and verbose in Java [meaning 7 and earlier]. Well, good news! Lambdas fix this problem: they let you pass code in a concise way. Lambdas technically don’t let you do anything you couldn’t do prior to Java 8. But you no longer have to write clumsy code using anonymous classes to benefit from behavior parameterization!”

The new Streams API makes it much easier to work with collections in Java and provides “a much different way to process data in comparison to the Collections API.” Using the Streams API, “you don’t need to think in terms of loops at all. The data processing happens internally inside the library.”

Meanwhile, if you are a diehard object-oriented programmer, you may be leery of the term “functional programming” and the notion of using functions as values. (“In practice, you can’t completely program in pure functional style in Java,” the authors note. Instead, you will learn how to write “functional-style programs” in which you hide the side effects.)

With Java 8, “two core ideas from functional programming…are now part of Java: using methods and lambdas as first-class values, and the idea that calls to functions or methods can be efficiently and safely executed in parallel in the absence of mutable shared state. Both of these ideas are exploited by the new Streams API,” the writers state.  Also, in Java 8, they add, “there’s an Optional class that, if used consistently can help you avoid NullPointer exceptions.”

This review barely dents the surface of this excellent how-to book’s contents. Whether you are learning Java now or you are a Java developer who wants to keep your coding skills up-to-date and sharp, Java 8 in Action should be a book you will read soon.

Si Dunn

Grails in Action, 2nd Edition – A (mostly) winning how-to guide to use with a winning web app framework – #programming #bookreview

 

Grails in Action, Second Edition

Glen Smith and Peter Ledbrook

(Manning – paperback)

Grails finishes at or very near the top in almost any smackdown of full-stack web application frameworks that run on the Java Virtual Machine (JVM). And this recently updated Grails in Action how-to book is mostly a clear winner, too.

According to the Grails.org website, open-source Grails “takes advantage of the Groovy programming language and convention over configuration to provide a productive and streamlined development experience.”

Grails likewise is a world that “moves very quickly,” the authors of Grails in Action, Second Edition emphasize. “There have been substantial changes in Grails in the time it took us to develop Grails in Action, Second Edition. Even moving from Grails 2.2 to 2.3 caused us to make significant changes! Although the book targets Grails 2.3, a new version of Grails (2.4) is already available. Fortunately, everything in here is still valid for the new version.”

In the first chapter, the authors try to move very quickly through the process of getting a Grails application up, running, tested and deployed. But in taking this “Grails in a hurry” approach, they race a bit too quickly and unclearly through the installation instructions, in my opinion. (My Linux and Windows installations did not work correctly at first, and I had to seek out  information on how to sort them out.)

And, in the portion of the chapter where you are told how to get the random-quote database set up and working, it is not always clear which file you are supposed to modify and in which subdirectory. I already had a little bit of experience with Groovy, so that portion went smoothly. But the Grails database steps could have been explained and illustrated more clearly. It took me several tries to finally get the “Quote of the Day” database working and posting random quotes.

The authors take a four-part approach to explaining Grails and its underlying Groovy programming language:

  • Part 1: Introducing Grails – You are shown how to get a nicely formatted Quote of the Day (QOTD) application up and running, while also learning how to work with Groovy.
  • Part 2: Core Grails – You get a “more thorough exploration of the three core parts of the Grails ecosystem: models,
    controllers, and views.” Includes such topics as: domain modeling; query mechanisms; how to query a database in Grails without using SQL; Grails’ web-oriented features; Grails Service objects; Grails’ tags for user interface construction; and Grails support for Ajax.
  • Part 3: Everyday Grails – The focus here is on “building all the necessary pieces of a real-world application.” The chapters cover tests, plug-ins, security in Grails and working with RESTful APIs. The chapters also cover (1) Grails single-page web apps using the Angular.js framework, and (2) Spring integration in Grails.
  • Part 4: Advanced Grails – These chapters zero in on “performance tuning, legacy integration, database transactions, custom build processes, and even how to develop and publish your own plugins.”

Aside from a few small omissions of how-to information, I am happy to have the wide-ranging contents of this book. And I am certainly pleased with what I can now do with Grails and Groovy, after reading Grails in Action, Second Edition.

 —Si Dunn

 

 

Play for Java – Good intro to the Play 2 Java web framework – #programming #bookreview

Play for Java

Nicolas Leroux and Sietse de Kaper

(Manning, paperback)

 

“There are,” co-author Nicolas Leroux writes, ” many Java web frameworks, but most of them have a key flaw: they try to hide the web behind an abstraction layer, rather than embracing it. That is the most important difference between Play and most other Java web frameworks (Servlets, we’re looking at you!).”

His writing partner, Sietse de Kaper,  adds: “Play ‘gets it.’ For ‘it,’ in this case, a lot of things can be substituted. Play ‘gets’ HTTP and the web in general, how developing web application works, what makes a nice and clean API, and more. This was clear from the early Play 1 beta versions, and that’s why we’ve used it on many projects since 1.0 came out. It didn’t disappoint. Now, with Play 2, Play continues to improve web development for the Java platform.”

Their new book from Manning is nicely written, adequately illustrated and structured properly to help newcomers get started with Play and with basic web application development. Play for Java also can help experienced web app developers quickly get up to speed quickly with this powerful development platform.

You start by creating and modifying the ubiquitous “Hello world!” application. Then you spend the remaining chapters developing, expanding and enhancing a warehouse management application, one designed to meet specific requirements within a made-up company. “Enterprise applications usually live inside the IT department and are usually hosted within the organization,” Leroux and de Kaper explain. Indeed, businesses may have several or many enterprise applications serving specific purposes, and those apps often do not communicate with each other.

As both writers note: “Web developers are used to interacting with their applications through the browser. With Play, you can also use the console to interact with your web application’s development environment and build system. This is important for both quick experiments and automating things.”

The web app framework Play is, indeed, fun to play with–and work with. For example, it is very good at showing you exactly (ona browser screen) where you have made a keystroke mistake or other blunder in your code. And the words  “Compilation error” on the screen display can’t be missed. Indeed, they can be read from across a room. (Fortunately, in my office, so no one sees them but me.)

If you decide to download Play and give it a try, be sure you (1) have Java installed correctly and (2) know how to set PATHs correctly on your Windows, Linux, or Mac machine. (I had a lingering Java glitch in one of my machines, and I nearly flung a Windows 7 PC into a wall in frustration. But I finally found the problem and fixed it, and Play immediately popped to life as shown in the book. Meanwhile, Play installed smoothly on a Windows 8.1 machine and an ex-XP PC now running Ubuntu.) 

The authors show how to use Play with three IDEs: Eclipse, NetBeans and IntelliJ. Or, if you prefer, you can stick with the Play console and a text editor such as Notepad++ (my current favorite). And they repeatedly emphasize that (1) you should not worry that their Java framework called Play actually is written in Scala and (2) you will encounter some bits of Scala while working with template files.

“Any template language has structures you need to know to build your templates, and Scala templates are no different,” they explain. “Once you know what you have to do to, for example, iterate over a collection or insert a variable value somewhere, you know all you have to know to use that feature. You don’t have to think of it as Scala if you don’t want to. Think of it as another template language.” (Actually, Scala is not scary at all once you’ve spent a little time with it or taken an online class.)

Play supports the optional use of some compiled assets, and “[o]ut of the box, Play 2 comes with support for LESS, CoffeeScript, and Google’s Closure compiler,” the co-authors note.

According to Playframework.org, Play is built on Akka and offers “a lightweight, stateless, web-friendly architecture.” It also offers built-in testing tools and speedy “hit refresh” workflow capabilities.

Whether you are an experienced web app developer, a newcomer, a student or a hobbyist programmer, it can be serious fun to work with–or play with–Play. And Nicolas Leroux’s and Sietse de Kaper’s Play for Java can be exactly the well-tuned guide you need to learn Play 2.

 — Si Dunn

 

 

 

 

 

 

Making Java Groovy – An excellent how-to guide for Java developers – #programming #bookreview

Making Java Groovy

Kenneth A. Kousen
(Manning, paperback)

I have looked at a lot of programming how-to texts in recent years, and this is one of the best I have encountered. Kenneth A. Kousen does not try to get readers to abandon aging and bloated Java in favor of a language that’s sleeker, shinier and newer. Instead, he seeks to show us how to use Groovy’s features and capabilities to help simplify Java, to make working with it easier, more efficient and–yes, even a bit more enjoyable. Indeed, Kousen proposes that we should gradually blend more and more Groovy into our Java code. Hence the title, Making Java Groovy.

(By the way, I lived through the hippie Sixties and remember how weary many of us grew of endlessly hearing the happy word “groovy”–as in “It’s groovy, man, groovy! Everything’s groovy!” I can say honestly that I resisted looking at Groovy, the programming language, for a long time, primarily because of that long-ago, wince-inspiring memory.)

Groovy is an object-oriented programming language that works on the Java platform, and it is intended to complement Java, not replace it. As Guillaume Laforge, the Groovy program manager, explains in his foreword to Kousen’s book: “The idea [behind Groovy] was to empower users to be more productive by removing the boilerplate of Java, and to simplify their programming lives by giving them compelling and straightforward APIs [application programming interfaces] to work with.”

Ken Kousen emphasizes that, among other things, Groovy “adds new capabilities to existing Java classes.” It uses Java libraries. And it makes it easier to work with XML and JSON. Kousen adds that “the Groovy version of a Java class is almost always simpler and cleaner. Groovy is far less verbose and generally easier to read.”

His book has ten chapters and two appendices and is structured into three parts. The first part, titled “Up to Speed with Groovy,” focuses on some long-time Java problems that Groovy addresses and simplifies, and it presents some ways you can use Groovy’s features in Java. The obligatory “Hello, World!” example is presented, but Kousen’s code accesses Google Chart Tools and generates a cool (okay, a groovy) “Hello, World!” 3D pie chart, to which you can add new slices and labels. (But, yes, you do first get the bland and obligatory Groovy shell command-line groovy:000>println ‘Hello, World!’ to verify that your Groovy installation works. Then you get to create the pie chart.)

Kousen is an independent consultant and technical trainer who specializes “in all areas related to Java.” He presents several Java code examples and shows how much shorter they can be made by integrating some Groovy into the mix. “Java historically hasn’t played well with others [other programming languages],” he cautions. But he demonstrates how Java and Groovy can be integrated smoothly to solve some nagging Java irritations and shortcomings.

The book’s second section highlights “Groovy Tools” and emphasizes build processes and testing, “two of the major ways Groovy is often introduced into an organization….”

The third section, “Groovy in the Real World,” describes “the sorts of challenges Java developers face on a regular basis” and how Groovy can help overcome them. The author starts with the Spring framework, “probably the most commonly used open source project in the Java world” and illustrates how “Spring and Groovy are old friends and work together beautifully.”  He also examines: (1) how Groovy interacts with persistent storage; (2) REST-ful web services, “with an emphasis on the JAX-RS 2.0 specification”; and (3) using Groovy in web application development.

The book’s instructions for downloading and installing Groovy are positioned near the back in Appendix A. and seem a bit sparse. But this is okay, since Making Java Groovy is not intended for programming beginners. And I can confirm that writers really don’t like to have to pause a well-written introduction long enough to explain how to download and install the right software for several operating systems.

Following Kousen’s instructions, I installed Groovy fairly easily on a Windows 7 PC, using a Windows EXE installer. He also mentions (too briefly) the Eclipse Marketplace. Since I have Eclipse (with Java and Scala) installed on a Linux machine, I used the Marketplace to get the Groovy and Grails plug-in, too. (My wife did not want Groovy anywhere on her precious Mac, so I did not test that installation.)

“Groovy generates Java bytecodes that are interpreted by a Java virtual machine,” Kousen states. “This means you have to have Java installed to install Groovy.”  Note also: “You need a full Java Development Kit (JDK) rather than a Java Runtime Environment (JRE).” And the Standard Edition (SE) is fine.

Appendix B, “Groovy by Feature,” expands upon Chapter 2’s “Groovy by Example,” and this one seems to be oddly placed. “While some people learn best through short, simple code examples illustrating each concept,” Kousen explains, “others prefer to see basic concepts combined to solve actual problems.” Appendix B “walks through most of the major features of Groovy and provides short snippets of code illustrating them.”

I would be happier if Appendix B had been positioned as Chapter 3, instead. Many people can learn both by feature and by example. And there should be nothing wrong with using one approach to reinforce the other.

But this is minor nitpicking. Making Java Groovy is an excellent how-to guide that I predict will go a long way to help popularize Groovy programming–even among us old guys who still shudder at the verbal excesses of our youth, when we proclaimed “everything” was “groovy.”

Si Dunn

Programming Groovy 2 – For the experienced Java developer seeking dynamic productivity – #programming #bookreview

Programming Groovy 2

Dynamic Productivity for the Java Developer

Venkat Subramaniam
(Pragmatic Bookshelf, paperback)


The programming language
Groovy has a bit of a checkered past. Before it reached Release 1 in early 2007, it was almost abandoned because of a series of development problems. But some dedicated developers reworked it, gave it new life, and helped it gain acceptance in a widening array of commercial projects. Release 2.0 became available last year, and you can download 2.1, with 2.2 in beta. Groovy is doing groovy now, thank you very much (and thank the Grails web application framework, too).

In his new book, which keys off of his 2008 Groovy 1 edition, Dr. Venkat Subramaniam  describes Groovy 2 as “lightweight, low-ceremony, dynamic, object-oriented, and runs on the JVM [the Java Virtual Machine].”

He notes: “Groovy is open sourced under the Apache License, version 2.0. It derives strength from various languages such as Smalltalk, Python, and Ruby, while retaining a syntax familiar to Java programmers. Groovy compiles into Java bytecode and extends the Java API and libraries. It runs on Java 1.5 and newer. For deployment, all we need is a Groovy Java archive (JAR) in addition to the regular Java stuff, and we’re all set.”

Groovy is not for coding beginners, nor is it a means to avoid learning Java. This book–well written and nicely illustrated with short code examples and screenshots–”is aimed at Java programmers who already know the JDK [Java Development Kit] well but are interested in learning the Groovy language and its dynamic capabilities,” Dr. Subramaniam says.

He has organized his 19-chapter, 333-page book into three major parts:

Part I: Beginning Groovy – Focuses on the fundamentals of the language but deliberately skips the basics of programming. The book, after all, is aimed at “experienced Java programmers.”

Part II: Using Groovy – Shows “how to use Groovy for everyday coding–working with XML, accessing databases, and working with multiple Java/Groovy classes and scripts….” Also delves into Groovy extensions and additions to the JDK.

Part III: “MOPping Groovy” – The odd title may conjure up a brief image of mopping up spilled gravy. But this part deals with “Groovy’s metaprogramming capabilities….” The coverage includes: (1) metaobject protocol (MOP); (2) “how to do AOP-like operations in Groovy” [AOP = “aspect-oriented programming”]; and (3) “dynamic method/property discovery and dispatching,” as well as Groovy’s “compile-time metaprogramming capability….”

If you are a Java developer seeking new tools. new challenges, and new horizons, this could be the right time and right way to get your groove on: with Groovy 2 and Dr. Venkat Subramaniam’s fine how-to guide.

“Groovy is an attractive language for a number of reasons,” the author says, naming four key ones:

“It has a flat learning curve.”

“It follows Java semantics.”

“It bestows dynamic love.”

“It extends the JDK.”

“Groovy,” he adds, “feels like the Java language we already know, with a few augmentations.”

Si Dunn