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

OpenGL ES 2 for Android – A fine quick-start guide for new developers – #android #programming #bookreview

OpenGL ES 2 for Android

A Quick-Start Guide
Kevin Brothaler
(Pragmatic Bookshelf - paperback)

Yes, the timing might seem a bit strange, releasing an OpenGL ES 2 book in early July, 2013, barely a month before the August release of OpenGL ES 3.

However, OpenGL ES 3 is backward-compatible with OpenGL ES 2. And the steps and techniques you can learn in this Open GL ES 2 book for Android are forward-compatible to OpenGL ES 3. Many also are applicable to iOS WebGL or HTML5 WebGL.

This “quick-start guide” assumes you have some experience with Java and Android, and it quickly jumps into creating OpenGL applications for Android. You install software tools such as the Java Development Kit (JDK) and the Android Software Development Kit and create a simple test project. Then you dive into developing and enhancing a 3D game project —  “a simple game of air hockey” — for the remainder of the book.

OpenGL ES 2 for Android is nicely illustrated, well-written, and cleanly organized with short paragraphs and short code examples that clearly have been tested. It is a fine quick-start guide, particularly for developers looking into OpenGL for the first time.

Some math skills are required to develop the air hockey game. But the author does a nice job of explaining and illustrating the math examples, as well.

Kevin Brothaler has extensive experience in Android development. He founded Digipom, a mobile software development shop, and he manages an online set of OpenGL tutorials for Android and WebGL: Learn OpenGL ES.

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

The Healthy Programmer – Better coding through better living – #programming #bookreview

The Healthy Programmer

Get Fit, Feel Better, and Keep Coding

Joe Kutner

(Pragmatic Bookshelf – paperback)

Yes, you know it is unhealthy to spend all day and much of the night hunched at keyboard, staring at a computer screen, gripping a mouse and nervously clawing at bags of vending-machine snacks because you haven’t had time to eat proper meals.

Yet that is exactly how many of us earn a living: spending long hours writing code, fixing code, or writing about the processes of writing and fixing code.

The work of a programmer can be devilishly complex and tiring. Often, it can be highly stressful, too. And, it can, over the long run, damage your health or even help shorten your life, if you aren’t careful.

Joe Kutner’s The Healthy Programmer takes a pragmatic and low-key approach to showing you how you can start improving the conditions of your body and brain without disrupting your job. His tips, tricks, and “best practices” are backed up by advice and commentary from doctors, therapists, nutritionists, scientists, and fitness experts.

“Having a system or a process is crucial to getting things done,” Kutner says. “In software, we often use an agile method to guide our development efforts. Agile processes are characterized by an iterative and incremental approach to development, which allows us to adapt to changing requirements. The method you use to stay healthy shouldn’t be any different.”

In his book, he shows “how to define a system of time-boxed iterations that will improve your health. We’ll start with two-week intervals, but like with any agile method, you’ll be allowed to change that as needed. At the end of each iteration you’ll do a retrospective to assess your progress.”

Crucially, Kutner’s approach is to start small, by changing one habit, and start gently, by doing some walking. “You won’t be bombarded with exercises and activities right away,” he emphasizes. “Instead, we’ll spend the first few chapters introducing some very simple, but essential, components of a healthy lifestyle. Don’t think that they are too simple, though. These are the activities that will have the biggest effect on your life.”

Kutner’s well-researched, well-written book takes a whole-body approach, with a keen understanding how programmers work.  He has been one for more than a decade and has spent much of that time researching the physical hazards of sedentary coding.

Chair exercises, standing desks, wrist braces, eye-care tips, and dietary recommendations are some of the areas covered. A “Pomodoro break,” for example, can help people involved in many different types of creative work, including programming. The basic approach involves working on a single task for a specific amount of time, such as 60 minutes, with short periods of exercise interspersed.

You might set a timer for 25 minutes, then focus on debugging some code. When the timer goes off, you reset it for five minutes and take a short walk. Then spend another 25 minutes doing a code review. When the timer goes off again, get up from your desk and do some exercises for five minutes. Then start a new task (or continue a previous problem) and repeat the cycle.

You may already have a daily exercise routine.  But Kutner warns that it “can interfere with your job [as a coder] if you don’t coordinate the two activities. If you do coordinate them, you may actually improve your ability to write code. That’s because immediately after exercise, blood shifts rapidly back to the brain, which makes it the perfect time to focus on tasks that require complex analysis and creativity.”

The Healthy Programmer has many good tips for avoiding or minimizing back pain, wrist pain, headaches and other irritants, as well good techniques for “upgrading your hardware,” meaning your body. Numerous easy-to-perform exercises are described and illustrated, including some you can do while seated or standing at your workstation. “[Y]our lifestyle can enhance your ability to do your job well,” Kutner emphasizes. “That’s why staying healthy is the best way to ensure you keep doing this job you love for years to come.”

Si Dunn

Realm of Racket: Learn to Program, One Game at a Time – #Racket #game #programming #bookreview

Realm of Racket
Learn to Program, One Game at a Time!

Matthias Felleisen, David Van Horn, Conrad Barski, M.D., Forrest Bice, Rose DeMaio, Spencer Florence, Feng-Yun Mimi Lin, Scott Lindeman, Nicole Nussbaum, Eric Peterson, and Ryan Plessner
(No Starch Press – paperback, Kindle)

Formerly known as PLT Scheme, Racket is an offshoot of the Lisp/Scheme family of programming languages. (Lisp, which was first specified in 1958, is the second-oldest high-level programming language, behind FORTRAN).

The (numerous) authors of this 294-page book call Racket “a friendly mutation of Lisp” and tout it as “perfect for all, from those who want to launch their education in computer science to those looking to expand their knowledge and experience in programming.”

Lisp has a long learning curve, so the writers have taken special pains to try to make Racket (“a weird-looking programming language,” they concede) approachable and fun by using comics and games built from short code examples.

Their well-written book is aimed at college freshmen readers. But they emphasize “that doesn’t mean you should drop this book if you are a sophomore or an industry professional.” Nor if you are still in high school or simply like to tinker with programming languages for fun and challenge.

“Regardless of your programming background,” they state, “many of the topics in this book will be new to you, and much of what you’ve learned before will appear in a new light.”

Realm of Racket is structured so that you start out programming very simple games and gradually tackle games that are more complex, while learning about such topics as functions, recursion, lambda, lists, structures, loops, testing, and more.

If you are interested in developing special-purpose computer languages that require specific knowledge of specialized fields, Realm of Racket’s  final chapter briefly delves into the field of language engineering. It notes that Racket “makes it particularly easy to create new programming languages, including special-purpose languages.”

Not surprisingly, some people who program in Racket call themselves Racketeers. The open source language and its program development environment (PDE), DrRacket (“Doctor Racket”), can be downloaded from http://racket-lang.org. “Racket can run on Windows, Mac, and *nix* systems,” the authors note.

Realm of Racket can be a fun, challenging book for computer-savvy teens nearing the end of high school or in their first years of college to study computer science or gaming. Younger readers likely won’t stick with it unless they have some helpful, patient guidance from knowledgeable older siblings or adults. Wait until they’ve gotten reasonably good at another language, such as Python, Ruby, C#, or Java, first.

Si Dunn

Hands-on Testing with PHPUnit How-to – A short, well-focused guide – #programming #bookreview

Instant Hands-on Testing with PHPUnit How-to
A practical guide to getting started with PHPUnit to improve code quality
Michael Lively
(Packt Publishing – paperback, Kindle)

PHPUnit is considered by many to be the leading tool for testing PHP code. This “Short, Fast, Focused” book (82 pages digital, 69 pages in paperback) is a recent addition to Packt Publishing’s “Instant” series. It zeroes in on how to install and use PHPUnit to create and run “easy-to-maintain tests.”

One strength of Michael Lively’s new book is his experience with PHP and PHPUnit. Another strength is the book’s step-by-step structure. It rates each key step as “Simple”, “Intermediate”, or “Advanced” and provides subheadings such as “Getting ready…”, “How to do it…”, “How it works…”, and “There’s more…” to help keep descriptions short and clear.

Code examples and screenshots also help the reader get comfortable with running tests using the PHPUnit framework.

Aside from skipping commas in some of the text, Michael Lively’s writing is clear and concise, and his descriptions and code examples have been reviewed by two experienced software developers.

The book is “written for anyone who has an interest in unit testing but doesn’t necessarily know where to start in integrating it with their project,” Lively states.

“It will provide useful tips and insights into how PHPUnit can be used with your projects and it should give you enough information to whet your appetite for the various features offered by PHPUnit.”

The code examples in Lively’s book “were written using PHP 5.3.24 and PHPUnit 3.7. All code samples were verified against a Linux box with Ubuntu 12.04 LTS.”

As with several other Packt books recently reviewed, if you use a Windows PC or a Mac instead of a Linux system, you pretty much are left on your own to figure out the installation process and certain commands.

–   Si Dunn

Functional JavaScript – Applying functional techniques and Underscore.js – #programming #bookreview

Functional JavaScript
Introducing Functional Programming with Underscore.js
Michael Fogus
(O’Reilly – paperback, Kindle)

When I first started tinkering with JavaScript, object-oriented programming (OOP) was the rage, and JavaScript frequently was touted as one of the key object-oriented languages. After all, according to many online descriptions, almost everything within JavaScript “is OO.”

Now, in this enjoyable new book, JavaScript is hailed as a functional programming language. Of course, functional programming recently has been the rage in many programming circles. And “enjoyable” may seem an odd word to attach to a software text. Yet, it fits. Michael Fogus shows here that he is a technical writer who can be entertaining, effective and well-organized.

“This book,” he states, “is not about spewing dogma regarding the virtues of functional programming. I think there are many functional techniques that offer ways to rein in the complexities of software development, but I realize that at times, there are better ways to implement any given individual part.”

It is possible, of course, to debate object-oriented vs. functional JavaScript until the digital cows are called back home and put into infinite loops. But, for those who don’t know or care much about the differences, here are some basic views.

The Mozilla Developers Network (to simply pick  one example) discusses objected-oriented JavaScript on its site and declares: “Object-oriented programming may be seen as the design of software using a collection of cooperating objects, as opposed to a traditional view in which a program may be seen as a collection of functions, or simply as a list of instructions to the computer. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects. Each object can be viewed as an independent little machine with a distinct role or responsibility.”

Meanwhile, HaskellWiki offers this explanation of functional programming: “In functional programming, programs are executed by evaluating expressions, in contrast with imperative programming where programs are composed of statements which change global state when executed. Functional programming typically avoids using mutable state.

“Functional programming requires that functions are first-class, which means that they are treated like any other values and can be passed as arguments to other functions or be returned as a result of a function. Being first-class also means that it is possible to define and manipulate functions from within other functions.”

Some of the programming languages typically labeled “functional” include Clojure, OCaml, Erlang,  Haskell, Scala, and F#.

Here is how Michael Fogus defines functional programming:

“As a bare-bones introduction, functional programming can be described in a single sentence:

Functional programming is the use of functions that transform values into units of
abstraction, subsequently used to build software systems.

“This is a simplification bordering on libel,” he continues, “but it’s functional (ha!) for this early stage in the book. The library that I use as my medium of functional expression in JavaScript is Underscore, and for the most part, it adheres to this basic definition.”

