justpy-org / justpy

An object oriented high-level Python Web Framework that requires no frontend programming
https://justpy.io
Apache License 2.0
1.22k stars 96 forks source link

Coding style #493

Closed WolfgangFahl closed 2 years ago

WolfgangFahl commented 2 years ago

Discussed in https://github.com/justpy-org/justpy/discussions/490

Originally posted by **platinops** September 4, 2022 I'm happy to see that justpy is again being actively developed. I did note however that several commits to not adhere to [PEP8](https://peps.python.org/pep-0008/). Some examples: - `getServer` -> `get_server` (incorrect use of CamelCase, [src](https://github.com/justpy-org/justpy/blob/461a6419a728353c2fc59d24e8c495eed226abfd/justpy/justpy.py#L379), [pep](https://peps.python.org/pep-0008/#function-and-variable-names)) - `self.sleepTime=sleepTime` -> `self.sleep_time = sleepTime` (incorrect use of spaces around equal sign, [src](https://github.com/justpy-org/justpy/blob/461a6419a728353c2fc59d24e8c495eed226abfd/tests/base_server_test.py#L30), [pep](https://peps.python.org/pep-0008/#other-recommendations)) - `global jp_server,func_to_run, startup_func, HOST, PORT` -> `global jp_server, func_to_run, startup_func, HOST, PORT` (missing space after comma, [src](https://github.com/justpy-org/justpy/blob/461a6419a728353c2fc59d24e8c495eed226abfd/justpy/justpy.py#L401), [pep](https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements)) Would suggest the use of the [black](https://github.com/psf/black) package to ascertain consistent code amongst all developers, in line with PEP8, while also appllying PEP8 more correctly w.r.t. CamelCase for classes, but lower_case for functions and variables.
WolfgangFahl commented 2 years ago

The CamelCase issue come from my personal background. See https://stackoverflow.com/questions/8908760/should-i-use-camel-case-or-underscores-in-python. So e.g. for download.py and some testingCode you'll see me referencing: You clipped an important part of PEP8: "mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility." Sometimes, CamelCase is acceptable. –

I'll try to stick more to PEP8 for new code and fix older code every once in a while,