Things Afoot

Here’s what I’m up to these days:

I now work for the Emerging Solutions group of BJC HealthCare. So far I’m loving it. I’ve been reunited with a couple of colleagues: Pat, who I worked with at MetaMatrix, and Paul who I worked with at Monsanto. My timing was fortunate: my first real work is to be on a team that is kicking off a new, large web portal. Technology includes Spring (MVC, Web Flow, Security), Hibernate, Velocity, Maven, CVS, web services. Development tools are Eclipse, the Atlassian tools (Bamboo, FishEye, Crucible, Jira, Confluence), GreenHopper (a Jira plugin giving a Scrum-centric view). We do scrum and even have two certified ScrumMasters.

Another colleague, Ryan Senior, has started within ES a shadowy secret cabal known as the Dead Coders Society. The group meets informally for an hour every few weeks and discusses some technology, book, or whatnot. We met this week, it was my second meeting; the group has just finished up Bob Martin’s Clean Code and then we voted on what to do next. We ultimately decided to read Guy Steele’s two Lambda Papers in preparation for tackling Real World Haskell.

Which segues nicely into the Lambda Lounge. This local functional and dynamic languages interest group has given me, and many others, the language itch. I believe Ryan (another regular) got the idea from λL to propose both the lambda papers and Real World Haskell. There has already been one Haskell presentation, and there are two more scheduled. I’ll be presenting on the Fan programming language in July. Fan is considerably less mind-bending for a Java programmer than something like Haskell, but nonetheless it is an enjoyable learning experience and I’m looking forward to presenting. I also implemented a Fan vending machine for the language shootout last month.

In other news, earlier this year I released a new version of my church’s website which I built using WordPress. It’s central feature is essentially a podcast of the audio of each sermon. I’d like to blog more about this in great deal, I learned quite a bit in the process. While I’m happy with the result – it is a quantum leap beyond the old site – I’ve already got a long mental list of improvements. First up – refactor away a lot of hardcoded behavior and, if possible, find or make WordPress plugins instead.

By the way, as I publish this I am sitting in the audience of the St. Louis Java User’s Group, watching Matt Taylor present about Groovy and Test Driven Development. He is writing an application from scratch live on stage using Groovy and TDD.

Google Chrome + remapped keys = True Love

I know I’m a little late to this party, but I have fallen in love with Google Chrome. I have made it my main browser at work and now at home. Once it’s available for Mac, there’s a good chance I’ll make the transition there, too.

The thing about Chrome is, 90% of the time what I want to do with the browser is google for something. With Chrome this is so optimized, it’s the closest thing on Windows that’s felt like QuickSilver. This is what I find myself doing multiple times per hour at work:

  1. alt-tab to Chrome
  2. ctrl-t opens a new tab and automatically places the cursor in the multi-purpose address/search bar
  3. type search text, hit enter, done

Only then, when the search results are up, do I have to reach for my mouse and select one. And in fact, often when typing the search criteria Chrome will display the top search results as I type, allowing me to select one with the arrow keys and bring up a search result without ever touching the mouse.

Chrome

On a related note, and I’m definitely late to this party – I can’t believe I’ve lived this long without remapping my Caps Lock and left Ctrl keys! I’ve done this at work and now at home, and it feels like typing on silk!

The one twist is that I share this home XP box with my wife, so the registry key I edited was:

HKEY_CURRENT_USER\Keyboard Layout

Instead of the local machine. This seems to work.

A couple nice quick Chrome key-combos (many of these are not specific to Chrome, of course):

  • ctrl-t – new tab
  • ctrl-shift-t – reopen most-recently-closed tab
  • ctrl-w – close current tab
  • ctrl-tab – next tab
  • ctrl-shift-tab – previous tab
  • ctrl-h – history
  • ctrl-j – downloads
  • ctrl-d – bookmark current page
  • ctrl-b – show/hide bookmarks bar
  • ctrl-shift-b – bookmark manager
  • shift-Esc – Google Chrome Task Manager (shows mem/CPU/network for each Chrome process (each tab is a separate process))

I still like Firefox, especially when I’m using the Firebug plugin. But there’s just something about Chrome, so slick, so clean…

Update: a coworker just suggested I search for about:internets in Chrome:

about:internets

Got my Geek Fix at the Lambda Lounge

Once again, the Lambda Lounge did not disappoint.

This month’s mind-bending topics included Factor, presented by Kyle Cordes, and Perl 6/Parrot, presented by Charles Sharp. Both of these guys are great speakers, I make it a point not to miss their talks.

Appistry again very generously hosted the λ Lounge and supplied Fortel’s pizza and beverages.

Jim Brasunas took a few minutes to talk about ITEN, a non-profit group which helps support ventures and startups. I think everyone was surprised to hear that there are nearly 100 technology-related startups in the St. Louis area.

We’ve been really spoiled by some great presentations and great speakers, so I don’t know what I was thinking when I volunteered to speak about the Fan programming language in July. Tonight I took notes during both talks, and I think I’ve spotted a few patterns that help to make any programming language presentation better.

  1. Go ahead and do a Hello World program, but…
  2. …a fibonacci sequence program has emerged as a must-have. It’s like the new Hello World.
  3. Keep things moving along. The slides/software can always be made available later or even made into handouts, as Kyle did.
  4. I like to hear just enough background to get an appreciation of where the language is coming from. What persons are involved? What are they trying to accomplish? What (if any) languages preceeded this language? Kyle and Charles both struck just the right note here, imho.
  5. How concise is the language? How productive does it make you?
  6. What real-world projects/accomplishments are associated with this language?
  7. What idioms are unique/advantageous in this language?

I’m very much looking forward to the language shootout next month, as I believe everyone is.

Revamping Church Website

I attend church services at the Kirkwood Church of Christ, and have for almost my whole life. In around 2005 I helped create the church website and have maintained it ever since. It is extremely basic, made entirely of static file content. It uses frames. Boilerplate HTML (the header for example) is copied into almost every HTML file. This is a website that would have been unimpressive back in 1997. It is extremely mundane and time-consuming to make almost any changes or addition to the content, and I have very little time to spare.

So I am redoing it from scratch, in the hope that some much-needed work this month will make future changes much easier. The main catalyst is that we want to be able to post the audio from every sermon, basically a podcast. A slightly less high priority would be to set up a blog for the preacher (L.A. Stauffer) and fold the existing “bulletin articles” into that. While I’m at it, I’d like to do a proper CSS layer, and if time permits I’d definitely like to add some jQuery goodness.

I decided it would be a good idea to blog my progress, for my own information if nothing else. So here goes.

Settling on a stack

(I stole that phrase from Alex’s blog entry, about the reference web app we implemented for Terracotta.)

LAMP will be the stack, basically. We are using ipower for web hosting. The server environment they have us hosted on, in a nutshell, is Debian, MySQL 5.0.45, Perl 5.8.8, PHP 4.4.7. Which is great, because I was thinking I wanted to use Wordpress for the sermon podcast. I decided I would do the work on my work MacBook Pro, I would use git for version control, and I would try to set everything up to run locally on the MBP before promoting to production.

By the way, I’ve never programmed in PHP before.

Day One

I spent about eight hours on Tuesday the 23rd getting started. By the end of the night I had installed PHP and Wordpress on my MBP, set it up with mysql, and had a running empty Wordpress blog running on my localhost. Here’re are some notes.

Apache 2.2.11 wouldn’t build on my box for some reason, so I reverted back to 2.0.63. (The whole make process for that project is amazing, how it auto-detects various things about the environment it’s being built with.) I decided I wanted to keep my project in a directory separate from the web server install, so I had to edit the httpd.conf file and add an Alias for that directory.

Wordpress has a nice famouse 5 minute install that walked me through creating the mysql user/password and database, then editing the wp-config.php file to use it. During this installation I realized I hadn’t installed PHP yet, so I did that (required more edits to httpd.conf). Then the next gotcha – apparently the way mysql hashes passwords is incompatible with PHP 4.4.x (or something), so the password has to be created in mysql like this:

mysql> SET PASSWORD FOR 'username'@'localhost' = OLD_PASSWORD('supersecretpassword');

Day Two

Tonight was my second night of working on things. My two accomplishments were to install git and get the initial project structure into version control, and to install the Eclipse PDT plugin for PHP development, and create an initial project out of the directory I’m working in. I have yet to open a single PHP file or program a line of code, but it feels good getting this much of my development environment squared away.

I got some help from Kyle Cordes’ blog about git, as well as the handout I kept from his talk at the St. Louis Java User’s Group.

Still a lot of unanswered questions. In particular, I’m not sure if Wordpress will be a good enough fit for what I want to do. I like the way Wordpress can do both blogs and static pages, so I’m hoping I can use a single installation of Wordpress to handle the main web site and also the podcasts, and I’m wondering if it’s possible (and easy enough) to modify Wordpress to be able to handle a separate blog (the preacher’s articles). So, two (or more) blogs but just one site, one theme, one mysql database. I’m guessing all the php can be modified to do this but I don’t really know.

Kyle Cordes presentation on Git tomorrow at St. Louis JUG

Just a quick post – tomorrow evening at the St. Louis Java User’s Group, Kyle Cordes will be giving a presentation on Git. I’m looking forward to this both because Kyle is a very good and accomplished speaker on technical topics, and also because I’m eager to learn more about this distributed source control tool. Hope to see you there!

Caching the Hot Stuff with Terracotta

As I’ve been blogging about recently, we have been developing an exam-taking web application at Terracotta to demonstrate the Session Clustering capabilities of Terracotta. Since one of the requirements of this web app is that we support 40,000 concurrent users, we thought we’d better cache the hottest exams (using Ehcache) rather than fetch them from Hibernate each time. Since modifying an exam should occur far, far less frequently than taking an Exam, and since Terracotta already supports Ehcache, this was a no-brainer.

There is an ExamService service, configured as a Spring bean, with DaoExamService being the default implementation:

The findById method is expected to be the most frequently-invoked method. The other two methods shown are administrative functionality, not expected to be used frequently. We want to cache the results of all three methods in a single, clustered Exam cache.

My approach was to write a new service, CachingWrapperExamService, a proxy which owned the cache and which delegated to another ExamService instance:

The following were straightforward changes:

  • Once again, our use of interfaces have reaped dividends: Introducing this new Caching ExamService was as easy as tweaking the Spring XML file – the change was completely transparent to all users of the ExamService bean. It also made unit testing easy, as I could create a mock ExamService to test caching with.
  • The Maven pom.xml had to be changed to note that Ehcache is now a compile-time dependency, not just a runtime dependency.
  • The Terracotta config file tc-config.xml did not have to be modified, as we were already using the Ehcache TIM, and so our CacheManager was automatically clustered.

And just like that, we have a clustered cache of the hottest exams being used.

ORM can lead to inflexibility; Terracotta can help

Okay, granted, I’m biased, I work for Terracotta. Be that as it may, I’d like to share some experiences my teammates and I have had using Hibernate recently while developing a web app.

First, some brief background. We are developing a “reference” web app at Terracotta to use to promote and explore the Sessions Clustering Use Case which we are working to nail. The app is an online exam-taking application, with the goal of supporting 40,000 concurrent users. I’ve blogged about this before, and you can read about the technology stack we settled on. Development has been done primarily by myself and my teammates Geert Bevin, Abhishek Sanoujam, and our supervisor Alex Miller.

Hibernate is wonderful, and it is an integral part of our web app. It feels to me like we got moving pretty quickly using Hibernate for persistence of our domain objects. For ORM, it’s unbeatable.

But the thing I noticed is, there’s just no avoiding the fact that whatever your domain POJO’s are that need to be persisted, chances are good that the use of ORM will impose some constraints on how you must write those POJO’s. I have two examples of this to share.

Example One – Generics

First, we have an exam Section class which, conceptually, is a container for either multiple sub sections, or Questions, but not both. The ideal solution would be to define Section as this (JPA annotations omitted):

where TestContent is an interface implemented by both Section and Question. Thus, an instance of Section could be declared as having type of either Section

or Section, which satisfies our constraint.

However, at runtime (when starting Tomcat), Hibernate (the JPA provider) threw an exception pointing out that Section had an unbounded type (or something like that). After a little digging around on the internet, I found a forum where someone explained that an Entity cannot have a generic type, because it’s not known until instantiation time what the linked Entity will be.

Therefore I had to compromise. I modified Section, removing it’s generic type and adding two explicit collections, one for Questions, one for Sections.

This is less than ideal because the Section API itself doesn’t naturally prevent a single Section instance from having both sub-sections and questions, even though we don’t want to allow this.

Example Two – complex object tree

Similarly, for my other example, one of the constraints is that a Question must have exactly one correct choice (from among it’s two or more choices). So our first inclination was to structure the Question class thusly:

But this caused problems when saving an edited Exam which had had a Question added to it. I no longer have the stack trace handy, but the gist of the Hibernate exception was that a transient (unsaved) object was detected in the object graph being merged (updated).

Alex and I dug in and finally examined the generated database schema. What we saw was that the QUESTION table had a CORRECT_CHOICE column which was a foreign key into another table, QUESTION_CHOICE I think it was. Alex and I theorized that there was a possible ordering problem in updating an Exam with a new Question and Choices – what if Hibernate attempted to set the CORRECT_CHOICE foreign key before inserting the new choices for the question?

