Evidlo/remarkable_mouse

Don't pass around `args` object

Closed this issue · 1 comments

I believe that passing container objects like args to all your subroutines is eventually asking for trouble. By using such a container, functions are allowed to hide what fields of the container they are actually using. And those functions are not reusable, as I have to first create an args container with all the right fields.

If you search for args you will find it is used in open_remote_device(), pipe_device(), and read_tablet(). But actually

  • open_input_device() is using args.address, and optionally args.key and args.password.
  • pipe_device() is using args.orientation, args.monitor, args.threshold, args.mode, and args.debug
  • read_tablet() is using args.orientation, args.monitor, args.threshold, and args.mode

That fact is completely hidden in the generic function(args) interface.

Instead of a function

def foo(args):
    print(args.address, args.debug)

foo(args)

I would recommend unpacking the arguments in the call

def foo(address, debug=False)
    print(address, debug)

foo(args.address, args.debug)

The code has mostly been refactored to not do this anymore.