473,378 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

docstrings vs language comments

When writing a python library, we can use docstrings for methods and
functions that are part of API. But what about comments for non-API
objects or python application code?

For applications, docstrings are not really much useful. Instead
language comments are prefered for them.

Language comments (starting with #) are usually considered to be a
little more readable than docstrings (when reading the source code for
understanding it).

So for non-API objects language comments will be prefered.

Thoughts?
Jul 18 '05 #1
2 3365

"Sridhar R" <sr*************@yahoo.com> wrote in message
news:93**************************@posting.google.c om...
When writing a python library, we can use docstrings for methods and
functions that are part of API. But what about comments for non-API
objects or python application code?
To my mind, docstrings are for saying how to use a module/class/function
(what is does and i/o specs) while comments are for saying how it does it
(the algorithm, which could change without changing the interface).
For applications, docstrings are not really much useful. Instead
language comments are prefered for them.
Docstrings and comments are for the benefit of programmers who use and
revise the code, not for non-programmers ultimate users. I don't see much
difference in this respect between a library function and a specific
application function.
Language comments (starting with #) are usually considered to be a
little more readable than docstrings (when reading the source code for
understanding it).
I think I personally prefer and find it easier to read docstring material
(as defined above) if it is consistently in docstring format.
So for non-API objects language comments will be prefered.

Thoughts?


You are entitled to your different opinions, but stating them as facts does
not change their status as opinions ;-).

Terry J. Reedy
Jul 18 '05 #2

There was a thread similar to this almost two weeks ago. While the
advantages of using docstrings is obvious, I remember commenting about
some of the typically minor disadvantages of docstrings which seem
consistent with your belief that hash-sign comments might be better
suited for stand-alone applications:

---
The only perceived disadvantages that I'm aware of occur when you don't
use the -OO flag. Docstrings end up in frozen executables and .pyc
files, visible through the use of the "strings" command (which is a
problem for people who think the information is hidden from the binary
file like a comment). The binary files are also ever so slightly larger
when docstrings are used instead of comments. However, using -OO
removes docstrings in addition to applying optimizations...the frozen
executable or resulting .pyo files have no docstrings and are a bit smaller.
---
If you use a hash-sign comment, you're guaranteed that it won't be in
the binaries, which is a big advantage to some if that comment contains
highly sensitive documentation.
---

-Rick Ratzel
Sridhar R wrote:
When writing a python library, we can use docstrings for methods and
functions that are part of API. But what about comments for non-API
objects or python application code?

For applications, docstrings are not really much useful. Instead
language comments are prefered for them.

Language comments (starting with #) are usually considered to be a
little more readable than docstrings (when reading the source code for
understanding it).

So for non-API objects language comments will be prefered.

Thoughts?

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steven Bethard | last post by:
I have two classes that implement the same interface, e.g. something like: class C(object): def foo(self): """Foo things""" ... def bar(self): """Bar things""" ... def baz(self):
6
by: Kamilche | last post by:
I have a large project that is getting complex, and I would like to print the docstrings without importing the modules. The only Python utility I could find references is apparently defunct and...
0
by: Edward Loper | last post by:
Epydoc 3 supports extracting information about Python modules by parsing. As a result, it can extract "docstrings" for variables. There are several possible ways these docstrings could be...
40
by: Edward Elliott | last post by:
At the risk of flogging a dead horse, I'm wondering why Python doesn't have any multiline comments. One can abuse triple-quotes for that purpose, but that's obviously not what it's for and doesn't...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: Richard Buckle | last post by:
Hi fellow Pythonistas, I've been using Python in anger for some time, and I must say, as I wrote in <http://macprang.sourceforge.net/>: "It's refreshing beyond words to use a language that so...
1
bartonc
by: bartonc | last post by:
You will be rewarded sooner than you think when you use docstrings to document your classes and functions. Whether you ever intend to publish your work or not, docstrings will help you in several...
1
by: Ant | last post by:
Hi All, I'm looking to provide online python documentation for several jython modules: does anyone know if there are tools to create documentation from docstrings that work in Jython? Jython...
6
by: Steve Brown | last post by:
I've got a series of modules which look like this: #************ # # Temperature Sense Test # #************ class Test3(ar_test.AR_TEST): """Temperature Sense Test"""
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.