Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Over-documentation

Over-documentation

Scheduled Pinned Locked Moved The Weird and The Wonderful
performance
25 Posts 16 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Ron Beyer

    This is from another forum I visit once in a while, somebody posting a code snippet:

    void loop(){
    byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
    byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
    rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

    if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
    {
    switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
    // 'switches' based on that byte
    {

    And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

    C Offline
    C Offline
    CPallini
    wrote on last edited by
    #15

    Ron Beyer wrote:

    At least we know what the 'compiler' is doing when you declare a variable

    Sure, we need certainties, after all! :laugh:

    Veni, vidi, vici.

    1 Reply Last reply
    0
    • R Ron Beyer

      This is from another forum I visit once in a while, somebody posting a code snippet:

      void loop(){
      byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
      byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
      rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

      if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
      {
      switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
      // 'switches' based on that byte
      {

      And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #16

      Ron Beyer wrote:

      At least we know what the 'compiler' is doing when you declare a variable

      Actually, it's not even accurate, technically. The compiler doesn't allocate "some memory", it reserves space on the stack when the function is called. Yes, the stack is of course memory, but it's not the same kind of memory one uses when allocating / deallocating. Marc

      Day 1: Spider Database Navigator Unit Testing Succinctly

      1 Reply Last reply
      0
      • R Ron Beyer

        This is from another forum I visit once in a while, somebody posting a code snippet:

        void loop(){
        byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
        byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
        rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

        if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
        {
        switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
        // 'switches' based on that byte
        {

        And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

        W Offline
        W Offline
        Worried Brown Eyes
        wrote on last edited by
        #17

        Lovely Not only way over the top, but where comments would be useful, those comments aren't. I would only put 1 comment in there - //254 means we are about to process a command, so read one & process it. Plus a comment to add a description of each entry in the switch statement to translate the number into something sensible. This removes clutter, and also the need to look up op-codes in the event of brain-fade. Regards, Stewart

        R 1 Reply Last reply
        0
        • W Worried Brown Eyes

          Lovely Not only way over the top, but where comments would be useful, those comments aren't. I would only put 1 comment in there - //254 means we are about to process a command, so read one & process it. Plus a comment to add a description of each entry in the switch statement to translate the number into something sensible. This removes clutter, and also the need to look up op-codes in the event of brain-fade. Regards, Stewart

          R Offline
          R Offline
          Ron Beyer
          wrote on last edited by
          #18

          All of those can be solved with compiler constants, for example: #define CMDSTART 254 #define READCMD 1 #define WRITECMD 2 etc... Which also eliminates "magic numbers" and makes the program more maintainable.

          1 Reply Last reply
          0
          • R Ron Beyer

            This is from another forum I visit once in a while, somebody posting a code snippet:

            void loop(){
            byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
            byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
            rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

            if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
            {
            switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
            // 'switches' based on that byte
            {

            And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

            S Offline
            S Offline
            StM0n
            wrote on last edited by
            #19

            So... I guess, there's a comment like

            //Captain Obvious was here. Obviously.

            (yes|no|maybe)*

            1 Reply Last reply
            0
            • P PIEBALDconsult

              "the the code"

              M Offline
              M Offline
              Max Methot
              wrote on last edited by
              #20

              Reminds me of this! [^]

              P 1 Reply Last reply
              0
              • M Max Methot

                Reminds me of this! [^]

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #21

                The first time I saw something like that said "Paris in the / the spring". I saw this[^] sign a couple of weeks ago at http://en.wikipedia.org/wiki/Painted_Rocks_(Arizona)[^]

                1 Reply Last reply
                0
                • R Ron Beyer

                  This is from another forum I visit once in a while, somebody posting a code snippet:

                  void loop(){
                  byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                  byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                  rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                  if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                  {
                  switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                  // 'switches' based on that byte
                  {

                  And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                  R Offline
                  R Offline
                  Rob Grainger
                  wrote on last edited by
                  #22

                  Amusingly, that doesn't really tell us much - the compiler doesn't "allocate" memory, the stack is allocated when the program starts - this simply updates stack pointers.

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                  1 Reply Last reply
                  0
                  • R Ron Beyer

                    This is from another forum I visit once in a while, somebody posting a code snippet:

                    void loop(){
                    byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                    byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                    rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                    if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                    {
                    switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                    // 'switches' based on that byte
                    {

                    And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                    V Offline
                    V Offline
                    Vasudevan Deepak Kumar
                    wrote on last edited by
                    #23

                    Over-zealous on the documentation part but missed out some basic coding standards like below: 1) Magic Strings/Numbers in code. 2) It would be better to have the value of serial_getch() assigned in a variable and then used in switch instead of calling it directly as a function in the switch construct.

                    Vasudevan Deepak Kumar Personal Homepage You can not step into the same river twice.

                    1 Reply Last reply
                    0
                    • R Ron Beyer

                      This is from another forum I visit once in a while, somebody posting a code snippet:

                      void loop(){
                      byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                      byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                      rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                      if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                      {
                      switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                      // 'switches' based on that byte
                      {

                      And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                      I Offline
                      I Offline
                      imagiro
                      wrote on last edited by
                      #24

                      Probably he had a boss who complained about insufficient comments - like my boss often does when reviewing my code complains about missing annotations (just review annotations, the code was already commented properly). So I did more or less the same like our guy here - and my boss was happy. He didn't get that it was supposed to be ironic...

                      1 Reply Last reply
                      0
                      • R Ron Beyer

                        This is from another forum I visit once in a while, somebody posting a code snippet:

                        void loop(){
                        byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                        byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                        rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                        if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                        {
                        switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                        // 'switches' based on that byte
                        {

                        And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                        L Offline
                        L Offline
                        Lutoslaw
                        wrote on last edited by
                        #25

                        No horror here if it was posted to someone who's not into programming. E.g. "==" operator is not obvious and may provoke questions what does it mean. Also, telling about "allocating" memory is more understandable that introducing to how stack and pointers work.

                        Greetings - Jacek

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups