Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Refactor function parameters to describe the behavior instead of the state which is interpreted in non-obvious ways #11300

@MadLittleMods

Description

@MadLittleMods

as a general rule, I would say it is preferable for method parameters to describe a change in behaviour ("inhibit_sync_to_clent") rather than describe some bit of state that the function is free to interpret as it wishes: it's much clearer for a later reader to understand how things tie together, particularly when things then get modified later on. Obviously this isn't a hard-and-fast rule, but it's worth considering.

[Currently we have a bit of a mess in some places (FederationEventHander.backfilled being a prime example) where you have to dig through 150 methods to find out what a flag actually does, and then somehow reverse-engineer what it is supposed to do. Don't do that.]

-- @richvdh, #11265 (comment)

Examples:

The interesting spots will be any of the bool function parameters, search for : bool.*=?.*,:

outlier and backfilled can be refactored out to options like:

  • inhibit_sync_to_client
  • inhibit_push_notifications
  • use_negative_stream_ordering
  • etc

is_peeking could be refactored into

  • inhibit_peekers_viewing_shared_rooms
  • include_membership
  • etc

To refactor, it's probably easiest to dive down to the innermost function to find the actual functionality each function parameter triggers and pipe the new options to the top.

In many cases, we rely on event.internal_metadata with outlier (or is_outlier), historical (or is_historical), soft_failed (or is_soft_failed), etc. There are many side-effects from setting something as an outlier for example. We could write methods like event.internal_metadata.should_proactively_send() with these descriptive behaviors based on those properties, new ex. event.internal_metadata.should_inhibit_sync_to_client().

Definition of done


Keywords:

  • Refactor logic to rely on descriptive behavior function parameters instead of interpreting a given field

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions