Wednesday, December 26, 2012

Happy Holidays!

Happy Holidays from Hacker's Valhalla!

If you were expecting content, Spring Framework 3.2 is released (TheServerSide).

Thursday, September 20, 2012

"An Upgrade Without Downtime"

Over at Udi Dhan is a summary post about Dennis van der Stelt's blog on how using a publish/subscribe model and large buffers allowed for power-cycling critical infrastructure without affecting the overall system performance.

It's the first time I've read something about software development and genuinely thought "epic".

Wednesday, August 29, 2012

Blog News and Regexes

For regular readers you may have noticed that there's been a lull in postings; I've had a combination of work and health issues that have taken their toll. Such is the fate of one man blogs!

The Server Side has an article on regexes; regexes (i.e. regular expressions) are one of those things that you need a lot of refreshers on (or need to read a lot to get!).

Wednesday, June 13, 2012

Something Important Happened

I just caught on the eetimes that there is a new software engineering certification.  What makes this a big deal is that it's by the National Council of Examiners for Engineering and Surveying, something that has an actual track record.

The test info is also on their site, look for "Software" in the list.  As the recent spat on Yahoo's CEO demonstrated, there isn't currently an equivalent of the engineering certifications in software.  This may change that.

This may prove to be pivotal for the field of Software Engineering / Programming / Whatever we call it.

Wednesday, June 6, 2012

NOW I Get It: Aspect Oriented Programming

After going through the Aspect related chapter of Spring in Action the concept of Aspects finally "clicked" for me.  This is after reading the Wikipedia on it, the Spring documentation and various other articles as well.

To summarize:

  • Some things (like logging) need to be executed everywhere, even in modules who's primary purpose isn't logging.  Aspects address this issue.
  • An Aspect is just a bit of code (with Spring it can even be a POJO) that is configured (typically with an annotation or XML) to run before, after, or around a join point (for now, assume it's a fancy word for method).
  • For the canonical example of logging, you can create an aspect to log something like "Calling method x with parameters x, y and z" before a method runs and "Returning from method x with return value y" afterwards.  
    • This separates the logged class from the logging system entirely and results in a second class logging the first one.  
    • If you want logging statements in the middle of a method, too bad, refactor to call a helper method (thus creating a new join point) and log there.
Hopefully presenting the gist of it with concrete examples will help everyone's understanding.

Monday, June 4, 2012

Gower's Law

Gower's Law: You can deliver a broken build in near-zero time.

(PS: thedailywtf article in the above link is gold)

This was inspired both by Peopleware (where they mention that when there is a tight schedule quality usually suffers) and my own experience in the work force.

Thursday, May 31, 2012

Review: Force Trainer

I know, I know, I'm a bit late to do a review of the Force Trainer since it came out around late 2009 (Gizmodo review).  However, only now did the price come down enough for me to try it out as I put it into the category: "interesting but is it really useful?"

If you're even later to the party than I am, the Force Trainer is one of the first generation of consumer-grade Mind Machine Interface, and like many other technologies is somewhat expensive (Amazon price is at ~35 USD instead of the original 129), somewhat difficult to set up (initial calibration is frusterating) and somewhat unreliable (or maybe I'm just not the Jedi I used to be).  In case you missed the subtext, yes, IT READS YOUR MIND (or more correctly reads your brain waves).

I've had it (so far) for about two days now and find it a much better concentration aid so far than guided meditation CDs or simple silence (without feedback, how will I know if I'm concentrating correctly?)

All in all, a decent buy at $35, just to have something that reads your mind (this technology will only get better and more prevalent as time goes on, so you may as well get used to it now).

Also, if electronics is your thing, there's a hack to link the input into a serial port.  You could technically adjust your dimmer lights with your thoughts via consumer technology.

I'm really starting to dig the 21st century!

Wednesday, May 30, 2012

Testing, Testing and Testing

You hear it in real estate: location, location, location.  You hear it (not as much) in software: test, test, test.  However, in software the tests are all different.

A recent project that I'm on involves a venerable app with as much technical debt as the US Government... and we need to add a feature.  Solution: tests, tests and tests.  More specifically if you don't know the different kinds of tests:

  • Good old Unit Testing, easy to implement and understand, unless...
    • You are getting used to mock objects (e.g. JMock or Mockito)
    • You are testing database functionality and are new to DBUnit
    • You are testing a web app or Servlet and are new to HttpUnit
    • You're confusing unit testing (ONE module) with integration testing (multiple modules)
    • Example: testing your Data Access Layer (DAL) with a dummy DB, like a local HSQL
  • Integration Testing, usually implemented with a framework that ends in "Unit" so it's easily confused with unit testing.  Integration testing integrates two or more components, everything from two classes to the entire app with a dummy DB.  Due to this you can have multiple levels of integration tests, each testing more modules together.  Examples include:
    • Testing a servlet in HttpUnit's ServletUnit instead of your actual web container
    • Testing your DAL with an "actual" database (whatever actual means to your project)
    • Testing a fully created Spring bean with the real beans injected instead of mocks
  • System Testing, this is tests of the entire system
    • QA usually conducts manual system tests
    • There can be automated ones as well with things like Selenium
    • As an example for a web app, using a supported browser to use the app in the final web container and using the real database.
