Sunday, November 13, 2005

Trade-off

One of my coding experiences has been that , writing code involves making a trade-off. But other people have figured that trade-off are also required in making decisions such as whether to fix a bug or not or even which features to include in a release and which to leave.

The article at above link also suggests that you need to be a good economist to make a trade-off( Since it is like an economics problem about optimizing about when given a set of resources). I think a mathematician would be better at doing it.
Check out the Dijkstra's article Programming as a discipline of mathematical nature

The article also has a small but excellent proof of why a program which has been divided into modules is likely to be more correct that a single monolitic program.
(Something that i thought was intutive can acutally have a proof surprised me).

Finally one of my own experiences in making a "trade-off"

Recently i had to design a lexical analyzer. A fairly straight forward problem , just use lex .But in my case there were several restrictions which ultimately forced me to write a hand written lexer.

One of the first decision i had to make was of input buffering.
There are several factors to decide
1. The size of buffer( some suggested that it should equal the page size of the machine ,other simply went for a large buffer say like 16K ).
2. To use double-buffering or single buffer.
3. How to code the use of buffer for maximum performance.

The amount of time spent by me in making above decisions exceeded the time i had budgeted for it by a factor of 10. But it was an ultimate learning experience.

My current understanding in how to make a trade-off is:
1. Consider all the factors and prioritize them ( for e.g. 1. Speed of code 2. Size etc. )
2. Less important factors can be usually "decided" with help of books and literature which explain other users experience.
3. Profile the performance of the algorithms for the most important factors and then choose the best algo/data structure

Point (3) can be a very time consuming step so you will have to make a trade-off based on no. of algo's/data structures you can profile and time you have :)

(since there are so many ideas about what a software engineer is, i think i will create my own definition someday)