Home » Software Development » It’s a Bad Solution to a Problem We Don’t Have

About Ashley Frieze

Ashley Frieze
Software developer, stand-up comedian, musician, writer, jolly big cheer-monkey, skeptical thinker, Doctor Who fan, lover of fine sounds

It’s a Bad Solution to a Problem We Don’t Have

What’s the worst sort of code?

Don’t say JavaScript. It’ll grow on you.

Nope, not Perl either.

Ok, so Perl is quite irritating.

The Worst Sort of Code…

It’s code we don’t need… followed by code that almost works, and then code that doesn’t work.

Code that almost works is very annoying, because you won’t realise it doesn’t work at first.

Code that almost works and we don’t need… there’s the perfect storm.

High Minded Best Intentions

We all want to do the best job possible. The creative process of development is full of what-ifs, and wouldn’t-it-be-greats.

Sometimes the developer wants to go the extra mile. If you can do that cheaply and there’s a known up-coming requirement, then that’s lovely. Brilliant.

Indeed, sometimes it’s actually easier to solve the general case for all use cases, rather than solve the subset in front of us.

However, we have to be self-critical about the time and risk we place on a solution that’s few steps beyond the immediate requirements. This is sometimes because the all-singing-general-purpose solution can be much more complex, imply some tricky edge cases and… wait for it… not quite work.

This can be a case where the attempt to provide two solutions for the price of one can produce no fully working solutions to either problem.

Quick Example

Let’s imagine we receive input text in the format "A B C" where there is a space between every character and output text in the format "ABC" where there’s not. With the spacing the string "The cat" would become "T h e c a t".

We can easily make an algorithm to convert between these formats. No big deal. We can also employ the space adder or the space remover, depending on which format we expect to be dealing with.

Let’s say someone tries to make the converting algorithm detect if we have the interlaced spaced and automatically do the conversion to output format if necessary. That might be nice. We don’t have to have two entry points and the caller doesn’t need to know which format is which. Except… what of the string "A " – which format is that in?

By attempting to handle all possible inputs with general purpose method, we can make an unprocessable edge case possible.

Summary

The above is an extreme example of a bit of attempted sophistication backfiring. The general case is that it’s often wasteful to solve problems we don’t have, even more so if the solution we end up with cannot be made to work as well as a simpler solution to the problem we DO have.

Published on Java Code Geeks with permission by Ashley Frieze, partner at our JCG program. See the original article here: It’s a Bad Solution to a Problem We Don’t Have

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of