There is of course, much more to software testing, but these three are usually a good start.  Heck, in many organizations / projects even using unit testing is new to people.  Like Regan said: trust, but verify.

PS: There's a good post at EvilTester with a more philosophical approach to testing.

Tuesday, May 29, 2012

College vs. Industry

Over at InfoQ they have a stimulating article "Crossing the Software Education Chasm" reviewing another ACM article of the same name.  A good article about how to better prepare college students for the "real world".  I've had some thoughts of my own from my own experience at San Jose State University (SJSU) in the Computer Science department.

Image by Clay Bennett
I'm not sure about education in general, but at SJSU we were consistently put into teams and consistently not even TOLD about code versioning software.  I was unfamiliar with even the CONCEPT yet alone the practice of even CVS until my Senior year.  Furthermore, testing was not emphasized at all (a point made in the ACM article) but at least writing was.  (Yes, you can blame or thank SJSU for this blog, indirectly).  The most important lession was not a formal class at all.

I used to think that college was the hugest, worst bureaucracy I would ever encounter.

Then I got a real job.

Saturday, May 5, 2012

DBUnit in Practice

For those of you unfamiliar with DBUnit, it works with JUnit to put a database into a known state between unit tests (e.g. you can wipe out the DB and start from a blank on each run if you want).

I've recently picked up how to use this technology in practice, and this article will help others ease the (somewhat steep) learning curve.

I found DBUnit to be a very collaborative technology, in the sense that it interacts with a lot of other technologies to do it's job.  First off, DBUnit does not PROVIDE the stub or mock database, you'll have to provide one yourself (Apache Derby and HyperSQL are swell for this).  Secondly you have to establish a connection to the DB yourself (using JDBC) and thirdly you'll need to create the tables for the DBUnit data yourself (e.g. via SQL CREATE TABLE statements).  Lastly you'll need to dependency inject (if you know Spring than this concept is nothing new) your JDBC connection object going to the test DB into whatever class you are going to test.  THEN you can run your DBUnit tests.

In conclusion, you need to use a lot of other technologies and paradigms in order to truly use DBUnit.  I hope that this overview and the links help.

Sunday, April 29, 2012

SVWJUG: Actors in AKKA

I went to a talk titled "Composable Futures With Akka 2.0" at the Silicon Valley Web Java Users Group at the famed Googleplex.  It was by Mike Slinn who has this new book with the same title.  Akka is a concurrency library for Scala and Java.

To AVOID the code-equivalent of this
race-condition, use Akka Futures.
One of the more interesting features of futures is that if you take quotes out of context, they can be hilarious:
"[You can] attempt to change the future, you will fail." --Mike Slinn, apparent determinist

It was a highly technical talk revolving around concurrency, everything that can go (easily) wrong and how to make sure that it goes right.  Mike was a great guy and posted his slides as well.

The tl;dr: Futures will let you have deterministic multi-threading.  If you can't tell, this is a big deal in that you can be confidant that your unit tests will mean that the app works correctly in production (no tricky race conditions!)  However, futures don't scale to multiple mother-boards so it isn't a grid-computing solution.  Futures are also composable and immutable (see quote above).

Concurrency is going to be increasingly important as the clock speed of silicon has basically been maxed out and Moore's Law is only continuing due to more cores, so if you want your program to run faster in the future than it does today you'll need to use concurrency.  If you're going to use concurrency, make it as predictable and repeatable as possible (e.g. eliminate race conditions).  Akka Futures let you do this.

Update: Mike Slinn also has a related article on InfoQ.

Tuesday, April 17, 2012

A Technique on Comments: The Separation Banner

In a lot of commenting best practice articles much ballyhoo is made of commenting in the small (single lines or methods) or at the class level (headers, footers, etc), but it seems hard to find anything in between (e.g. what is a good way to separate major parts of a single class).  This article will explain a technique I've seen used, but haven't seen named before or expounded upon: The Separation Banner.

