docstrings style question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Brown

    docstrings style question

    I've got a series of modules which look like this:

    #************
    #
    # Temperature Sense Test
    #
    #************
    class Test3(ar_test.A R_TEST):
    """Temperat ure Sense Test"""


    I don't like the duplicated information: But the comment is attractive, and
    the docstring self.__doc__ is already in use in the test log. I've read that
    all modules and classes should have docstrings, but I don't really have
    anything else to say, and each module contains only one class. I don't think
    that

    """Temperat ure Sense Test"""
    class Test3(ar_test.A R_TEST):
    """Temperat ure Sense Test"""

    would be a real improvement.

    What do you think?

    Steve.


  • Russ P.

    #2
    Re: docstrings style question

    On Jan 9, 9:47 pm, "Steve Brown" <st...@mhomer.a uwrote:
    I've got a series of modules which look like this:
    >
    #************
    #
    # Temperature Sense Test
    #
    #************
    class Test3(ar_test.A R_TEST):
    """Temperat ure Sense Test"""
    >
    I don't like the duplicated information: But the comment is attractive, and
    the docstring self.__doc__ is already in use in the test log. I've read that
    all modules and classes should have docstrings, but I don't really have
    anything else to say, and each module contains only one class. I don't think
    that
    >
    """Temperat ure Sense Test"""
    class Test3(ar_test.A R_TEST):
    """Temperat ure Sense Test"""
    >
    would be a real improvement.
    >
    What do you think?
    >
    Steve.
    I tend to be a bit skimpy with one-line comments for classes and
    methods, but I think a more complete (""" style) comment is often
    appropriate for the top of the file.

    I'm sure you can think of more to say than "Temperatur e Sense Test."

    What temperature? What kind of temperature sensor? What kind of test
    is it, and why are you doing it? That may all be obvious in context,
    but you've provided no context in your post. Also, if the module is of
    any significant size, you might want to provide a clue about who wrote
    it. Then, if someone has a question about it later, they will know who
    to ask.

    Comment

    • Fredrik Lundh

      #3
      Re: docstrings style question

      Steve Brown wrote:
      I've got a series of modules which look like this:
      >
      #************
      #
      # Temperature Sense Test
      #
      #************
      class Test3(ar_test.A R_TEST):
      """Temperat ure Sense Test"""
      >
      >
      I don't like the duplicated information: But the comment is attractive, and
      the docstring self.__doc__ is already in use in the test log. I've read that
      all modules and classes should have docstrings, but I don't really have
      anything else to say, and each module contains only one class. I don't think
      that
      >
      """Temperat ure Sense Test"""
      class Test3(ar_test.A R_TEST):
      """Temperat ure Sense Test"""
      >
      would be a real improvement.
      >
      What do you think?
      since you already seem to cater to your audience (clearly marked
      comments for people browsing the code, brief docstrings for the test
      log), I don't really see why you should change anything.
      I've read that all modules and classes should have docstrings
      if nobody's going to read them, there's no reason to add them. don't
      treat generic style advice as dogma.

      </F>

      Comment

      • Ryan Ginstrom

        #4
        RE: docstrings style question

        On Behalf Of Steve Brown
        What do you think?
        I think that comments are for maintainers, and docstrings are for users.

        Some of the things I use comments for:
        * Visually separate classes (using a syntax-highlighting editor)
        * Explain algorithm choices
        * Explain bug fixes so I don't later "fix" code back to the buggy version

        Some of the things I use docstrings for:
        * Describe interface (inputs/outputs)
        * Sample usage

        I personally don't use doctests, but that's one more use of docstrings.

        Regards,
        Ryan Ginstrom

        Comment

        • Martin Marcher

          #5
          Re: docstrings style question

          Russ P. wrote:
          On Jan 9, 9:47 pm, "Steve Brown" <st...@mhomer.a uwrote:
          >I've got a series of modules which look like this:
          >>
          >#*********** *
          >#
          ># Temperature Sense Test
          >#
          >#*********** *
          >class Test3(ar_test.A R_TEST):
          > """Temperat ure Sense Test"""
          >>
          >I don't like the duplicated information: But the comment is attractive,
          >and the docstring self.__doc__ is already in use in the test log. I've
          >read that all modules and classes should have docstrings, but I don't
          >really have anything else to say, and each module contains only one
          >class. I don't think that
          >>
          >"""Temperatu re Sense Test"""
          >class Test3(ar_test.A R_TEST):
          > """Temperat ure Sense Test"""
          >>
          >would be a real improvement.
          >>
          >What do you think?
          It's still duplicated information.
          I tend to be a bit skimpy with one-line comments for classes and
          methods, but I think a more complete (""" style) comment is often
          appropriate for the top of the file.
          >
          I'm sure you can think of more to say than "Temperatur e Sense Test."
          exactly my opinion
          What temperature? What kind of temperature sensor? What kind of test
          is it, and why are you doing it? That may all be obvious in context,
          but you've provided no context in your post. Also, if the module is of
          any significant size, you might want to provide a clue about who wrote
          it. Then, if someone has a question about it later, they will know who
          to ask.
          I tend to mention the main use cases for test classes (especially) and also
          a "human readable" description of what can happen (forgive me the missing
          line breaks). Something like this:

          class Test3(ar_test.A R_TEST):
          """Temperat ure Sense Test.
          This class assures that the connection to the hardware sensor can be
          established. It also checks a reference sensor that always reports a
          certain value so that one can be sure correct data values are reported.
          """

          hth
          martin

          --



          You are not free to read this message,
          by doing so, you have violated my licence
          and are required to urinate publicly. Thank you.

          Comment

          • Neil Cerutti

            #6
            Re: docstrings style question

            On Jan 10, 2008 12:47 AM, Steve Brown <steve@mhomer.a uwrote:
            I've got a series of modules which look like this:
            >
            #************
            #
            # Temperature Sense Test
            #
            #************
            class Test3(ar_test.A R_TEST):
            """Temperat ure Sense Test"""
            >
            >
            I don't like the duplicated information: But the comment is attractive, and
            the docstring self.__doc__ is already in use in the test log. I've read that
            all modules and classes should have docstrings, but I don't really have
            anything else to say, and each module contains only one class. I don't think
            that
            >
            """Temperat ure Sense Test"""
            class Test3(ar_test.A R_TEST):
            """Temperat ure Sense Test"""
            >
            would be a real improvement.
            >
            What do you think?
            I recommend a careful reading of PEP 257.

            You shouldn't waste your time creating (at best) decorative comments, like:
            #************
            #
            # Temperature Sense Test
            #
            #************
            class Test3(ar_test.A R_TEST):
            """Temperat ure Sense Test""

            Remember that comments have to maintained along with the rest of the
            code, so unnecessary ones just create more work for you. Any time you
            can replace a comment with self-explanatory code, you should.

            Here's a vast improvement:

            class TemperatureSens eTester(ar_test .AR_TEST):

            --
            Neil Cerutti <mr.cerutti+pyt hon@gmail.com>

            Comment

            • Steve Brown

              #7
              Re: docstrings style question


              "Neil Cerutti" <mr.cerutti@gma il.comwrote in message
              news:mailman.40 8.1199973821.89 6.python-list@python.org ...
              On Jan 10, 2008 12:47 AM, Steve Brown <steve@mhomer.a uwrote:
              >I've got a series of modules which look like this:
              >>
              >#*********** *
              >#
              ># Temperature Sense Test
              >#
              >#*********** *
              >class Test3(ar_test.A R_TEST):
              > """Temperat ure Sense Test"""
              >>
              >>
              >I don't like the duplicated information: But the comment is attractive,
              >and
              >the docstring self.__doc__ is already in use in the test log. I've read
              >that
              >all modules and classes should have docstrings, but I don't really have
              >anything else to say, and each module contains only one class. I don't
              >think
              >that
              >>
              >"""Temperatu re Sense Test"""
              >class Test3(ar_test.A R_TEST):
              > """Temperat ure Sense Test"""
              >>
              >would be a real improvement.
              >>
              >What do you think?
              >
              I recommend a careful reading of PEP 257.
              >
              You shouldn't waste your time creating (at best) decorative comments,
              like:
              #************
              #
              # Temperature Sense Test
              #
              #************
              class Test3(ar_test.A R_TEST):
              """Temperat ure Sense Test""
              >
              Remember that comments have to maintained along with the rest of the
              code, so unnecessary ones just create more work for you. Any time you
              can replace a comment with self-explanatory code, you should.
              >
              Here's a vast improvement:
              >
              class TemperatureSens eTester(ar_test .AR_TEST):
              >
              --
              Neil Cerutti <mr.cerutti+pyt hon@gmail.com>
              Yes, I'm working in that direction. At present there is still code that
              parses the test sequence to get the class name, but I'm rebuilding that.

              However, there will still be sufficient information for some of the tests
              to justify one doc string or comment as well as the class name.

              Is it possible to get from an object to a class module doc string?

              Something like self.class.modu le.__doc__ ?

              I'm not able to do an assignment inside the test class, because I have
              to keep that clean, but I can do assignments inside the parent test class.


              Steve


              Comment

              Working...