The state of Spring so far…

I-heart-spring-AidenI have never been more excited to be a part of the Spring team as I am now. It feels like we are blazing new trails left and right. Seeing the massive turnout this week for Stephane and Brian’s “Spring Boot University”, a 3-hour session at DevoxxFR, left me awestruck. Wish I could have been there.

Everywhere I turn, people are gobbling up Spring Boot. They tell me, this is what they have been looking for. How did this happen? It’s a really neat history.

A little bit of history

The Spring Framework started lean and mean. It was a fantastic way to integrate critically needed tools through its profound power of dependency injection. Some people criticized this as hype, but the community’s massive adoption proved the vitality of this approach. Coding was fun! Demo apps are one thing, but people were using Spring Framework to build large, complex systems. Complex systems need lots of components. Existing APIs like JMS, JDBC, and other things came with the need for lots of plumbing. These APIs were way too low level. And thus was born JmsTemplate, HibernateTemplate, and my personal favorite: JdbcTemplate.

But that was not all. Building web apps with Spring MVC was hot. It made testing app controllers nice and easy. You weren’t obligate to run web-based acceptance tests through complex controls. Instead, you could isolate things. Nonetheless, as the needs of the community grew, so did Spring. To help different parts of Spring grow and evolve and now slow down the core framework. other projects were formed. Spring Security, Spring Data, Spring Integration, Spring Batch, and more. At one point, people expressed their dislike for “spring.jar” containing everything. The Spring team chopped things up into finer grained JARs so you could grab what you needed. Then we had too many JARs. What?!?

As the power and might of Spring grew, so did its learning curve. People were asking which project to use. How to integrate them together. What version of Spring Integration with the version of Spring Framework I’m using? How do I even start using Spring MVC? What steps do I need to carry out?

Spring Boot is born

platform-spring-bootThus was born Spring Boot. Spring Boot brought forth a series of critical concepts.

  • Pre-pick the versions of Spring and other libraries so you don’t have to
  • Auto-configure boilerplate stuff like Spring MVC, Security, Integration, etc.
  • Remove key beans if you define your own
  • Accelerate Spring’s power of externalization of properties to Warp Factor 9!
  • Add on DevOps-ready metrics

A big hurdle was mixing together different libraries. If I have Spring Framework 4.0.1, what version of Spring Integration should I pick? Simple: pick one version of Spring Boot, and both of those dependencies are pre-picked for you. Boot doesn’t stop there. It extends into lots of key 3rd party libraries. This decision was so popular, that Spring IO was created to reach out and harmonize the versioning of 380+ libraries.

A big issue (especially for me, a non-web guy at the time), was standing up Spring MVC. First, you had to put certain bits into web.xml. Then you needed to stand up view resolvers, message converters, controllers, and a whole cadre of other components. You really needed to understand Spring MVC to do it and to do it right. Spring Boot stepped up to the plate and said, “don’t worry, we’ve got you covered”. Add “spring-webmvc” to your project, and Boot will create all that stuff for you. You just create a controller that returns view names, and you’re up and running.

danielskullNo form of automation can ever cover every circumstance. Sooner or later, developers need to break out of the framework’s default position. And this is where LOTS of tools fail on a massive scale. There are two common outcomes: 1) Don’t permit such customization and hamstring future developers or 2) Add so many extension points that the simple use case vanishes. Spring Boot introduces option 3) Drop bits of auto-configured stuff when you create your own. This is known as backing off, and has moved the bar forward on app and framework development really far. New applications and new frameworks will surely adopt this approach to expansion because it just makes sense. If you build a framework and don’t shoot for this, someone starting after you might catch up and pass you because they will.

Something I’ve needed for years before I wrote Java for my day job was externalization of application properties. I dealt with development, test, and production environments. Rebuilding apps for each target was wasteful. So I hand wrote code for that. Spring Framework has always had powerful support for properties files, but Spring Boot took that feature and accelerated the options. Having APP_ENV and -Dapp.env both map to @Value(“${app.env}”) String appEnv or class ApplicationProperties { public void setAppEnv(String env)… } is sheer genius can cannot be understated. People talk about 12-factor apps and high tech wwizbang manifestos, but this concept is simple to grok and applicable just about everywhere. You could be running a close network solution (which I did at my old job) with no cloud involvement and find this technique the Right Thing To Do.

DevOps-ready controls and metrics is something area always begging for. System administrators, program managers, business analysts, and others are always asking for this extra metadata about our apps. Being able to spit out a first cut of this by simply adding one dependency to an application is phenomenal. Then being able to craft your own metrics and controls with little effort ramps your app up to production ready and Management Friendly by providing them the warm fuzzy metrics for clients without breaking the bank of technical debt.

Where are things now?

With Spring Boot spreading across the Java ecosystem over the past two years, it really is exciting to see how much fun people are having building apps. They focus on the end game, not setting up infrastructure. Hearing chatter like “Using Spring Boot is like pair programming with the Spring team” (@starbuxman) and “Spring Boot is just what we need” is cool. I get excited to go the Nashville JUG and talk about some piece of Spring, not just because it “looks good”, but because I can sincerely point out how using it is simply fun! Isn’t that what real software is supposed to be? Functional, carries business value, and at the same time, fun to build and release? It almost feels like Spring Boot introduces yet another rennaisance to application development.

3021OS_mockupcover_normalI have been quite pleased that my previous book, Python Testing Cookbook has earned double the advance over the past three years (and keeps making me money!) But I jumped out of my chair when the first statement for Learning Spring Boot came in last month and showed that over 400 people had bought a copy. My excitement to write about Spring Boot was paralleled by my instinct that people would want to learn about Boot’s secrets.

There is a lot of action happening in the Spring team as we continue to blaze trails we couldn’t foresee five years ago. Many of our key decisions in the past have put us on a strong  footing to continue pushing the envelope for the future in both application power as well as ease of development. The community experience of putting out new features, getting feedback, and generally building something better each and everyday that helps thousands of people solve problems is both inspiring and humbling. There’s no other place I’d rather be working.

Happy coding!

I’ve never shared this with anyone…

Tonight writing prompt: I’ve never shared this with anyone, until now:

***

Perhaps you’ve noticed that I have a Mac? See the cute apple icon? And my phone. Anyone can tell what that is. But the truth is…I like Windows. The look, the feel of the screens. The flat out power behind it is incredible. My colleagues would think me crazy if they ever found out. They use Mac or Linux mostly. One that used to use Windows moved to Mac years ago. And every night, after my wife goes to sleep, I browse Amazon looking at the Windows phones. It’s true. I’ve never told this to anyone. I trust you can keep this secret. My credibility as a Mac savant would be ruined should anyone get word of this. My brother-in-law would be only one to welcome me with open arms. He might snicker a little. Perhaps tell me he knew all along. Please please please please don’t tell him. Now you know everything about me.

***

This is pure fiction. I actually briefly stunned my wife. She asked, “Is this true?” I replied, “no!” Heh.

Imagine explaining the internet to someone from the early 1900s

Tonight’s writing prompt was different. Describe/explain the internet to a person from the early 1900s. Better yet, TV or your cell/smart phone. Some pointers were that this was was a time frame where people had the early telephone, electric lights, and very simple cars. Here’s what I crafted:

***

Do you know how you can pick up the phone and use the operator to ring up someone? Imagine opening a book and ringing up your favorite book. You know you can hop in your automobile and drive to your destination of choice? Imagine opening a blank newspaper and then picking which one you want to read. You know how you can turn on lights at night, and read many more hours than your grandfather could with a simple candle? Imagine people around the world writing new newspapers, books, and articles late into the night. And you can read them as they come out. You don’t need to wate for tomorrow’s edition of the paper. The moment they publish something, it’s available in your blank book. It’s available in your blank paper. And over time, you can actually follow your favorite authors. Perhaps you started reading Jules Verne. But then Mark Twain starts writing. You don’t have to buy a new book. You can simply ask for Mark Twain’s latest novel and its available. Or perhaps Mark Twain decides to write a weekly letter.

