Thoughts on Complexity

In programming, there are many levels of complexity.  You can start of at a beginner level, where your barely grasping the language, and the correct syntax to use that language:

main(){
int i;
i=0;
for(i=0; i<4;i++){
   //do something
}
}
The programmer learns more by viewing more examples and tricks, and can eventually do more than they could before.  If the beginner programmer in them then looked at their more advanced code, much of it they wouldn’t understand the What and Why behind what they did:
typedef struct example{
    int counter;
    double storage[][];
};
main()
{
int returnval;
example phystruct1;
phystruct1.counter = 12;
returnval = processexample(phystruct1); //process the example
//more stuff
}
While this may be something that they would learn eventually, to a beginner or to someone inexperienced, who needs to look at the code, it can be quite daunting.  But the added complexity may not be required, and reduces the comprehension of the code.  In general, if code can be written to be simpler, it is better, provided that the simplicity doesn’t cause the code to suffer from inefficiencies.
I believe there is a balance that can be achieved between complexity and simplicity, between an experienced level and novice, and I believe that this extends past programming languages.  If you can make a car with fewer parts that are easy to find, then in general, you made a better car than one that is more complex.  If you can build a circuit with 5 parts rather than 20, then it would be simpler.
But it is not the case of fewer parts the better.  If your circuit with 5 parts costs more than the circuit with 20, then it should make you question the decision that resulted in the selection of those 5 parts.  Perhaps those parts are more robust and it is ‘worth’ the added expense.  Buying a $20 blender may be justifiable if it is expected to last a long time, but at what point do you buy the $2 blender?
Even though one may have more sophisticated/complex tools, languages, programming styles, etc.. doesn’t mean that those should be used.  One wouldn’t use a table saw to cut a pencil in half, just as one wouldn’t cut a 2×4 using a Dremel.  It comes down to the golden rule: keep it simple stupid (KISS).
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s