Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/12/05 21:33
Read: times


 
#99315 - defensive coding how and why
some recent postings have made me think about posting the below, so here we go.

I am a great proponent of defensive coding, how?
1) there is no reason whatsoever to try to be "elegant".
2) if it does not look good in the debugger, rewrite it.
3) if you use "free code" load it in the debugger, work a bit with it, then throw it away. If you got an idea or two, great.
4) long ISRs are outlawed.
5) anything timing dependent that is not interrupt based is outlawed.
6) only the small memory model is legal.

I am a great proponent of defensive coding, why the above points?
1) "elegant" code is 10 times more buggy and 10 times more difficult to debug.
2) writing code is easy, reading code should be that too.
3) if you can not make "free code" lokk like yours it is more dangerous than helpful.
4) while such are possible OK they should only be resorted to after much research showing that no other method exist.
5) I have not had a need to break this rule, but otherwise see 4)
6) the large/huge etc model is very convenient, but "remembering" to make critical variable "data" is so much more error prone than to have to make some large arrays and buffers "xdata".

None of the above preclude well worked out code that is "right", sometimes it is, indeed, more demanding to write "defensive" code than "elegant" code. I think that it requires more skill to write "dull, working code" that "really smart code with only a few bugs".

The above does, indeed make the coding more dull, but as someone once said "they call it work, that is why they pay you for it".

Now, it is, of course, fun now and then to do some really fancy code, that's fine, just do not let the people that pay you suffer for that reason.

Erik

Ok, start arguing, I'll sit back and smile


List of 57 messages in thread
TopicAuthorDate
defensive coding how and why            01/01/70 00:00      
   What do you mean?            01/01/70 00:00      
      Elegant            01/01/70 00:00      
         Paradox?            01/01/70 00:00      
      clarification            01/01/70 00:00      
         Remember            01/01/70 00:00      
            Absolutely, and even then should be avoi            01/01/70 00:00      
            Absolutely, and even then should be avoi            01/01/70 00:00      
            extrodiaray?            01/01/70 00:00      
                extrodiaray?            01/01/70 00:00      
                  Goooooogle            01/01/70 00:00      
                     No, he does not            01/01/70 00:00      
                        proofreading            01/01/70 00:00      
                     Another challeneg            01/01/70 00:00      
                        another challenge            01/01/70 00:00      
               OK, I can not Spell            01/01/70 00:00      
                  this is my point            01/01/70 00:00      
                     I sure you could, But            01/01/70 00:00      
                        Really?            01/01/70 00:00      
                           professors and classes            01/01/70 00:00      
                           Really !            01/01/70 00:00      
                              Hmmm            01/01/70 00:00      
            defensive commenting            01/01/70 00:00      
         Don't know            01/01/70 00:00      
            Ok, let me get away from that word            01/01/70 00:00      
               Gotcha            01/01/70 00:00      
                  and I came to truly despise that word wh            01/01/70 00:00      
                     Just like driving            01/01/70 00:00      
            Elegant equals...            01/01/70 00:00      
               that it            01/01/70 00:00      
               Oh, how true...!            01/01/70 00:00      
                  It's never the author's problem            01/01/70 00:00      
                     I knew a person who told me about a real            01/01/70 00:00      
                        A blissful existence            01/01/70 00:00      
                  Your bugs versus my bugs (or vice versa)            01/01/70 00:00      
                     common wisdom has it that the average pr            01/01/70 00:00      
   One exception            01/01/70 00:00      
      exceptions            01/01/70 00:00      
         vice versa            01/01/70 00:00      
            what is obvious            01/01/70 00:00      
               your mileage may vary            01/01/70 00:00      
                  that is the very same            01/01/70 00:00      
                     competent            01/01/70 00:00      
                        please define "working"            01/01/70 00:00      
                           competent programming => working program            01/01/70 00:00      
   i'm new            01/01/70 00:00      
      if you move your eyeballs a bit to the l            01/01/70 00:00      
         Coding Bible            01/01/70 00:00      
            Precedence vs. explicitness            01/01/70 00:00      
   Outlaw coding!            01/01/70 00:00      
      a program it is, by definition, asynchro            01/01/70 00:00      
         Methinks the point was missed            01/01/70 00:00      
            "Easy?"            01/01/70 00:00      
            but we agree            01/01/70 00:00      
      VIPER?            01/01/70 00:00      
      What does "timing" mean?            01/01/70 00:00      
         excuse the foreigner, if he was not clea            01/01/70 00:00      

Back to Subject List