***

I have to admit, my wife’s writing was hilarious and way better than mine. But it was fun, because we each took a turn and read a scene from our manuscripts.

Never underestimate old men on park benches

Tonight, our Writer’s Group had an exercise. Based on the statement above, write something in five minutes or less. This is what I crafted:

* * *

It surprised me. I usually have my tea. Somtimes crumpets. Then I sit in my usual spot. London Financial Times, that’s what I read.

But today was different. Somtehing was falling out of the sky. A jet? Heathrow’s noisy traffic nearby was my first thought. Nope. Not that. Several large boxes from nowhere were crashing in from high above.

My eyes widened with surprise. Not because a whole bunch of boxes landed in the park’s pond. Sure that was awkward. But the fact that the boxes opened up and several animals emerged. And they started talking!

“Where are we?” a green frog asked.

I did the only thing possible. I replied, “You are in the United Kingdom. The gem of the North Sea. The great Britannia.”

And then they were off. My wife would never believe this.

* * *

Do you have a clue what this scene depicts? If so, drop a comment.

Happy writing!

How to create your own OpenOffice backend w/ @asciidoctor /cc @kubern @ysb33r

asciidoctorMy work on creating an asciidoctor backend for Packt Publishing (i.e. OpenOffice) seems to have caught several people’s attention. Today I spotted an exchange of tweets asking about OpenOffice in general. I figured a more detailed approach to doing that would better fit in a blog posting.

Starting with the basics

For starters, this whole thing is based on creating an FODT document, not an ODT one. The “F” stands for Flat and it is basically an XML document. Your mission, should you choose to accept it, is to create an XML document with all the right parts. That’s the reason my backend is written in SLIM.

SLIM is basically XML with every bit of unnecessary stuff removed. No closing tags. No angled brackets. Nested elements are denoted by indentation, hence giving it a more YAML-like feel. Checkout the following fragment for generating different section levels.

Working backwards

My recommendation is to start from a document you know and love. I started with Packt’s template they sent me. I performed a “Save As” and picked “Flat ODT” to get it into XML format. I then wrote a sample asciidoctor document with all the things I wanted. I suggest you start small and not get into complex layouts (yet). Remember: Minimum Viable Production (MVP) is the key to short, iterative success. From there, I started running my backend against this thing and comparing it with the outcome.

Got xmllint? If not, you should. Your output will be compressed XML. xmllint is the key to viewing your FODT output. Got giant monitor? .It can help dealing with stuff scrolling off the screen as you inspect your handiwork.

A key thing to understand. Asciidoctor splits up each “element” of asciidoc into a separate fragments and looks for the corresponding stuff in your backend. Got a “section”? Look for slim/packt/section.fodt.slim.

  • slim is the template engine
  • packt is the name of the backend (hence all your fragments will be there)
  • section.fodt.slim is convention-over-configuration for generating an FODT-styled chunk of XML everytime asciidoctor hits a “section”.

The top level thing for you document is, duh, document.fodt.slim. And this is also where you’ll find the root FODT XML <office:document>.  Way at the bottom is a common pattern, “=content”. This says, continue processing further asciidoc tokens and insert results at this level.

Iteration is the key to success

To run your backend against your asciidoc input:

asciidoctor -T /path/to/your/backend-root/slim -b packt your.adoc

My backend doesn’t cover every possible element of asciidoc because I didn’t need them. With asciidoctor, you can start with just document.fodt.slim & helpers.rb and when it hits an unknown token, it will tell in simple terms. Go and code <foo>.fodt.slim, and run again. Eventually, you can piece out your entire document. And in the process, you’ll become quite fluent with both FODT and asciidoctor.

Don’t give up!

You will undoubtedly hit some bumps. I sure did. One was getting my code fragments to apply a different style to the last line of any block of code. I probably invested two weeks of effort in this entire backend while writing Learning Spring Boot, but the payoff was enormous. If you are trying to convert a giant slew of documents, try to avoid after the fact edits. And if possible, get the core stuff working, like sections, paragraphs, bold/italics, bullets and admonitions. That stuff really motivated me to push forward.

Oh yeah…

Last time I checked, asciidoctor has special processing rules for double underscrores (__). Several of my style names from Packt had them, and it caused havoc. Once I tracked it down, I simply did a global replace, reducing them to single underscores. DON’T USE DOUBLE UNDERSCORES FOR ANYTHING!

Good luck!

Checking out editors

idea_sublime_atomIf there is something software developers do, it’s get real picky about tools for editing software. That’s why there are strong, almost religious debates about vi vs. emacs. I recently got fed up with TextMate for various reasons, so I decided to investigate more than my usage of vi.

I’ve included a screenshot of all three, side-by-side on my 39″ monitor. You guess which is which.

Sublime Text 3

This one I have found to be pretty neat. It’s fast, snappy, and opening up a project is a single command from my shell: subl /path/to/project

I quickly got moving when I learned there were only two key commands: Cmd-P and Cmd-Shift-P. The first is used to find files. You start typing fragments of a filename, and it quickly narrows your selection. Pick it, and it’s open in no time flat. That nicely matches Java’s one-class-per-file convention. Cmd-Shift-P is the Command Palette, which lists every available command. You then start typing fragments, and your list of commands shrinks. Then you can arrow-down and pick it, or hit the hotkey. Having a single way to find any command or file saves me from going to my trackpad and using the menus.

In the JavaDocs, HTML tags are nicely highlighted. Sometimes the color choices of Java syntax seem a tad awkward. But I rarely alter settings because I always fear either losing them, or going to someone else’s machine and not having them. Perhaps I might be able to stash them in Dropbox and soft link them in?

Another killer feature is the right-hand miniaturized layout of the entire file. Hover over it, and you quickly see where you are.

I’m still pretty new, so I haven’t learned how to open multiple tabs on the same file yet. Nonetheless, this tool is already productive for me!

Atom

After spending almost a whole day adding new asciidoctor content, my colleague Roy Clarkson hinted that I should check out Atom. I downloaded it last night and took a peek.

Nicely, Atom has the same keystroke to pull up the Command Palette. This feature sure must be popular. Right off the bat, I noticed the font size was a bit big. While it appealed to fuzzy vision, it was too impractical for the ground I needed to cover. Felt like I was peeking through a tube to see the code. So I pulled up the Command Palette and shrink the font size about five times so it approached the size of Sublime.

Opening the same file in the same project, I noticed that the color palette of syntax highlighting was a bit easier on my eyes. The contrast between bits of code didn’t seem wide enough, while Sublime’s contrast was a bit much.

I read an article pointing out how Atom is built on top of Chrome, JS, and Node, and conveniently comes with the JS toolset. Another article heavily criticized Atom’s shaky foundations which can start to magnify performance issues as you get into bigger projects. I’ve already seen a bit of this when trying to find files. Sublime just seems snappier.

IDEA

To compare things in full, I switched IDEA to it’s Darkula theme and opened the same file in the same project. A third syntax highlight color palette. Great. This dark-theme on IDEA is softer on the eyes, but some of the color clashes kind of turn me off. I’ve tweeted before that I don’t get it. Yet, at the same time, I use green-on-black for Terminal and totally dig the white/color-on-black of the other editors. Perhaps if I commit to a couple days, I might get into this?

What does IDEA have that the others don’t? IDEA is a full fledged IDE. Pick a function, then find everywhere that it’s used. Editors aren’t designed to do that.

This Command Palette from the editors has encouraged me to learn how to do that in IDEA. Apparently, Shift-Shift is the way to pull “Search Everywhere”. I am trying to do more of this. I have already learned how to find files and classes as well as pull up refactoring toolbars. These are all handy features. But to speed up the action, I need to jump to the command palette. From there, you can see commands as well as learn their hotkeys. More time on the keyboard is the ticket to efficient coding.

Results?

So far, IDEA isn’t going anywhere. I need this type of stuff. I just have to keep improving my efficiency at using it. As for an editor, Sublime is ahead of Atom right now. But like my bio says, I’m always looking for the right tool.