Home arrow Blog

Michael's blog is now available on the Click here to order on Amazon.com

Apache Struts 2 Web Application Development is out!

Struts 2I am pleased to announce that the book I was a reviewer for, Apache Struts 2 Web Application Development by Dave Newton is finally out! It is available on amazon here: http://www.amazon.com. Published by Packt Publishing, it is a good overview of the Struts 2 web framework. One thing that Dave did better than any author of other web framework books I’ve read is the coverage of JavaScript. He covers JavaScript very thuroughly. Not only covering what the framework provides (which actually isn’t much) but core JavaScript concepts and jQuery. Overall, this is a solid Struts 2 book with the advantage of being a good JavaScript book. I encourage you to check it out!

Java Classpath Debugging with verbose Arguement

Today I came across a useful tidbit for debugging classpaths. A little background: I was attempting to write a unit test using the PowerMock framework to mock a static method. When I went to execute the test, I received an exception that I had two versions of org.apache.commons.logging.Log in my classpath. Looking over my classpath, it’s no wonder. Like most projects, the list of libraries in this project reads more like a history of the project than what it actually uses. Multiple copies of the same jar file…multiple verisions of the same libraries…just a mess (don’t get me started on dependency management…that’s a topic for another day).

So with the help of Google I discovered the -verbose:class JVM parameter. Ever wonder what classes are being loaded in your JVM? Ever wonder who is loading that mysterious class? This is the parameter for you. This option outputs a list of classes loaded and from where. In my case, PowerMock was loading Log and so was a copy of the commons-logging jar file I had in my project. What are some debugging tips you’ve used in the past that may not be every day knowledge? Leave it in the comments!

Paired Programming…automating human tasks.

I miss pairing (or the practice of paired programming). Those who have never tried paired programming commonly look at the practice as a waste of resources. Two people doing the work of one…or so it seems. However, there are so many things that pairing brings to the table. One of those is that when you pair program, things you would have to do anyways just happen. They get automated automatically (pun kind of intended). So let’s take a look at paired programming as a way to automate things you are going to do anyways (or prevent from happening).

  • Automating of issue solving.

    As technologists, we face scenarios on a regular basis where we have to work through something that we haven’t done before, haven’t done in a while or just aren’t sure what the best way to do it is. When this occurs, our productivity can come to a crawl as we research the solution. With two developers, the likely hood that: a) one of the devs knows the answer or b) they can research the answer quicker cuts down on the time spent churning on a single issue.

  • Knowledge transfer automation.

    This is related to the item above. When you work side by side with someone, you learn together. If one person knows something, they teach the other and vice versa. By rotating pairs, this transfer of knowledge happens automatically across your team. This limits the creation of SMEs and prevents bottle necks that occur when only one person knows a particular technology or part of the system.

  • Automatic distraction repellant.

    When was the last time you were working in your cube and someone walked up just to talk? Unfortunately, (although no one will admit it) this happens way to often in the business world. This painful disruption of thought as well as the time taken away from development is a huge drain on productivity. However, when two or more people are already working together, people become less likely to interrupt. Those casual “Hey, did you catch the game last night?” conversations seem to just go away. People, by nature, are less likely to interrupt a pair of developers working than just a single developer. Just another place where there is power in numbers.

So how about it? On paper this makes sense. Those who have tried it seem to agree. However, why is it that this practice seems about as likely to go mainstream as cutting overtime (which many studies have proven actually makes developers less productive…a topic for a different day)? What are your experiences with paired programming? What’s good, what’s bad? Share your thoughts in the comments!

Prototype’s Element.insert

So today I was working on a small item that I figured would be pretty straight forward…until I went to Prototype’s documentation. I want to say that overall, I really like Prototype’s doc site. Overall, it is laid out well and 95% of the time has exactly what I need. Unfortunately, this is one time where it didn’t. I wanted to implement a simple select box with two arrow buttons next to it (up and down). The goal was to allow users to order the options in the select box. Below is the code I was using for moving an element up (down was similar):

function upOption() {
  if(!clicked) {
    clicked = true;
    options = $('selectId').childElements();

    for(var i = 0; i < options.length;) {
      element = options[i];
      if(element.selected && (i - 1) >= 0 ) {
        options[i].remove();
        options.splice(i, 1);
        Element.insert(options[i - 1], {before: element});
      }

      i++;
    }
    clicked = false;
  }
};

Where I got stuck was on the Element.insert. The documentation (as found here) states that “Inserts content before, after, at the top of, or at the bottom of element, as specified by the position property of the second argument. If the second argument is the content itself, insert will append it to element.”. What does that mean?!?!

I’ll tell you what it means. Element.insert takes two parameters, the element to insert the new content ajacent to and one of the following:

  • The content to be inserted
  • A Hash with a single key that dictates where to put the content with the content as the value

The example above is an example of the option with the hash. What this does is it takes options[i - 1] and places element into the DOM as the first sibling above options[i - 1]. What each option does is as follows:

  • before: Places the element as the first sibling before the identified element in the DOM
  • after: Places the element as the first sibling after the identified element in the DOM
  • top: Places the element as the first child under the identified element in the DOM
  • bottom: Places the element as the last child under the identified element in the DOM

If we use the example Element.insert($('myList'), {XXX: new Element('p')});, the new p element would show up in the corresponding place:

<div id="container">
     before
     <ul id=”myList”>
          top
          <li>element 1</li>
          <li>element 2</li>
          <li>element 3</li>
          bottom
     </ul>
     after
</div>

So there you have it. Please feel free to point out any optimizations I could do in my method. One I already know about but was unable to get working was removing the line element = options[i]; and just use the element returned from the remove() function. Unfortunately, I was unable to get that to work (as tested in IE7). As always, I look forward to the comments!

Thanks to Joseph Hirn and Partial Mocks

I just came from a brown bag session given by Joseph Hirn on unit testing. He did an excellent job covering unit testing concepts as well as some great tools/tricks. One that he pointed out that I think I will dive into on this site is the concept of Partial Mocks.

Partial Mocks are concept provided by EasyMock’s Class Extension package. They allow for the mocking of a method over an entire class. A tutorial coming soon.

Once again, I’d like to say great job to Joe and thanks for the free advertising ;)

A sound backup strategy. Is that so hard?

Ok, I’m confused. This is 2009, correct? The web is 19 years old. Why do companies go into production at this point in time without ANY form of tested data backup plan? I’ve seen two reports since the first of the year of companies folding due to the complete loss of all user data.

The first was the blogging platform Journalspace in January (they have since been picked up by a new owner…hopefully they have heard of off site backups). Journalspace was using RAID as their backup. The thought was that if one drive fails, we have a copy on drive two, so all will be good. Fine in theory…if the only failure that occurs is a hardware one. In Journalspace’s case, the data was wiped via software. If you delete a file on purpose from drive one, it will be deleted as well from drive two. A backup strategy, RAID is not.

Now we have the social bookmarking site Ma.gnolia. Today they announced that their attempts to recover from a database server crash have been unsuccessful and all data has been lost. In this case, instead of not having a backup strategy at all, they just had one that didn’t work. I would now consider them poster children for testing your backup strategies.

Am I missing something? As a user of services like these, these should serve as examples of why you shouldn’t trust your service providers and do your own backups. Backup your WordPress or Blogger blogs. Backup your del.icio.us and digg links. What methods do you use to backup data that service providers store for you? Let us know in the comments!

A great saying for how to live…

I am a lucky guy. I’ll be the first to admit it. Regardless of the situation I’m in, no matter how bad it seems, things tend to fall my way. My mother says:

“Michael can fall in a pile of sh!t and come out smelling like a rose”

And it’s true. However, I came across a saying today (an old co-worker of mine had it in his gmail profile) that really fits why I believe that things tend to fall my way. After some research, I believe it was said by John Wooden (a famous college basketball coach):

“Things turn out best for the people who make the best out of how things turn out”

I’m a big believer in that you make your own luck in life. If you set things up well, they will fall your way. This really has nothing directly to do with technology, but as more of a life principal.

When things don’t go your way, do you tend to blame yourself or look at external sources? You are the one variable you can always control. When you can control the outcome of situations by controlling yourself, you suddenly become a lucky person.

Share your thoughts in the comments!

New Tutorial on EasyMock’s MockControls

Most people who have used EasyMock before are familiar with the types of mock objects. There is the basic mock object, created with EasyMock.createMock(MyInterface.class);. There is the strict mock that validates both the method calls and the order they occur. Finally there is the nice mock which returns a basic default (false, 0 or null) if an unexpected method call occurs. However, most developers I have come across don’t use mock controls much. Today we change that! My new tutorial will introduce you to the concepts of mock controls and show you an example of where your unit testing without them may not be as safe as you think. You can check out the new tutorial here: http://www.michaelminella.com/testing/mock-controls-with-easymock.html

Thanks And A New Year

I wanted to take a minute during the hustle and bustle of the holidays to say thanks to everyone in cyberspace. Although I have been a web developer for over seven years, this is the first year that I actually took the time to put something out on the net that I could call my own. It is my goal to provide tidbits and knowledge to those who happen by my site that should make their development a bit more smooth. From the feedback I have received I think I am on track. But I need to thank you for both following and supporting what I have put together here. Your feedback is both invaluable for my growth as a content developer and as support for the time and effort that goes into putting together a site like this. Thank you.

With that being said, it’s also time to start looking forward to next year. This past year I launched the site, developed tutorials on JUnit, TestNG, EasyMock, jmockit, Prototype and script.aculo.us. What are some areas that you want to learn more about? Should I go more in depth into some of the above topics? Are there topics in the web/java space that you would like to see me cover? I have created a survey to gather some input. Let me know what you think by taking it here:
View Survey.



Thanks again for all your encouragement and ideas. I’m really looking forward to an exciting 2009!

Personal Development Environments

We all know that source control, effective build scripts and continuous integration (CI) are all vital to a successful project at work. However, what about personal projects? You know the ones…that website you built for Uncle Bob’s starting business or the application you developed when you were playing with Groovy. Most of these projects begin as nothing more than a right click in our favorite IDE, creating a new project and starting to code. However, I am curious if anyone has a more robust system for their personal (or not yet public) development. If for no other reason, what if one of your projects sparks something that becomes bigger than what was envisioned at the outset and you want to make that your new business. Migrating to source control can be difficult at best and that would only be the beginning of issues.

So I ask you, readers, what do you use for your development environment? Do you use source control? If so, do you host it or is it hosted by someone? Build scripts, yes or no? CI? Let us know in the comments!