XaverStiensmeier / ilarisdiscordbot

A discord bot for the ilaris ttrpg
GNU General Public License v3.0
0 stars 0 forks source link

Code formatting #60

Closed lukruh closed 5 months ago

lukruh commented 6 months ago

I don't want to be that guy... but.. there are some very long lines and nested definitions, that could easily be formatted automatically using something like black: https://pypi.org/project/black/

I would also import some modules/functions directly to avoid writing something like commands.parameters(default=... 30 times in a file.

XaverStiensmeier commented 6 months ago

I commonly use PyCharm's formatting which adheres to PEP8 rules and requirements for arranging and formatting Python code. I might have missed formatting some files. Do you see a big advantage in using black instead?

Regarding commands.parameter you intend to import it so you can use parameter instead? That's totally fine. Or do you intend to also change parameter to a shorter name?

lukruh commented 6 months ago

maybe even from commands import parameter as param but that was just an example.

Black is very strict and easy to use (integrated in pycharm since v2023 just pip install black and activate in settings) but checking for pep8 should be good enough. However I got a lot of complains because of line length, I can change the rule, but maybe we should not go over 90 or 100 characters or it becomes hard to edit in some terminals or split screen.

I also don't really like the "hanging indentation" for very long function names (and would completely avoid it for consistency). Here is an example:

text_channel = await ctx.guild.create_text_channel(name="Text", overwrites=overwrites,
                                                   category=category)

shows all important stuff outside the field of view. I'd prefer writing it as

text_channel = await ctx.guild.create_text_channel(
    name="Text", 
    overwrites=overwrites,
    category=category
)

IMO its easier to read and navigate and also possible to comment out specific arguments real quick.

lukruh commented 5 months ago

I just deactivated my formatters and will only fix long lines on the fly if they are not readable in split screen (git diff etc..). This is usually around 90 characters on my laptop screen.