by Sean McGrath
Software

Premature parameterization is the square root of all evil

October 21, 2008, 10:28 AM — 

Almost all software - regardless of its function in life - involves using computer code to operate on data. Sometimes (rarely) there is no data at all. Sometimes (not so rarely these days) the data is, itself, code.

In general, the relationship between the code and the data features a split on the data side. Some of the data is end-user, application data and some of it is configuration data. The configuration data is very interesting because the functionality of any application software is a function of how the code and the configuration data inter-relate.

In the trade, we often call it parameterization. We spend time finding the parts of the application that do not need to be "wired" into inviolate computer code and instead, we read those parameters from data files. The term "soft coding" is often used to describe this idea.

When I say that "we spend time" on parameterization I'm afraid that I often see that time spent sub-optimally - to the detriment of software development projects. To illustrate, lets take a simple example from mathematics. Mathematics is a great place to look when looking for examples of generalization done right. Mathematics is essentially all about patterns: finding them, notating them, exploiting them and, most powerfully of all, generalizing them.

Let us take the example of finding the square root of a number. How does a mathematician think about such a problem? Without a moment's thought the mathematician thinks about the more general problem of the N'th root. If you can figure that out, a solution for N = 2 just drops out of the more general solution. If you are in luck, to quote Polya, you may even find that the more general problem is easier to solve.

Now the parameterization here, from a software perspective, looks obvious. Instead of wiring 2 into your code you work with N and then your parameterization provides 2 or 7 or whatever as required. However, it is remarkable to me how many times the obvious parameterization turns out to be sub-optimal. To continue the square root example. Maybe your applications is manipulating equations? Well. mathematicians - the kings and queens of generalization - long ago figured out that square roots are just a special case of a more general concept of a Polynomial equation. If you can solve Polynomial equations, then all your square roots and cube roots just drop right out as mere special cases.

I often find myself cautioning developer to resist the very strong urges that come early in a project, to nail the parameterization and start slurping up configuration files. Like code optimization, it is often the case that waiting is the best strategy. With optimization, its important not to do it too early because your ideas about where the hotspots are, tend to be off base - often wildly so. You need to gather performance metrics to be sure and of course, to do that you need a reasonably complete application. Mantra: make it work, then worry about making it work fast.

Similarly with parameterization. Until the application is more fleshed out it is difficult to predict what the most potent form of parameterization will be. Mantra: make it work with wired in data. Then, worry about how best to parameterize it. More often than not you will find that your first instincts about parameterization have evolved considerably.

I like it!
Comments

You mean "polynomial", not "Diophantine"

Diophantine equations are ones for which integer (or rational) solutions are sought. Since the square (or nth) root is typically not an integer, this is not a generalization of the original problem. In fact, since it is known that there is no algorithmic solution to general Diophantine equations (Hilbert's 10th problem), making such a generalization would be counterproductive even if it were appropriate. Finding the roots of a polynomial is valid generalization, and there are efficient algorithms for doing so.

P.S. You misspelled Polya's name.
| reply

Anonymous, Mea culpa. Both

Anonymous,

Mea culpa. Both fixes will be applied.

Sean
| reply
Free books

Build your tech library with our book giveaways.

Hacking Exposed, Sixth Edition
By Stuart McClure, Joel Scambray, George Kurtz; Published by McGraw-Hill/Osborne

The original Hacking Exposed authors rejoin forces on this tenth anniversary edition to offer completely up-to-date coverage of today's most devastating hacks and how to prevent them. Using their proven methodology, the authors reveal how to locate and patch system vulnerabilities. The book includes new coverage of ISO images, wireless and RFID attacks, Web 2.0 vulnerabilities, anonymous hacking tools, Ubuntu, Windows Server 2008, mobile devices, and more. Enter now!

Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace