The Artima Developer Community
Sponsored Link

Weblogs Forum
The Simplest Thing That Could Possibly Work?

24 replies on 2 pages. Most recent reply: Jul 18, 2008 11:45 AM by Jim Knowlton

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 24 replies on 2 pages [ « | 1 2 ]
Don McCaughey

Posts: 7
Nickname: donmcc
Registered: Feb, 2006

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 3, 2008 5:46 PM
Reply to this message Reply
Advertisement
> > 1. Write a test
>
> assert !isPrime(1);
> assert isPrime(2);
> assert isPrime(3);
> assert !isPrime(4);

> > 2. Write the simplest code that makes all the tests
> pass
>
> boolean isPrime(long l) {
>    return l != 1 && l != 4;
> }

> > 3. Refactor
>
> Am I refactoring to make it less simple?
>
> > 4. goto 1 until you can't think of any more test cases for
> > your requirements
>
> That's going to take a while.

Well, at this point in your example, I would have a number of different directions I could go and questions to ask about my requirements.

One obvious area is how to handle input values less than 1: throw an IllegalArgument exception perhaps? Or maybe the caller should never pass me a negative value and an assert statement in the code might be better.

The more interesting thing to consider is whether to continue with a table driven approach, do a calculation for each input, or a hybrid approach (caching previously calculated values, or a table for a frequently queried range). Maybe your range of legal inputs is small and a table is the simplest thing that could possibly work.

A general use mathematical function with a single input like this doesn't illustrate TDD very well. Your first step in writing isPrime() should probably be to find a good algorithm in a trusted reference, not to write a test for each possible input value.

When you write unit tests for a function like this, you typically choose a few representative and interesting values (start and end values of your valid range, etc). Unit tests are there to give you confidence that your code does what you intended it to (and that changes while refactoring didn't break anything).

Don McCaughey

Posts: 7
Nickname: donmcc
Registered: Feb, 2006

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 3, 2008 6:58 PM
Reply to this message Reply
> I also love the 'possibly work' part. I personally
> prefer things that will 'definitely work' but that's
> just me I guess.

I think you're confusing "probably" with "possibly" ^_^.

> From your description, it doesn't solve any real problems
> so that would make it a cost with no benefits and
> therefore unwise. And trust me, I've seen over
> complicated designs. I've dug through some really crazy
> shit wondering why the 'experts' that wrote it didn't
> spent some time making the code actually work instead of
> creating functionality that was never used.

I think we're basically on the same page here. To me, the "simplest thing that could possibly work" means: don't build features that weren't asked for, don't create abstractions and layers that don't simplify your code overall, don't try to optimize your code without clear goals and real profiling and performance test results.

But I think some people confuse "simple" with "expedient" and/or "easy". Taking you database API example, if you needed to run some complex query that your API didn't support, the most expedient and easy thing would be to just splat some raw JDBC and SQL in the code. However, this would make your code overall less simple since you've now got a mish-mash of database code scattered around.

The "simplest thing that could possibly work" doesn't mean putting on blinders and not considering the bigger picture, but I think it also admonishes programmers not to write code so abstracted that you lose sight of your goals.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 3, 2008 10:08 PM
Reply to this message Reply
> The "simplest thing that could possibly work" doesn't mean
> putting on blinders and not considering the bigger
> picture, but I think it also admonishes programmers not to
> write code so abstracted that you lose sight of your goals.

You and I and probably most people who will read this understand that but I'm sure a lot of people don't. I guess there's no point in ranting on and on and I don't want you to think I'm projecting that on you. Thanks for humoring me.

John Zabroski

Posts: 272
Nickname: zbo
Registered: Jan, 2007

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 7, 2008 11:32 PM
Reply to this message Reply
> I don't know where this idea that test cases
> can define functionality came from but it's
> really annoying. I'm currently contending with
> a dogma that test cases are adequate functional
> specs.

Or that unit tests are the right model for test-driven development. I recently read (and plan to review) <i>Extreme Swing Testing</i>, which was published a month ago. The authors are devout XP practitioners, and the first chapter is pretty much a defense of XP and TDD. What they fail to understand is that I am not interested in debating that. What I was interested in learning is why unit tests are a good model for testing the view state at discrete events. To this end, they utterly failed, because a lot of their tests would have to be duplicated on a per-widget basis. The problem with view state is that it is composable and therefore you need some way to do fine-grained tests at the integration level to make sure the system starts and stays in a consistent state.

After considering unit testing a failure, I am not looking at things like NDepend and CQL.

There was also a recent debate on usenet://comp.object about what the appropriate granularity for a "unit" was. This also misses the point entirely, because it assumes that the fundamentally difficult thing about testing software is encapsulating the right stuff, rather than identifying/discovering constraints that improve quality.

John Zabroski

Posts: 272
Nickname: zbo
Registered: Jan, 2007

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 7, 2008 11:32 PM
Reply to this message Reply
er, now looking at things like NDepend and CQL.

Kazim Zaidi

Posts: 2
Nickname: kazim59
Registered: Jul, 2008

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 10, 2008 3:54 PM
Reply to this message Reply
James, what you're talking about is tolerance for code compression. As human programmers, we all have different tolerance for complexity in code. For a newbie, even simple is not simple. For an experienced developer, big systems appear to be simple. (and I'm talking with reference to my own level of experience :-P)

http://steve-yegge.blogspot.com/2008/02/portrait-of-n00b.html

However, I believe that after a certain amount of complexity, the system is complex for everyone. And that's real complexity. It is here where this catch-phrase gets its meaning.

It means, precisely, do not do complex things. Take simple steps to conquer the problem.

Otherwise, to take that catch-phrase literally means ruining your system, since often the simplest thing is simply not the best thing, requiring lots of rewrite in later phases.

Raoul Duke

Posts: 127
Nickname: raoulduke
Registered: Apr, 2006

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 10, 2008 7:52 PM
Reply to this message Reply
http://tech.groups.yahoo.com/group/leanprogramming/message/217

i thought it was decent food for thought.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 11, 2008 4:33 AM
Reply to this message Reply
The subject itself reminds me of the HelloWorld Java program of uncyclopedia.

http://uncyclopedia.org/wiki/Java

Also brings to mind the Spring vs J2EE debate. Clearly someone went through a major thought process to try and eliminate the complexity and ugliness of J2EE via Spring.

Jim Knowlton

Posts: 2
Nickname: jimknowlto
Registered: Jul, 2008

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 18, 2008 11:43 AM
Reply to this message Reply
I'd suggest that we go one further, and emphasize it as the simplest thing that could possibly work. When you think about it, what does it mean to work?

- To successfully compile?
- To run without crashing?
- To be well-designed?
- To be easily maintainable?
- To please users?

All these could be used as criteria for "working", given a particular context.

Jim Knowlton

Posts: 2
Nickname: jimknowlto
Registered: Jul, 2008

Re: The Simplest Thing That Could Possibly Work? Posted: Jul 18, 2008 11:45 AM
Reply to this message Reply
Sorry, my last post might not have been clear...I meant to write it as "the simplest thing that could possibly work"

Flat View: This topic has 24 replies on 2 pages [ « | 1  2 ]
Topic: Simplyfing Java Generics by Eliminating Wildcards Previous Topic   Next Topic Topic: Tim O'Reilly in China


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us