Skip to main content

Starting Simple

Posted by daniel on January 21, 2004 at 5:08 AM PST

"Once we get something on the screen, we can look at it. If it needs to be more we can make it more. Our problem is we've got nothing."

In Bill Venner's interview in Also in Java Today , Ward cunning explains to Bill Venners what is meant by doing the simplest thing that could possibly work . The idea is to "focus on the goal. The goal right now is to make this routine do this thing. Let's not worry about what somebody reading the code tomorrow is going to think. Let's not worry about whether it's efficient. Let's not even worry about whether it will work. Let's just write the simplest thing that could possibly work."

We sometimes forget that "the simplest thing" is a very subjective notion. Perhaps case statements and nested if-else are the simplest way to code something up. Then you learn the State pattern and find that in some cases (but not in all cases) applying the State pattern is the simplest thing that works. In fact, it never seems to start that way. Even when you know the State pattern, your initial steps are often some control structure. As the complexity of what you are trying to code up grows, you may find that you can re-introduce simplicity with State. But all of this depended on you having some additional knowledge.

Ward makes the analogy to simplifying a complicated proof in mathematics with a new proof that "uses a branch of mathematics that you might have to study to master, but once you master that branch of mathematics you can use it. And a 20-page proof becomes a 10-page proof. You'd have to say it's simpler, because it's a shorter path. Maybe it's longer if you have to do a digression to actually learn a new branch of mathematics, but let's assume that over time we realize that this branch is important to know in general, so we all become familiar with it."

In other words, it may take a lot of work to make something simpler. Taking what you currently know as a given, Ward explains that "Coding up the simplest thing that could possibly work is really about this: If you can't keep five things in your head at one time and make a decision, try keeping three things in your head. Try keeping just one thing in your head, and see if you can make a decision. Then you can think of the next thing. And amazingly, when you write some of this dumb, straight-ahead code, it often turns out that it was all that was required. It works great."

Perhaps one of the techniques worth adding to your arsenal to help you introduce simplicity are mocks. In Mock Objects Made Easy , Crazy Bob writes "When writing unit tests with mock objects, there's no need to resort to specialized frameworks such as MockObjects. I find plain old Java combined with widely available IDE code generators to be much more effective." The entry provides several concrete examples of how to use Mocks when testing. Reader feedback argues that as his library grows he will have ended up recreating much of what is already provided in the MockObjects framework.

In today's Weblogs , Satya Komatineni provides A quick refresher on CSS selectors . His entry is a list of CSS elements you may want to use with a link to further description of these elements. He also links to more notes on CSS.

In Projects and Communities The MathUtils project in the Education and Research community provides implementations of Linear Algebra classes.The current contents of the File Sharing Directory include classes for calculating Cross Products and for working with mathematical Vectors and Complex Numbers.

The Jini community points to this posting about Grid Computing vs. JavaSpaces which asks "with the advent and promise of the Grid Computing [...] , is Grid Tech. going to push over the JavaSpaces".

In today's
News Headlines

Registered users can submit news items for the href=""> News Page using
our news submission
. All submissions go through an editorial review by news director
Steve Mallet before being posted to the site. You can also subscribe to
News RSS feed

Current and upcoming
Java Events

Registered users can submit event listings for the href=""> Events Page using our href=""> events submission
form. All submissions go through an editorial review before being
posted to the site.

Archives and Subscriptions: This blog is delivered weekdays as the
Today RSS feed
. All members can subscribe to the email
updates for the site at the href="">
java-net Mailing Lists page. You must be logged in to subscribe
the javanet_Daily and javanet_Weekly lists. Also, once this page
is no longer featured as the front page of
it will be archived along with other past issues in the href=""> Archive.