Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Sunday, February 1, 2009

Corey Haines and Code Katas

Surrounded by the smell of burnt popcorn and listening to the video Road Thoughts - Practice : 'Doing it right' vs 'Getting it done' really drove home some thoughts.

Do Katas. Do the same problems over and over again. Apply different techniques and approaches. Some quotes from the video:
  • "don't wait for those things to be ingrained..." over time.
  • Practice. "1 hour a day; as much as you can."
  • "Write small problems or solutions to a problem."
Practicing is essential. Practicing effectively is the goal. Practicing efficiently is a challenge.

For a Refactoring kata, what may work for you is setting up some code that needs to be refactored along with the needed JUnit Tests. Once at a satisfactory level of refactoring, you can blow away the refactored solution and refactor again from the start. Where to store such an exercise or Refactoring starting point?

I have given some thought to creating a Java project using Google's Project Hosting that contains things to practice on. I could apply the following labels to the project; label:Java label:kata. There are a couple projects in there now with those labels. I even see a "java-katas" project, but it is currently void of code.

Another thing to think about is practicing with a framework such as Struts2. Perhaps another project could be created which has the labels of Java, kata, struts2.

If Maven 2 is gaining enough popularity, maybe an even better solution is to create Maven archetypes which contain everything you need to practice particular things. Imagine creating a temporary project that is based off a starter template/archetype. Everything you need is downloaded automatically and you're ready to practice.

Well, good luck to you in your quest to practice. Time for me to practice and eat more carefully prepared popcorn.

Update! (March 15, 2009) -  http://code.google.com/p/funkata/ now exists.

Wednesday, November 26, 2008

Wrapping 3rd Party Code Is Clean Code Crafty

The Clean Code book by Robert C. Martin has great points about system boundaries. In chapter 8 titled Boundaries and in the section called Using Third-Party Code, the book shares why and how to wrap 3rd party code.

Points For Why To Wrap Third Party Code (page 115):
  1. The third party code can evolve
  2. Your wrapper's interface can be made to precisely suit your application's needs
Like the book says on page 115, "If you use a boundary interface like Map, keep it inside the class, or close family of classes, where it is used."

That's huge! I also like the "Sensors" class example which has a method that will give you a "Sensor" class. Sensors giving you a Sensor, implies a naming rule-of-thumb which I also like.

Friday, June 13, 2008

Testing an Annotation

I found neat ways to test annotations.

Here is some annotation test code using JUnit

public class LongParameterListRefactoringTest {

@Test
public void isAnnotationWhenAsked() throws Exception {
assertTrue(LongParameterListRefactoring.class.isAnnotation());
}

@Test
public void annotationIsAnnotated() throws Exception {
assertTrue(LongParameterListRefactoring.class.getAnnotations().length > 0);
}

@Test
public void isAnnotatedWithRetentionAnnotation() throws Exception {
Annotation annotation = LongParameterListRefactoring.class.getAnnotations()[0];
assertTrue(annotation instanceof Retention);
}

@Test
public void isAnnotatedAsSourceCodeAnnotation() throws Exception {
Annotation annotation = LongParameterListRefactoring.class.getAnnotations()[0];
Retention retention = (Retention)annotation;
assertEquals(RetentionPolicy.SOURCE, retention.value());
}

}
This code lived at the SeePeople project.

Note: annotationIsAnnotated has since been changed. Can you guess why?

Thursday, November 29, 2007

xUnit Patterns and the Mid-Missouri XP Meeting

The Mid-Missouri XP (Extreme Programming) group meeting last night was quite enjoyable. James Carr led the meeting. James Carr's great experience with test frameworks and Software Development in general really showed through in a positive light.

We dove right into Gerard Meszaros' XUnit Test Patterns site at http://xunitpatterns.com/ and specifically http://xunitpatterns.com/Test%20Double.html. We covered Test Stub, Test Spy, Mock Object, Fake Object, and much more.

I put forth the questions: What are the essential Test Patterns? Where is the UML Distilled version of Test Patterns? The answer was Fake Object and Test Stub will get you to where you want to be 95% of the time.

There was much discussion too. The people who attended had dived into various things and were just great people too. We swapped stories of experience and various technologies that we have explored. Since many people there used Java, one great example of a test framework that was mentioned is JMock.

(You can hook up with what the Mid-Missouri XP group is doing at http://tech.groups.yahoo.com/group/mid_mo_xp/ : In the group, there is a post about the meeting from James Carr )




Friday, November 9, 2007

Gateway Jug in St. Louis

I visited the Gateway JUG in St. Louis. I enjoyed the pizza, people, and topics. The topic of the evening was Web 2.0.

There's so much that a person gets from going to such events. Undoubtedly, a person is exposed to tips and other technologies as a result. I plan on going to the Gateway JUG again.