The Source for Java Technology Collaboration
User: Password:



Chet Haase

Chet Haase's Blog

Patterns, Shmatterns

Posted by chet on August 08, 2003 at 06:30 PM | Comments (8)

Seeing as how this is my first blog, I thought it was reasonable to go on a complete tangent instead of spending my soapbox time rambling on about upcoming features and cool Java graphics things. Maybe I'll get into that stuff in a later column...

For years now, we've been hearing about how Patterns and Components will make our code much better, easier, reusable, etc. etc. etc. (etc.). But I have yet to see patterns or components created for the most commonly used and recreated things of all: bugs.

I find myself continually writing new code with completely new features, yet I invariably end up inserting the same type of bugs in it. There's the array overrun error (at least in native code). Then there's the "Whoops! I used the wrong local variable to dereference my data structure inside of this loop bug." There's the "I forgot to initialize that variable bug." Or the "I forgot to Unlock that thing that I had previously Locked" bug.

Think how much easier and better and cooler our code (and lives) would be if we no longer had to worry about creating these problems from scratch, but could just rely on standard patterns, or even reusable components to do them for us?

Efficiency: Coding time would be much less because I could just grab those objects at any time and jam them into my code without even thinking about it:
"I need to fail out of this loop right about here; what if I use the BadDereference pattern?"
Debugging: Debugging would be way faster. We wouldn't even have to use a debugger or analyze the code at all; we could simply glance at it and find the problems by inspection:
"I see you have a BadLoopVariableIncrementor pattern at work here. Let's try taking that out and see if the code works."
Management: Managers and program mangers would find it much easier to quantify programmers' productivity and effectiveness:
"My bugfinder script found 87 bugs in the 4 new files you've checked in. This is 6.7% more than last month; we need to make that number go down, not up."

Life will be so much better with BugPatterns and BugObjects. The promises of object reusability will finally come true; after all, what single object in the software world is more used than a bug?

And why do you think they called it Oops to begin with?

I'll get to work soon on these patterns, and then a library of BugObjects. I'll try to open source the project so that everyone can contribute. If we can get everyone to participate, then maybe we can nail the whole spectrum of bugs and we won't have to write any of our own bugs anymore!

First I have to finish working on my jdk1.5 features, which includes fixing various bugs. Man, if I could only fix them by grep'ing through the code for BugObject instances...

Chet.
(Currently working on 1.5 features and bug fixes, including new VolatileImage API and fixing various things related to hardware acceleration on Windows. Wish me luck.)


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

  • Would definitely save time... You're definitely onto something here, Chet. I've been trying to write bad code all day, and a BadCodeFactory would make things much easier. As it is now, I have to keep copying and pasting the same bugs by hand, which is annoying as well as error prone. I've been having to add catches for GoodCodeExceptions all over the place.

    Posted by: walendo on August 08, 2003 at 09:59 PM

  • IntelliJ IDEA and FindBugs FindBugs does something sort of like what you want -- I believe it even uses the phrase "bug pattern detector." It finds lots of very useful bugs by scanning the bytecode for bad patterns. (See http://www.cs.umd.edu/~pugh/java/bugs/ to download.) Also, IntelliJ IDEA has many features to reduce bugs while you're coding. Unused variables are highlighted, and the new early access builds highlight things inline like assignments that are never accessed (i.e., thrown away). (See http://intellij.com - or http://intellij.net for the (free) EAP builds.)

    Posted by: keithkml on August 09, 2003 at 12:26 PM

  • Would definitely save time... Walendo: The Factory pattern would be excellent in this context. I am also working on a BugStrategy pattern, in which you request a bug object, but do not care how that bug is implemented. I would probably have some variations on that, such as a MemoryBugStrategy and a TypoBugStrategy, so that you can request bug objects in certain BadCode domains.

    Posted by: chet on August 11, 2003 at 10:08 AM

  • IntelliJ IDEA and FindBugs Keith: I was actually trying to be completely facetious in this article, although the existence of bug-finding tools for non-facetious code is interesting. Thanks for the pointer.

    Posted by: chet on August 11, 2003 at 10:10 AM

  • OOPs indeed > And why do you think they called it Oops to begin with? Sounds more like Bizarr-OO to me: "Me am hate bugs! Me want to write lots and lots of them!"

    Posted by: uncle_alice on August 11, 2003 at 10:31 PM

  • IDEA IS an anti-bug pattern! Just want to second this, it is almost hard to write those common bugs with IDEA. If your code bugs out, it's normally the algorithm that are flawed. (Something for v5.0 ? Just an IDEA..) You can code for hours and your code compiles, and possibly works, the first time! And no, I don't work for IntelliJ. (yet ;-) Regards, Mikael

    Posted by: mgrev on August 12, 2003 at 01:42 AM

  • How will you categorize your up-coming book? I sense that you're on the verge of a breakthrough, and will probably have to write a book documenting these patterns (soon to be affectionately known a the Gang of One book). What categories will you use? Destructional - (AbstractMemoryCorruptor). Amorphic - Helps to introduce chaos and entropy into system (PseudoProxy). Misbehavioral - (InnocentBystander)?

    Posted by: d_bleyl on August 14, 2003 at 02:11 PM

  • How will you categorize your up-coming book? Excellent idea, although I can see this idea expanding into an entire series, perhaps with each book dedicated to a single pattern. these are so fundamental to software development that they deserve to be covered in excruciating detail. Some of the books, such as The InfiniteLooper Bug Pattern, could even become a non-ending series of their own. I'll get right on that... Chet.

    Posted by: chet on August 14, 2003 at 03:18 PM





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