Can you give a concrete example instead of an abstract one? It would be good to see how you are trying to comment your code and why this concept of "sub comments" is necessary.
Also, I am not sure if it's a PEP thing or not, but it's at least my opinion that you should avoid arbitrary comment "styling", like doing #####---- and what not. Especially in the middle of function bodies. There was a point in my earlier python career when I followed others examples of doing it to separate classes and free functions within the module, but now I find it annoying. It's quite noisy, and would be even noisier to find within a function body. And to me it would seem like if you need that kind of separation between so many blocks, that maybe the function is too big and should be refactored? Is the function possibly doing too much work, which requires you to visually break them down in comments?
Justin
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8d11364b-74aa-4e17-ace4-aeeb5cc26989%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sounds like a typical usecase for docstring along with line comment.
def my_function():
"""Short description of function
Longer description, with argument signature and return type etc
related to the function overall.
"""
# Line comment, related to upcoming line or series of lines.
code here
This, along with “cyclomatic complexity“, in particular about keeping functions small, should encourage short and concise code.
Was this what you meant?
yes, this is a specific example extracted from my last post
https://pastebin.com/te0EEAeC
So in the example, the main comments are the ones beginning with # // The main comment
I feel that I can visualize better the body of the code with # // The main comment
And then the sub comments would be the ones just like # The subcomment
For me, it helps reading the code, but I guessI should not create my own comment symbol..
Marcus, usually I do the doc string comment after the methods. But again, it might be completely irrelevant but instead of using """ """ I use ''' ''' and I don´t jump a line.
It looks more compact. But I guess I should follow PEP event if I have other point of view.
Justin, I read once that if you need to do the kind of comments that I do, or put inside the code a divider like # -------------------------------------------# it is because you should be using
more functions, and not putting everything inside of the same function.
I have seen codes like that, with 25 functions or more. But many of those functions had inside 10 or less lines of code. Doesn´t it make it more confusing with so many functions?
Also, I recently started studying c++, and it seems that they don´t care as much about all this kind of things.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/39a72965-9d40-45d9-a66c-5eb5b049253c%40googlegroups.com.
def complex(real=0.0, imag=0.0):
"""Form a complex number.
Keyword arguments:
real -- the real part (default 0.0)
imag -- the imaginary part (default 0.0)
"""
if imag == 0.0 and real == 0.0:
return complex_zero
I am trying to convince my self to use this, but it I dont like it.
Why not
def complex(real=0.0, imag=0.0):
"""
Form a complex number.
Description: This script does this and that
and other stuff
Status: work in progress
Extra notes: need to implement something somewhere
Author: some guy
"""
if imag == 0.0 and real == 0.0:
return complex_zero
I don´t want to bore you again with the same questions. I try to follow every universal convention, I just
don´t understand why in the first line I should begin intermediately after """ and then jump a line, and then the last line alone """
For instance, I do understand how 80 char per lines reads better, and that I should not create my own style, but this docstring style. I don´t know
R
I just don´t understand why in the first line I should begin intermediately after “””
Conventions such as these enable external tools to operate on your docstring and make certain assumptions, such as what types arguments expect and their description. The first line is typically reserved for a summary of the docstring, and having it on the first line provides two advantages that, aside from tools, I sometimes benefit from myself.
def my_function():
"""First line
Subsequent lines
are here.
"""
summary = my_function.__doc__.split("\n")[0]
print(summary)
# Try putting the summary on the next line
Some tools assume the first line is your summary (such as Sphinx), but if you aren’t using those tools or making tools yourself that depend on this convention, it probably isn’t the end of the world if you go with what you prefer.
Speaking of preference, tools such as Sphinx and docstring conventions, there is another player on the block that I personally prefer.
The important bit I think is that you find something you like that (1) remains consistent, (2) isn’t entirely alien to others (like us) if you want others to read it and (3) works with the tools you would like to use, such as Sphinx.
def my_function():
"""First line
Subsequent lines
are here.
"""
summary = my_function.__doc__.split("\n")[0]
print(summary)
That make more sense now. I´ll do it like that.
I am not sure about leaving a blank line between in the end of the doc string . According to PEP 8 it should be like this right?
def my_function():
"""First line
Subsequent lines
are here.
"""
summary = my_function.__doc__.split("\n")[0]
print(summary)Anyway, I am becoming a style freak when there are so many thing I need to learn yet.
So yes, I´ll stick with those conventions. Thx Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/bf4a6d7b-657a-4a64-a7de-4aab703d2b16%40googlegroups.com.