(Underscore.js can be obtained from http://underscorejs.org and imported into “the applicable project directories.”)

Fogus refuses, in his text, “to create a false dichotomy and say that functional and object-oriented styles should stand in opposition.” Indeed, he notes that JavaScript supports both models and “systems can and should be composed of both models.”

He also points out that JavaScript can be used with other paradigms, including imperative programming, prototype-based object-oriented programming, and metaprogramming.

“In no way does this book represent even a modicum of original thinking regarding functional programming in JavaScript,” he states. Yet, it is a worthy effort.

It is well written, smoothly organized, and nicely illustrated with short code examples and helpful diagrams. And Fogus notes that JavaScript does have “[l]anguage oddities, unsafe features, and a sea of competing libraries” that raise concerns when it is selected for a project. Functional programming, he contends, can be one way to help ensure that JavaScript “can be not only safe, but also simple to understand and test, in addition to being proportionally scalable to the size of the code base.”

Here is the chapter lineup for Fogus’s 237-page book:

  • Chapter 1. Introducing Functional JavaScript
  • Chapter 2. First-Class Functions and Applicative Programming
  • Chapter 3. Variable Scope and Closures
  • Chapter 4. Higher-Order Functions
  • Chapter 5. Function-Building Functions
  • Chapter 6. Recursion
  • Chapter 7. Purity, Immutability, and Policies for Change
  • Chapter 8. Flow-Based Programming
  • Chapter 9. Programming without Class

Functional JavaScript is a winner on at least two counts: (1) as a how-to text for long-time JavaScript programmers wishing to learn more about functional programming; and (2) as a how-to text for long-time functional programmers desiring to learn more about JavaScript.

The book is not recommended for JavaScript newcomers who are still at the level of typing console.log(“The answer to everything in the universe is 42″). However, experienced beginners can learn from it, and so can those of us who just tinker with JavaScript periodically and use it mainly to work with Node.js, Backbone.js, Ember.js, CoffeeScript, HTML and other choices.

Si Dunn

Python Cookbook, 3rd Edition – Breaking Away from Python 2 to Python 3 – #programming #bookreview

Python Cookbook, 3rd Edition
David Beazley & Brian K. Jones
(O’Reilly - paperback, Kindle)

PYTHON 3 users will be very pleased with this new book. Those who still cling to Python 2 likely will not.

Even though “most working Python programmers continue to use Python 2 in production,” its authors concede, and “Python 3 is not backward compatible with past versions,” this third edition of the popular Python Cookbook is intended to be used only with Python 3.3 and above.

“Just as Python 3 is about the future, this edition…represents a major change over past editions,” Beazley and Jones state. “First and foremost, this is meant to be a very forward looking book. All of the recipes have been written and tested with Python 3.3 without regard to past Python versions or the ‘old way’ of doing things. In fact, many of the recipes will only work with Python 3.3 and above.”

THEIR “ultimate goal,” they point out, was “to write a book of recipes based on the most modern tools and idioms possible. It is hoped that the recipes can serve as a guide for people writing new code in Python 3 or those who hope to modernize existing code.”

The 687-page Python Cookbook, 3rd Edition is not intended for beginning programmers. However, beginners can learn a few things from it and keep the book on their shelves for future use as they gain experience with Python 3.

And, it can be a helpful guide if you are working to update some Python 2 code to Python 3. According to the authors, “many of the recipes aim to illustrate features that are new to Python 3 and more likely to be unknown to even experienced programmers using older versions.”

THE book offers 15 chapters of how-to recipes organized into the following major categories:

  1. Data Structures and Algorithms
  2. Strings and Text
  3. Numbers, Dates, and Times
  4. Iterators and Generators
  5. Files and I/O
  6. Data Encoding and Processing
  7. Functions
  8. Classes and Objects
  9. Metaprogramming
  10. Modules and Packages
  11. Network and Web Programming
  12. Concurrency
  13. Utility Scripting and Administration
  14. Testing, Debugging, and Exceptions
  15. C Extensions

Each of the approximately 260 recipes is presented using a “problem-solution-discussion” format. Here are a few recipe titles chosen at random:

  • “Combining and Concatenating Strings”
  • “Reformatting Text to a Fixed Number of Columns”
  • “Bypassing Filename Encoding”
  • “Iterating over the Index-Value Pairs of a Sequence”
  • “Capturing Variables in Anonymous Functions”
  • “Implementing Stateful Objects or State Machines”
  • “Enforcing an Argument Signature on *args and **kwargs”
  • “Creating Custom Exceptions”
  • “Writing a Simple C Extension Module”

SOME of the book’s code examples are complete. But others, the authors caution, “are often just skeletons that provide essential information for getting started, but which require the reader to do more research to fill in the details.”

If you are serious about Python and keeping pace with its progress, you should seriously consider getting this excellent how-to book.

Si Dunn

Creating Mobile Apps with jQuery Mobile – A good & wide-ranging how-to guide – #programming #bookreview

Creating Mobile Appls with jQuery Mobile
Shane Gliser
(Packt Publishing – paperback, Kindle)

The long tagline on the cover of Shane Gliser’s new book deftly sums up its contents:  “Learn to make practical, unique, real-world sites that span a variety of industries and technologies with the world’s most popular mobile development library.”

Gliser unabashedly describes himself as a jQuery “fanboy…if it’s officially jQuery, I love it.” He is an experienced mobile developer and blogger who operates Roughly Brilliant Digital Studios. He also has some background in mobile UX (user experience).

Both aspects of that background serve him well in his smoothly written, nicely illustrated how-to book that zeroes in on jQuery Mobile, a  “touch-optimized” web framework for smartphones and tablets.

You may be surprised when you extract the 234-page book’s code examples and related items and find that the ZIP file is almost 100MB in size. Gliser covers a lot of ground in his 10 chapters. And each chapter contains a project.

Still, what you don’t do in the first chapter, “Prototyping jQuery Mobile,” is work at a computer. In the true spirit of UX, Gliser has you start first with a pen and some 3×5 note cards. Your goal is to rough out some designs for a jQuery Mobile website for a new pizzeria.

Why the ancient technology? “We are more willing to simply throw out a drawing that took less than 30 seconds to create,” Gliser writes. Otherwise, it’s too easy to stay locked into one design while trying different ways to make its code work. And: “Actually sketching by hand uses a different part of the brain and unlocks our creative centers.”

Best of all, working first with paper sketches enables team members who are not coders to contribute some comments, suggestions, and corrections for the emerging design.

In Chapter 2, “A Mom-and-Pop Mobile Website,” you step over to your computer with the paper prototype in hand and start converting the final design “into an actual jQuery Mobile (jQM) site that acts responsively and looks unique.” You also begin building “a configurable server-side PHP template,” and you work with custom fonts, page curl effects using CSS, and other aspects of creating and optimizing a mobile site.

“Mobile is a very unforgiving environment,” Gliser cautions, “and some of the tips in this section will make more difference than any of the ‘best coding practices.’” Indeed,  he wants you to be aware of optimization “at the beginning. You are going to do some awesome work and I don’t want you or your stakeholders to think it’s any less awesome, or slow, or anything else because you didn’t know the tricks to squeeze the most performance out of your systems. It’s never too early to impress people with the performance of your creations.”

Chapter 3, “Analytics, Long forms, and Front-end Validation,” moves beyond “dynamically link[ing] directly into the native GPS systems of iOS and Android.” Instead, Gliser introduces how to work with Google static maps, Google Analytics, long and multi-page forms, and jQuery Validate. As for static maps, he says, “Remember to always approach things from the user’s perspective. It’s not always about doing the coolest thing we can.” Indeed, a static map may be all the user needs to decide whether to drive to a business, such as a pizzeria, or just call for delivery. And, as for Google Analytics: “Every website should have analytics. If not, it’s difficult to say how many people are hitting your site, if we’re getting people through our conversion funnels, or what pages are causing people to leave our site.”

Meanwhile, desktop users are familiar with (and frequently irritated by) long forms and multi-page forms. Lengthy forms can be real deal-breakers for users trying to negotiate them on mobile devices. The author presents some ways to shorten long forms and break them “into several pages using jQuery Mobile.” And he emphasizes the importance of using the jQuery Validate plug-in to add validation to any page that has a form, so the user can see quickly and clearly that an entry has a problem.

The focus in Chapter 4, “QR Codes, Geolocation, Google Maps API, and HTML5 Video,” is on handling concepts that can be “applied to any business that has multiple physical locations.” Gliser uses a local movie theater chain as his development example. A site is created that makes use of QR codes, geolocation, Google Maps, and linking to YouTube movie previews. Then, he shows how to use embedded video to keep users on the movie chain’s site rather than sending them off to YouTube.

In Chapter 5, the goal is “to create an aggregating news site based off social media.” So the emphasis shifts to “Client-side Templating, JSON APIs, and HTML5 Web Storage.” Notes Gliser: “Honestly, from a purely pragmatic perspective, I believe that the template is the perfect place for code. The more flexible, the better. JSON holds the data and the templates are used to transform it. To draw a parallel, XML is the data format and XSL templates are used to transform. Nobody whines about logic in XSL; so I don’t see why it should be a problem in JS templates.”

Next, he shows how to patch into Twitter’s JSON API to get “the very latest set of trending topics” and “whittle down the response to only the part we want…and pass that array into JsRender for…well…rendering” in a manner that will be “a lot cleaner to read and maintain” than looping through JSON and using string concatenation to make the output.

Other topics in Chapter 5 include programmatically changing pages in jQuery Mobile, understanding how jQuery Mobile handles generated pages and Document Object Model (DOM) weight management, and working with RSS feeds. Gliser points out that there is still “a lot more information out there being fed by RSS feeds than by JSON feeds.” The chapter concludes with looks at how to use HTML5 web storage (it’s simple, yet it can get “especially tricky on mobile browsers”), and how to leverage the Google Feed API. Says Gliser: “The Google Feeds [sic] API can be fed several options, but at its core, it’s a way to specify an RSS or ATOM feed and get back a JSON representation.”

Chapter 6 jumps into “the music scene. We’re going to take the jQuery Mobile interface and turn it into a media player, artist showcase, and information hub that can be saved to people’s home screens,” Gliser writes. He proceeds to show how “ridiculously simple it can be to bring audio into your jQuery Mobile pages.” And he explains how to use HTML5 manifest “and a few other meta tags” to save an app to the home screen. Furthermore, he discusses how to test mobile sites using “Google Chrome (since its WebKit) or IE9 (for the Windows Phone)” as browsers that are shrunken down to mobile size. “Naturally, this does not substitute for real testing,” he cautions. “Always check your creations on real devices. That being said, the shrunken browser approach will usually get you 97.5 percent of the way there. Well…HTML5 Audio throws that operating model right out the window.”

Since “mobile phones are quickly becoming our photo albums,” Gliser’s Chapter 7, “Fully Responsive Photography,” shows first how to create a basic gallery using Photoswipe. Then, in a section focused on “supporting the full range of device sizes,” he explains how to start using responsive web design (RWD), “the concept of making a single page work for every device size.” The issues, of course, range from image sizes and resolutions to text sizes and character counts per line, on screens as small as smart phones and tablets, or larger.

In Chapter 8, “Integrating jQuery Mobile into Existing Sites,” three topics are key: (1) “Detecting mobile – server-side, client-side, and the combination of the two”; (2) “Mobilizing full site pages – the hard way”; and (3) Mobilizing full site pages – the easy way.” Gliser avoids some potential “geek war” controversies over “browser sniffing versus feature detection” when detecting mobile devices. He zeroes in first on detection using WURFL for “server-side database-driven browser sniffing.” He also shows how to do JavaScript-based browser sniffing, which he concedes may be “the worst possible way to detect mobile but it does have its virtues,” especially if your budget is small and you want to exclude older devices that can’t handle some new JavaScript templating. He also describes JavaScript-based feature detection using Modernizer and some other feature-detection methods.

As for mobilizing full-site pages “the hard way,” he states that there is really “only one good reason: to keep the content on the same page so that the user doesn’t have one page for mobile and one page for desktop. When emails and tweets and such are flying around, the user generally doesn’t care if  they’re sending out the mobile view or the desktop view and they shouldn’t.” He focuses on how “it’s pretty easy to tell what parts of a site would translate to mobile” and how to add data attributes to existing tags “to mobilize them. When jQuery’s libraries are not present on the page, these attributes will simply sit there and cause no harm. Then you can use one of our many detection techniques to decide when to throw the jQM libraries in.”

Mobilizing full-size pages “the easy way” involves, in his view, “nothing easier and cleaner than just creating a standalone jQuery Mobile page…and simply import the page we want with AJAX. We can then pull out the parts we want and leave the rest.” His code samples show how to do this.

Chapter 9, “Content Management Systems and jQM” looks at the pros and cons of using three different content management systems (CMS) with jQuery Mobile: WordPress, Drupal, and Adobe Experience Manager. “The key to get up and running quickly with any CMS is, realizing which plugins and themes to use,” Gliser writes.  He also explains how to use mobile theme switchers.

Drupal offers some standard plugins that provide contact forms, CAPTCHA, and custom database tables and forms, and enable you to “create full blown web apps, not just brochureware sites,” he notes. But: “The biggest downside to Drupal is that it has a bit of a learning curve if you want to tap its true power, Also, without some tuning, it can be a little slow and can really bloat your page’s code.” .

As for Adobe Experience Manager (AEM), Gliser merely introduces it as a “premier corporate CMS” and a “major CMS player that comes with complete jQuery Mobile examples.” He doesn’t show “how to install, configure, or code for AEM. That’s a subject for several training manuals the size of this book.”

Chapter 10, the final chapter, is titled “Putting It All Together — Flood.FM.” Using what you’ve learned in the book (including prototyping the interfaces on paper first), you create “a website where listeners will be greeted with music from local, independent bands across several genres and geographic regions.” Along the way, Gliser introduces Balsamiq, “a very popular UX tool for rapid prototyping.” He discusses using Model-View-Controller (MVC), Model-View-ViewModel (MVVM), and Model-View-Whatever (MV*) development structures with jQuery Mobile. He shows how to work with the Web Audio API , and he illustrates how to prompt users to download the Flood.FM app to their home screens. He finishes up with brief discussions of accelerometers, cameras, “APIs on the horizon,” plus “To app or not to app, that is the question” and whether you should compile an app or not. Finally, he shows PhoneGap Build, the “cloud-based build service for PhoneGap.”

Bottom line: Shane Gliser’s book covers a lot of  useful ground for those who are ready to learn jQuery Mobile.

Si Dunn

Arquillian Testing Guide – For better integration testing & functional testing on the JVM – #programming #bookreview

Arquillian Testing Guide
John D. Ament
(Packt Publishing – Paperback, Kindle)

If you have some experience with integration testing and functional testing on a Java virtual machine (JVM), John D. Ament’s important new book can help you get up to speed with the Arquillian testing platform’s numerous features and capabilities.

Arquillian “leverages JUnit and TestNG to execute test cases against a Java container,” Ament explains. The Arquillian framework, he adds, has three major sections: “test runners (JUnit or TestNG), containers (Weld, OpenWebBeans, Tomcat, GlassFish, and so on), and test enrichers (integration of your test case into the container that your code is running in.)” Also: “ShrinkWrap is an external dependency for you to use with Arquillian; they are almost sibling projects. ShrinkWrap helps you define your deployments, and your descriptors to be loaded to the Java container you are testing against.”

Ament’s 224-page book shows how to write simple code for various Java application tests but also explains how to develop rich test cases that you can run automatically.

The author uses the JUnit test container in his examples but explains how you can use the TestNG test container, if you prefer.

While the book is aimed at readers with intermediate experience, newcomers to Java testing can learn from it, too. Before diving into the process of explaining Arquillian, Ament describes “the fundamentals of a test case,” from an Arquillian perspective, of course. And he devotes a chapter to “The Evolution of Testing,” from the early days of manually testing single units to the advent of automated testing with powerful new tools. (Manual testing, by the way, is still important and will not go away soon, Ament indicates. “There is likely no removing manual testing for functional applications,” he writes.

“Manual testing should be considered when performing user acceptance testing, where you need to validate that the application functions the way you would expect end to end. From a quality assurance standpoint, it’s the most direct way to make sure an application works the way expected.” But, he warns, “a developer shouldn’t wait until this point to begin testing….”

He also devotes a chapter to the basics and the process of container testing. “Arquilian is all about testing your code inside a container,” he says. “Containers represent what your application will run on.” His text examines each of the “three primary ways that Arquillian can interact with a container — embedded, managed, and remote.”

Embedded containers, he notes, “typically run on the same JVM as your test case. Next are managed containers, which Arquillian will start up for you during the test process and shut down after the tests are run but run in a different JVM. Finally, there are remote containers, which are assumed to be running prior to the test and will simply have deployments sent and tests executed.”

The book’s remaining chapters take the reader deeper into the testing processes and how to use of Arquillian’s features and extensions.

Arquillian is not software you can learn to use effectively in a single weekend of hacking. You must learn it by using it and using it a lot, Ament emphasizes. “Run as many tests as you can with Arquillian…[y]ou make the best use of Arquillian when you use it throughout 100 percent of your tests.”

Arquillian Testing Guide is available through several sources, including Amazon and Packt Publishing.

Si Dunn