bastisawesome / guessinggame_ttv

A Twitch bot to play a word guessing game
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Cleanup Text at Max Column #41

Open bastisawesome opened 1 year ago

bastisawesome commented 1 year ago

That title is probably confusing, but it should get the point across.

In several parts of the codebase there are strings that would extend beyond the 80 character limit. To fix them, often some hacky, hard-to-read workarounds are used for string-concatenation and/or continuation. Replace these hacks with slightly-more readable code that utilises str.strip and the textwrap built-in library.

An example from database.py: old:

exists_query = ('SELECT * FROM sqlite_master WHERE type = "table" AND '
                f'name = "{tablename}"')

new:

from textwrap import dedent as dd
...
exists_query = dd(f'''
                  SELECT * FROM sqlite_master WHERE type = "table" AND
                  name={tablename}
                  ''').strip()

Not 100% certain whether or not this is more readable, but it definitely seems less hacky than floating parenthesis. Will keep this under review until either someone else comments/makes a pull request, or the time comes for me to begin work on this issue.

bastisawesome commented 1 year ago

The biggest benefit to this change is that it makes it possible for the SQL queries to be formatted without impacting the generated code. Though, this probably could have and should have been done this way from the start using multi-line strings.

That benefit does not exist for non-SQL query strings, but this issue would still make it clearer what is happening and produce slightly cleaner code.