Every minute invested in planning, saves you 10 in implementation

I have no idea who came with this statistic, but I can confirm that it is true !

 

The example below doesn’t want to explain how to search for strings nor how to use TDD, but to demonstrate that a bit of planning in advance can really speed things up!

 

I was in need of a way to search in a pretty complex data structure for a complicated string (letters, numbers, symbols), but not by doing an exact search. Instead I was looking like a search similar to how humans apply a “looks like” algorithm.

So, I was trying to implement some heuristics.

 

Having TDD (Test Driven Development) in mind, I created a test program and I was planning to enhance the algorithm while I was feeding it with values.

So, I immediately identified a few patterns that were rather trivial to implement and without thinking too much, I actually started to implement them.

 

How useless !

After more than 30 min of implementing, I started to scratch my head because I was identifying more and more cases that didn’t match those patterns. Needless to say, my TDD-like attempt failed miserably! (Yes, I know, TDD, is more complex than this)

 

Pretty nervous, I closed the computer and took a piece of paper.

I started to write down what I want to achieve in the first place:

Search for a string in the data structure by identifying strings that “look like” the string I need.

Then I identified the actors:

STRING                                           DATA STRUCTURE(DS)

Below each of them I wrote examples of possible values.

The problem was that in some cases, the given STRING was much bigger than the strings in the DS, even if they were looking alike. They contained too much additional data (context) that I didn’t need. My first approach (when doing TDD) was to remove the extra data, but this proved to be too complex.

After less than 10 minutes of analyzing the possible input data, it struck me:

Instead of trying to reduce the long STRING so that I always can compare it with the values stored in the DS, why not comparing the values in the DS with the STRING?

Well, this covers… about 50% of my values. Fortunately, the first method, compare STRING with each element in DS, covers the rest 50%.

So, I wrote 1/2 line of code and I solved the problem in 30 seconds.

Compare this with more than 30 min of writing code.

 

Conclusion:

Plan in advance, do not assume, even if you are sure about something.

Even the simplest things can be solved sometimes easier if you just looks at them from another perspective.

 


© Copyright 2015 Sorin Mustaca, All rights Reserved. Written For: Sorin Mustaca on Cybersecurity

Check www.mustaca.com for the IT Consulting services I offer.
Visit www.itsecuritynews.info for latest security news in English
Besuchen Sie http://de.itsecuritynews.info für IT Sicherheits News auf Deutsch

About the Author

Sorin Mustaca

Sorin Mustaca, (ISC)2 CSSLP, CompTIA Security+ and Project+, is working since year 2000 in the IT Security industry and worked between 2003-2014 for Avira as Product Manager for the known products used by over 100 million users world-wide. Today he is an independent IT Security Consultant focusing on Cybersecurity, secure software development and security for IoT and Automotive. He is also running his personal blog Sorin Mustaca on Cybersecurity and is the author of the free eBook Improve your security .

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close