Refactor Python code to functional style #53

Open
opened 2022-01-09 18:38:51 +01:00 by pfm · 2 comments
Collaborator

Separate operations and the data they operate on so we can cover the code with unit tests.

Ideas:

  • Extract a function to build commands to be executed with subprocess.Popen.
  • Extract functions to process data returned by subprocess.Popen.
Separate operations and the data they operate on so we can cover the code with unit tests. Ideas: * Extract a function to build commands to be executed with `subprocess.Popen`. * Extract functions to process data returned by `subprocess.Popen`.
pfm added the
CODE
label 2022-01-09 18:38:51 +01:00
pfm self-assigned this 2022-04-23 12:17:24 +02:00
Author
Collaborator

More ideas for general refactoring:

  • Extract configuration predicates verifying parameteres used most often. Something like is_configuration_complete() (provided by lacre.config) would make sense.
  • Extract email notification code to a separate module, like lacre.notifications.
  • Use a template engine instead of plain string operations.
  • We should trace types of payloads and switch to either bytes or str, but not intermix them.

General refactoring direction:

  • Functions shouldn't be too complex. Nested ifs are a hint.
More ideas for general refactoring: * Extract configuration predicates verifying parameteres used most often. Something like `is_configuration_complete()` (provided by `lacre.config`) would make sense. * Extract email notification code to a separate module, like `lacre.notifications`. * Use a template engine instead of plain string operations. * We should trace types of payloads and switch to either `bytes` or `str`, but not intermix them. General refactoring direction: * Functions shouldn't be too complex. Nested `if`s are a hint.
pfm added a new dependency 2022-06-05 21:28:46 +02:00
Author
Collaborator

Another idea is to have as many functions that return some results instead of producing side-effects as possible.

General Lacre flow could be:

  1. Scan recipient list, identifying appropriate delivery details for each of them.
  2. Perform actual delivery.

Right now everything is mixed, making it so hard to test.

Another idea is to have as many functions that return some results instead of producing side-effects as possible. General Lacre flow could be: 1. Scan recipient list, identifying appropriate delivery details for each of them. 2. Perform actual delivery. Right now everything is mixed, making it so hard to test.
pfm removed their assignment 2023-05-11 21:33:28 +02:00
Sign in to join this conversation.
No description provided.