471,348 Members | 1,150 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

docstrings style question

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

#************
#
# Temperature Sense Test
#
#************
class Test3(ar_test.AR_TEST):
"""Temperature 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

"""Temperature Sense Test"""
class Test3(ar_test.AR_TEST):
"""Temperature Sense Test"""

would be a real improvement.

What do you think?

Steve.
Jan 10 '08 #1
6 1079
On Jan 9, 9:47 pm, "Steve Brown" <st...@mhomer.auwrote:
I've got a series of modules which look like this:

#************
#
# Temperature Sense Test
#
#************
class Test3(ar_test.AR_TEST):
"""Temperature 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

"""Temperature Sense Test"""
class Test3(ar_test.AR_TEST):
"""Temperature 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 "Temperature 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.
Jan 10 '08 #2
Steve Brown wrote:
I've got a series of modules which look like this:

#************
#
# Temperature Sense Test
#
#************
class Test3(ar_test.AR_TEST):
"""Temperature 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

"""Temperature Sense Test"""
class Test3(ar_test.AR_TEST):
"""Temperature 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>

Jan 10 '08 #3
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

Jan 10 '08 #4
Russ P. wrote:
On Jan 9, 9:47 pm, "Steve Brown" <st...@mhomer.auwrote:
>I've got a series of modules which look like this:

#************
#
# Temperature Sense Test
#
#************
class Test3(ar_test.AR_TEST):
"""Temperature 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

"""Temperature Sense Test"""
class Test3(ar_test.AR_TEST):
"""Temperature 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 "Temperature 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.AR_TEST):
"""Temperature 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

--
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

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

Jan 10 '08 #5
On Jan 10, 2008 12:47 AM, Steve Brown <st***@mhomer.auwrote:
I've got a series of modules which look like this:

#************
#
# Temperature Sense Test
#
#************
class Test3(ar_test.AR_TEST):
"""Temperature 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

"""Temperature Sense Test"""
class Test3(ar_test.AR_TEST):
"""Temperature 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.AR_TEST):
"""Temperature 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 TemperatureSenseTester(ar_test.AR_TEST):

--
Neil Cerutti <mr***************@gmail.com>
Jan 10 '08 #6

"Neil Cerutti" <mr********@gmail.comwrote in message
news:ma************************************@python .org...
On Jan 10, 2008 12:47 AM, Steve Brown <st***@mhomer.auwrote:
>I've got a series of modules which look like this:

#************
#
# Temperature Sense Test
#
#************
class Test3(ar_test.AR_TEST):
"""Temperature 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

"""Temperature Sense Test"""
class Test3(ar_test.AR_TEST):
"""Temperature 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.AR_TEST):
"""Temperature 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 TemperatureSenseTester(ar_test.AR_TEST):

--
Neil Cerutti <mr***************@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.module.__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
Jan 11 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sridhar R | last post: by
reply views Thread by Craig Ringer | last post: by
2 posts views Thread by Steven Bethard | last post: by
6 posts views Thread by Kamilche | last post: by
reply views Thread by Edward Loper | last post: by
12 posts views Thread by jelle | last post: by
reply views Thread by tjhnson | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.