
Dead weight
As every developer will tell you, when you build the application you can create a debug-version of the app. This has extra code added in that provides ongoing telemetry so that, if the application fails, the developer can see where, why and when the crash occurred.
Before the application is delivered to the users the debug code is removed making the application smaller, faster and it consumes fewer of those precious cpu-cycles.
That is the code debugger. What about the human debugger?
A big chunk of every application is code that will never be executed. This is code that is designed to help the users when they make an error. This code is the validation statements and actions and the compensating code to unwind changes that now cannot be committed.
A customer told me recently that they have to complete a form with six entries, one of which is pre-filled. They have to fill in this form, perhaps, once a month. The data is usually the same each time it is completed. This, to them, was tedious and in need of automation. Processing thousands of forms might seem as though something was being achieved but the real work is in dealing with the exceptions.
So what does this mean for computing?
Here is a the first program I ever wrote. It is in FORTRAN. It calculates the area of triangle using the semi-perimeter method.
PROGRAM main C This program calculates the area of a triangle using C the Semi-Perimiter method C C By Kevin Parker C C Area = SQRT( SP (SP - A) * (SP - B) * (SP - C) ) C SP = (A + B + C) /2 C Variable definitions REAL sidea, sideb, sidec, sp, aot INTEGER n C Get the lengths of the three sides WRITE (unit=*, fmt=1001, advance="no")"Enter length of A: " READ (unit=*, err=91, fmt=1002) sidea WRITE (unit=*, fmt=1001, advance="no")"Enter length of B: " READ (unit=*, err=92, fmt=1002) sideb WRITE (unit=*, fmt=1001, advance="no")"Enter length of C: " READ (unit=*, err=93, fmt=1002) sidec C Validate the data IF (ABS(0.0 - sidea) < 0.000001) THEN PRINT *, 'Invalid triangle: length of side A is zero' STOP END IF IF (ABS(0.0 - sideb) < 0.000001) THEN PRINT *, 'Invalid triangle: length of side B is zero' STOP END IF IF (ABS(0.0 - sidec) < 0.000001) THEN PRINT *, 'Invalid triangle: length of side C is zero' STOP END IF IF (sidea < 0) THEN PRINT *, 'Invalid triangle: length of side A is negative' STOP END IF IF (sideb < 0) THEN PRINT *, 'Invalid triangle: length of side B is negative' STOP END IF IF (sidec < 0) THEN PRINT *, 'Invalid triangle: length of side C is negative' STOP END IF IF (sidea > sideb + sidec) THEN PRINT *, 'Invalid triangle: A is > than lengths of B + C' STOP END IF IF (sideb > sidec + sidea) THEN PRINT *, 'Invalid triangle: B is > than lengths of C + A' STOP END IF IF (sidec > sidea + sideb) THEN PRINT *, 'Invalid triangle: C is > than lengths of A + B' STOP END IF C Calculate the area sp = (sidea + sideb + sidec) / 2.0 aot = (sp * (sp - sidea) * (sp - sideb) * (sp - sidec)) ** 0.5 C And the result is WRITE (unit=*,fmt=1003) "Area of triangle ", sidea, ", ", sideb, & ", ", sidec, " is ", aot STOP 91 PRINT *, 'Invalid data entered for side A' STOP 92 PRINT *, 'Invalid data entered for side B' STOP 93 PRINT *, 'Invalid data entered for side C' STOP 1001 FORMAT(a) 1002 FORMAT(f6.2) 1003 FORMAT(a,f6.3,a,f6.3,a,f6.3,a,f8.3) 1004 FORMAT(a,f9.6,a) 1005 FORMAT(a,i8,a) END PROGRAM main
Notice how much of the code is in red? All that code is code that, in the normal course of events, will never be executed. Once the user knows how to use the application they don’t make data entry errors so why validate the data.
In fact in this simple application the extra code increases the executable size by 10% and the run time by 40%. And the cpu cycles consumed to run are also increased by 40%.
Imagine telling your boss you can save 40% of the cpu cycles on your processors. And what if everything ran 40% faster. How much would that improve the user’s satisfaction with the system?
So am I advocating ripping out the validation code? No, not really. What I am proposing is that we might design the application such that it detects the user and determines if the user is an advanced one or a novice. If the user is an expert skip all the validation, if they’re a novice test everything until they become an expert.
Just a thought.
Thank you for sharing. Great content.