Quite simply, a separation banner is used when you need to demark major blocks of a class or other source-file (assuming you aren't using Java) to aid in visual navigation and in keeping the class in order.  The pattern I've seen the most is a line of slashes (i.e. enough to fill up to the 80 column), two slashes + text, and another line of slashes.  E.g.
  // IFoo Implementation
Other examples for the text inside can be things like "Accessors" "Static Methods" or "Inner Classes".

Humorous Image brought to you by
Digital Storytelling and The Simpsons
In general, I have found the separation banner to be quite useful, and created an Eclipse code completion entry for it so I can avoid adding all of those slashes every time.  As always, you can have too much of a good thing so having one banner for every five methods or more (roughly) has worked for me.

So, next time you frequently get lost in the inner muckings of a class, consider adding some additional structure with a separation banner.

Sunday, April 15, 2012

Best of Perl - Plain English if Statements

I worked with Perl for a couple of years and I miss being able to write code that feels like plain English.  I've managed to capture a bit of this into plain old Java by using self-documenting booleans instead of actual statements in if statements, as in the following:
final boolean fooExists = foo == null;
if (fooExists) {
  // code here
Hater's Gonna Hate at
This seems almost too simple to deserve the declaration, but you can also write more complex statements like "if (fileIsOpened)" or "if (stringHasContents)" (i.e. not null and not empty / blank).  In particular, it helps when re-factoring someone elses code to understand what an if block actually does or MEANS.

Tuesday, April 10, 2012

NOW I See: The Realized Benefits of Unit Testing

We all know the things that we are supposed to do, but don't as much as we should: eat fiber, cut down on sugar, don't be sedentary, exercise, eat fruit, unit test.  Blegh!

Not my exact point, but pictures about
unit testing are hard to find!
(Image from Reportnet)
For the last part at least, I came across some actual useful results.  Before, whenever I wanted to unit test a class, I didn't write a test for it before and usually had to ramp up on another technology to boot (JUnit3 vs JUnit4, HttpUnit, DBUnit, Mocking) or realize that I really wanted an integration test (jMeter, Selenium).

This time however, I spotted what looked like incorrect code and there was already a unit test for the class!  I was able to write a short test that verified the bug (i.e. wrote a failing test), fixed it and reran the test successfully!  All this in less time it would take to run mvn verify (including deployment to WebLogic)!

I'll be a bit less loathe to write tests in the future now, since I actually SAW that "it's better in the future" thing they say about testing.

Tuesday, March 27, 2012

Maven Reporting Configuration

A small cheviot caused me a lot of problems with Maven Reporting.  As it turns out, configuration in the pom.xml file under project/build is completely ignored when running mvn site!  

Live and learn.

Wednesday, March 7, 2012


In software engineering, as in much of life, there is no substitute for good old-fashioned character. has a definition of "moral or ethical quality: a man of fine, honorable character."  In particular (for creating great software), exemplifying the virtues of industriousness, truth and courage.  The practical application of industriousness is obvious (even when your code is compiling), but truth and courage are needed when a deadline isn't going to be made, or a critical bug is found.

Thanks to
Character is especially important, as the client or boss frequently has less technical knowledge, and counts on our trustworthiness and expertise (see also, information asymmetry).

This may sound disingenuous from an author who shamelessly plugs this blogs in comments and posts demotivational posters for the links (I mean, for the readers), but even though this is a new profession, lessons from ancient Greece about virtue and character still hold true.

Thank you.

Monday, March 5, 2012

Drop-down Form Submissions in Trinidad

I've recently been doing this the very wrong way.  So I'll be going over the wrong way, and the right way.

The embarrassingly wrong way, is to have an Apache Trinidad drop down followed by a command link.  You set the onchange of the drop down to document.getElementById('commandLinkId').click() and have the command link do the submission.  I swear I found some webpage that recommended this, but I can't find it anymore.  As a side note, if you're doing things REALLY WRONG you can put the value of the dropdown as a variable instead of a property and try to read it in the actionListener of the command link.  This method may truly be Daily WTF worthy.

The less wrong way (using Trinidad), but the seemingly standard way to do it in normal JSF to do it would be use onclick="this.form.submit()".  This is a decent way for normal (non-Trinidad) JSF, but Trinidad makes it even easier!

The RIGHT way is to use Trinidad's autoSubmit feature.  This not only fixed a bug (doing it the VERY WRONG WAY resulted in a race condition with the version I was using), but saved lines of gristly code, avoids JavaScript (being used directly) and cuts out an invisible commandLink.

Please, please avoid my foolishness.

Friday, February 17, 2012

Spring and null ExternalContexts

After brief consternation of getting null values for Spring's ExternalContextHolder.getExternalContext() and RequestContextHolder.getRequestContext().getExternalContext() I realized that I was calling this code outside of Spring entirely!

From double-checking the docs I guess it seems that this is considered a "common sense" feature and isn't mentioned.

My only solace in the dreaded NullPointerException is that even the inventor doesn't like them.

Thursday, January 19, 2012

Buzzin': Buzzwords and Technologies from the January 2012 SVJUG

Image from
So many technologies you'll be buzzin'.  This article will briefly summarize the meeting and the technologies mentioned.

So the Silicon Valley Java User's Group had a great meeting on January 18th at the Googleplex.  It was on a fairly advanced topic, Heroku.  James Ward delivered it and delivered it well, it was a whirlwind tour-de-force of a microcosm of Java and other technologies.  Heroku itself was described as PaaS, Cloud + Polyglot and in the course of the session, many, many other buzzwords (it wasn't really "buzz" in that it was actual informative content and not empty hype) and technologies were mentioned.  So many that they need some explanation and so many explanations that they need categories.

I hope that you enjoy drinking from the fire hose!  You definitely will if you need to ramp-up on these things.  I hope you found some use here or followed some of the links.  At the very least if you were already familiar with the 80 technologies listed (YES!  EIGHTY!) then you deserve a pat on the back (and probably a hefty salary!)