The Source for Java Technology Collaboration
User: Password:



Editor's Daily Blog

Refactoring in real life

Posted by daniel on January 05, 2005 at 07:28 AM | Comments (0)

Throwing stuff away

I spent some time last week writing a toy application that exercises the Apple Rendezvous Java APIs. This particular example is a tictactoe game. At one point I realized that most of the game logic isn't needed for the final version as it will mainly be used in a book I'm co-authoring with Rendezvous architect Stuart Cheshire. The code that makes the example a better tictactoe game gets in the way of the code that expresses what it is that Rendezvous is doing. So I ripped it out.

The magic was that I could easily rip out six classes and a couple hundred lines of code without fear that I'd ruined anything. I just ran my unit tests again and moved on. With the bar still running green, I had the confidence to delete the code that I had commented out. Along the way I also moved some files around and found that IntelliJ's Idea is a very smart tool. I moved a test class from one package to another and IntelliJ moved the line that calls the test class in the AllTests.java file of the first file to the correct line in the corresponding file in the other.

Is it too much to ask for a tool that does that with my real life items as well. I would love to be able to run a suite of tests and know that I can safely delete these thirty emails. Kimmy-the-wonderwife would love it if I had a tool that did the same for books, magazines, and papers I have stacked all over our third floor.

Unit tests/ TDD is the life changing practice for me from all of those proposed as part of XP. I'm working on how it might work in cleaning up other areas of my life.


In Also in Java Today Ashwin Jayaprakash knows he's sticking his neck out to call his article Towards Bug Free Code. But he's got some good practices to back it up - J2SE 5.0-based tricks for achieving code that is more loosely-coupled, and thus more readily testible. "If we make good use of some of the basic idioms and thumb-rules of design and programming, we can take a step closer towards software with a lot less bugs."

This article suggests that if your mission is to do the simplest thing possible, then using mock objects in unit testing may not be meeting these goals. In Unit Test More Efficiently with Mock Object Alternatives, he explains that his pseudo object " is definitely not a mock object. There are no methods defined above and beyond what is available on the interface. The pseudo doesn't remember any object state or verify anything during or after test execution; it simply throws an exception on any method call. Now, this is not necessarily a stub, because it is not providing any canned values that a test may use."


Steve Harris explains why he started the Mnemos Project in today's Weblogs. He asks " Have you ever longed for a simple way to persist Java objects; something along the lines of what Shelve/Pickle does for Python objects? Mnemos may be just what you've been looking for."

James Gosling thinks about Sharpen the Axe: the Dark Side . He worries that sometimes we can wander off and get lost sharpening the axe and never return to the problem at hand.

Michael Nascimento Santos continues his discussion of AOP in More about Practical AOP and Transparent Remoting He is answering questions about whether or not AOP makes applications more complex by masking the complexity.


In today's Forums, Bino George writes " AbsoluteLayout does more than just setting Layout to null. AbsoluteLayout may even accomodate for changes in font sizes etc. I know that the Swing team is working with the Netbeans team to provide enhancements to the Swing layouts so that building Swing UIs can be made easier and more intuitive.I have seen a demo of it and it seems very intuitive, almost like a graphics tool. Layouts are one of the most commonly complained about area because most
people find the exisiting layout managers complex and unintuitive."

Subnark raises issues of Iterable not Iterator . "Under the current symantics only classes which implement java.lang.Iterable may be used in a 'foreach' statement. Since all this interface requires is to return an Iterator, it would be nice if there was a special case for Iterator. I find that I end up with an iterator and not an Iterable often since I use legacy code that does not implement this interface, or I'm using a class which can be iterated in multiple ways."


Also featured in Projects and Communities, Kathy Walrath has pointed out on the Java Desktop community homepage that four JavaDesktop projects are #1 in the five categories measured. Congrats to lg3d and xhtmlrenderer.

The Global Education and Learning community features docclerc, an application with Tapestry, Spring, and Hibernate that is a coordinated publish and edit document system and automatic version control.


In today's java.net News Headlines :

Registered users can submit news items for the java.net News Page using our news submission form. All submissions go through an editorial review before being posted to the site. You can also subscribe to thejava.net News RSS feed.


Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. Also, once this page is no longer featured as the front page of java.net it will be archived along with other past issues in the java.net Archive.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds