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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/19/11 13:17
Read: times


 
#180706 - Problem with commenting too
Responding to: ???'s previous message
Good code should not contain source code comments telling what a source line does (unless the source is really "interesting" for some reason).

Good code should contain source code comments that explains why the code does what it does. Symbol names etc should be so carefully selected that you in almost all situations can look at the source line and know what it does without any comment.

But if you see a line "delay_us(5)" you do know what it does. You may not know how (using timer or assembler busy loop etc) but you must at least assume that it represents a 5us delay +/- some error margin. But the important thing is that it is impossible to know why there is a delay. And even harder to know why the value is 5 - what would be wrong with 3 or 12 us delay instead?

A beginner always spend his time explaining what a line does, totally duplicating the assembler or C code with the same expressed in english. That is so stupid that it hurts. Especially after two or three updates to the code, when suddenly the computer instructions and the english text says different things.

Good reference code should preferably be documented as we want the code documented. But that means that a web site focusing on "good code" may have to present the code twice.

Once as we want the code to look in a real project.

And a second time, broken down into blocks in a HTML page, where specific constructs in the code is commented on separately - possibly also showing alternative code sequences together with motivations why these alternatives wasn't used instead.

List of 37 messages in thread
TopicAuthorDate
Studying good code?            01/01/70 00:00      
   Apprenticeship            01/01/70 00:00      
      Always good to read code            01/01/70 00:00      
   I assume you write ...            01/01/70 00:00      
      Nice! :)            01/01/70 00:00      
   Becoming an "efficient firmware architect"            01/01/70 00:00      
      Professional training classes            01/01/70 00:00      
   A call to the 8052 community            01/01/70 00:00      
      Stumbling stone is commercialism            01/01/70 00:00      
      my initial offerings            01/01/70 00:00      
         Great!            01/01/70 00:00      
      A more fundamental problem            01/01/70 00:00      
         Hardware-specific vs. "good code".            01/01/70 00:00      
            source of inspiration            01/01/70 00:00      
               Intentionally bad vs. unintentionally bad?            01/01/70 00:00      
                  Hard to intentionally write really bad code            01/01/70 00:00      
                     why it's hard to write bad code...            01/01/70 00:00      
                        Standard mistakes.            01/01/70 00:00      
                           Brilliant link            01/01/70 00:00      
                     Bad code that actually works.            01/01/70 00:00      
                     it takes a genius            01/01/70 00:00      
         Good code for teaching            01/01/70 00:00      
            _More_ than just MISRA? *heartattack*            01/01/70 00:00      
            Pedagogical            01/01/70 00:00      
            and there's the rub            01/01/70 00:00      
               Problem with commenting too            01/01/70 00:00      
               Many hands make light work            01/01/70 00:00      
         Arduino            01/01/70 00:00      
            No need for reference hw            01/01/70 00:00      
               Beautiful Code            01/01/70 00:00      
                  There are lots of books on good coding practices ...            01/01/70 00:00      
                     And that was the OP's specific question!            01/01/70 00:00      
      Another Fundamental Tenet            01/01/70 00:00      
         Critisism            01/01/70 00:00      
   studying code ...            01/01/70 00:00      
      Even high-end embedded suffers            01/01/70 00:00      
         I agree, but            01/01/70 00:00      

Back to Subject List