u/DecoherentDoc

Question about documenting functions

Question about adding documentation into your code (either for a future you or someone else). I'm self taught and I've been making a real effort to figure out home to do things the "right" way or more Pythonic way since I finished my PhD.

Is there a standard way of documenting your functions?

Below are two examples. The first is what I do now. I'm forgetful, so this helps when I come back to code much MUCH later. I don't have to parse the code much to know what it does. The second is what I think is closer to what people do? I recently learned about the 'typing' module and also learned about doc strings (like, six months ago).

If there's a standard, are these close? Is there a better way to do it? Am I worrying about minutia that I should just not worry about? Any advice would be super helpful. Thanks in advance (and sorry about formatting)!

Examples:

def heavilyDocumented(a, b, c):

"""

Purpose:    Here's what it does

Args:       a (int) - here's what the number represents

            b (dict) - {"this is a descriptive key" : its_value}

            c (str) - again, just saying what this represents

Return:     Here's a description of what the return is (str)

"""

print("and the code goes here")

def lessDocumented(a: int, b: dict, c: str) -> str:

"""Here's what the function does"""

print("and the code goes here")
reddit.com
u/DecoherentDoc — 5 days ago

Desktop ME2 Suicide Mission Calculator

So, I wanted to do a run where I killed off basically everyone, but needed to figure out how to also survive the end of ME2. I ended up making a program to calculate who dies and at what stages based on this flowchart. It's only my second time writing a GUI, so any feedback is appreciated. You can find my calculator on Github here in this repository. It runs from the command line / Terminal. Make your selections in a box (starting from the left) and press the button at the bottom of the box and the result reads out below.

I was going to package it as an executable, but there are issues across platforms and I just don't have the experience making executables. I've only done it once and on a windows machine. That program is also on my Github, it's a random password generator (this repository here) in case anyone is interested in that.

Please let me know what you think. I hope someone (other than just me) finds it useful!

Side note for those that know code really well, I'm not a pro and I enjoy improving. So, if you open the .py file up and see something that could be more Pythonic or needs to be done in a certain way to be more secure or more clear or something, don't hesitate to mention it!

u/DecoherentDoc — 14 days ago