I’m not 100% positive that’s the correct explanation, but in any case Alex made the executive decision to simplify our domain model and not spend any more time debugging. We added a boolean “isCorrect” property to Choice, and removed the “correctChoice” reference from Question:

Problem solved – we no longer got the Hibernate exception. But, as Abhishek pointed out, our domain objects no longer enforced the constraint that a question could have only one correct choice. With the updated classes, nothing would prevent instantiating a question with multiple choices marked as correct. This put the burden on additional validation code to enforce this constraint, and overall is just less than ideal.

How Terracotta Can Help

The point I am agonizingly slowly building to is, I think it’s acceptable to have these constraints on our persistent domain objects, but only on the ones that should be persisted. An anti-pattern that we at Terracotta have seen again and again is the misuse of the database and ORM to persist state that really does not belong in the System of Record, but rather is transient state that must be persisted only to scale applications by keeping the applications stateless. One of the Terracotta co-founders, Orion, coined the term “State Monster” to describe this abuse of the db, and recently Wille Faler wrote a very good blog describing this.

Terracotta can help by providing an alternative to making apps stateless for scalability purposes. With Terracotta, go ahead and write your application in the most natural way, including shared state that is only transient. Consider this helpful graph about data lifetimes when deciding what state belongs in the SOR and what state is merely transient or pending. Then, use Terracotta to both cluster and persist the POJOs that don’t belong in the SOR. The advantage is that Terracotta does not impose any constraints on the API of the sorts I have written about here – generics are fine, arbitrarily complex object graphs are no problem. Terracotta clustered objects don’t even have to implement Serializable.

Me Meme

unflattering

Via Mario

  1. Take a picture of yourself right now.
  2. Don’t change your clothes, don’t fix your hair…just take a picture.
  3. Post that picture with NO editing.
  4. Post these instructions with your picture.

Weekly Summary – web app

It was a better week. As I said last week I was looking to cut down on distractions and improve my focus. I stuck to a morning routine this week: every day I got up around six, took a 30 minute walk on the beach while listening to Stackoverflow podcasts, then got showered and online by 7 to 7:15. I usually got over an hour of work done before anybody else even woke up. I kept twittering, e-mail and such to a minimum.

I’ve definitely enjoyed working at our condo here in Destin, FL. It was quite a novelty to work on a balcony overlooking the Gulf of Mexico, and I made sure to rub my teammates’ faces in it. But honestly by the end of the week I couldn’t stand to work out there with all the noise and glare. I spent most of my remaining time on the north balcony which overlooks a golf course and lake, and is much quieter.

This week I got started on the reference web app that we are working on as part of Terracotta’s strategy to really nail the clustered “user session” use case. Alex has blogged in detail about that strategy, and more recently on the technology stack we settled on for the web app. Geert Bevin, who is himself the author of the Rife web framework, had already spent a week or two learning Spring MVC and laying down some architectural groundwork. By the time I got started on Monday he was up and running and had stubbed out some basic pages.

My week was divided into two parts. Part one was two and a half painful days of just setting up my workspace. This involved upgrading to Eclipse 3.4 Ganymede, which includes the WTP that Geert was already using to launch the app in Tomcat. Then upgrading all of the plugins I needed. Then endlessly debugging because I got exception after exception when I tried to do seemingly anything.

When I was interviewing for Terracotta, one phrase I heard was “just in time learning”, and that was certainly true this week. Here is a probably-not-complete list of technologies that I’ve had to learn at least some of (or some more of) this week, quickly: Maven and it’s Eclipse plugin, Subversion and Subclipse plugin, WTP, Spring MVC, JPA annotations with Hibernate as ORM provider, SOJO (for JSON parsing in Java), Crosscheck (being evaluated for JavaScript unit testing in Java vm), jQuery, MySql, and probably some other stuff I’m forgetting.

During the second half of the week, everything started clicking and I was finally committing changes. I began working on the exam-creation page. Geert recommended that we approach the page by using JavaScript to allow the user to build up an entire exam and submit it as a single request, passing JSON to the Controller. I’m really excited about this because I’ve grown to like coding JavaScript. I’m almost disappointed that I’ll be on vacation this week. By week’s end I had the controller basically working, accepting and parsing JSON. But I did not get any JavaScript in place yet, although I spent a good bit of time reading up on jQuery and Crosscheck.

My Office This Week

I’m working remotely this week in Destin, FL. It’s rough, but that’s life working for Terracotta.

destin.jpg s100_1479.JPG