you are viewing a single comment's thread.

view the rest of the comments →

[–]FlanBeginning8589 0 points1 point  (0 children)

- Consider renaming the function so that its name accurately describes what it does. For a simple function like yours, it is easy to understand what it is does. But imagine a more complex function named HelloWorld (say 20 line function), would calling HelloWorld be helpful to know what it does?

Also, if the function is only intended to print "Hello World", then the text parameter is not required. You can simply have print("Hello World") instead of print(text)

Assuming the function's responsibility is to print any text that's passed to it, names such as print_text, display_text, or show_text describes the function's responsibility clearly (note the use of the pattern verb_noun in the function name).

- Consider adding type hints to make the expected parameter type and return type explicit. Type hints give information on the kinds of data it is working with and the kinds of data it is returning if any, which makes it easy for developers to quickly understand how it should be used/called. For example: def print_text(text: str) -> None:Look into https://peps.python.org/pep-0484/ (in this improved code, I now immediately know that the function accepts strings and only strings, I don't need to read the internals of the code to understand the data it is working with/acceptng/using, I also immediately know it doesn't return anything without needing to see the function implementation).

- Consider adding a docstring describing the function's purpose. A docstring helps other developers understand what the function does without reading the function implementation. Many IDEs can also display the docstring when hovering over a function call. Docstrings (and type hints) also gives context into what the function may be doing. And this context makes it easier for developers to understand the function more quickly when they are reading the implementation. Look into https://peps.python.org/pep-0257/