4 ms·
s/comment/docstring/
by xapata 6y ago
s/comment/docstring/
- BurningFrog 6y agoI have yet to understand the point of docstrings. How are they, in practical reality, better than comments?
- powersnail 6y agoThe difference is in tooling. Docstrings are collected and displayed in many contexts. The intended purpose is writing “documentation” in the same place as code. Comments are only seen if you open the source file.
- BurningFrog 6y agoOK, I can see how that's useful for a certain workflow. The way we work, it's just a different comment syntax. I do like have a dedicated place for it.
- xapata 6y agoPython's builtins, the standard library, and many popular community libraries and tools use docstrings to generate tooling and documentation websites. Describing it as "useful for a certain workflow" is so understated it borders on false. The reverse is more true: docstrings are not useful for a certain workflow, but most Python programmers will find them quite helpful. All Python programmers already benefit from the docstrings written in the libraries they use, which generate tooltips and documentation websites.
- f00_ 6y agoyou can access it from object.__doc__, and there is tooling in ide's like pycharm to quick view them to see what a function does, auto generated documentation prior to mypy/type hints it allowed you to document the types of a function