Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data Classes

Data Classes

How Python punishes us for trying to do right when following principles for object-oriented design and what new features are coming to 3.7 that will make our lives easier.

Lighting talk at December CamPUG meeting

Avatar for Jan Chwiejczak

Jan Chwiejczak

December 05, 2017
Tweet

More Decks by Jan Chwiejczak

Other Decks in Programming

Transcript

  1. How Python punishes good OOD  Python multi paradigm programming

    language  However, most serious projects have a strong OOD structure goo.gl/QJDG22
  2. How Python punishes good OOD  Python multi paradigm programming

    language  However, most serious projects have a strong OOD structure  Make lots of small self contained classes that do one thing and do it well goo.gl/QJDG22
  3. We leverage Python strengths  name, host = … 

    [(name, host, port, arm_type)] = … goo.gl/QJDG22
  4. We leverage Python strengths  name, host = … 

    [(name, host, port, arm_type)] = …  self.params[‘arm_pool’][name][3][INSTRUMENT] goo.gl/QJDG22
  5. We leverage Python strengths  name, host = … 

    [(name, host, port, arm_type)] = …  self.params[‘arm_pool’][name][3][INSTRUMENT] goo.gl/QJDG22
  6. Starts well class Arm: class Arm: def __init__(self, name, host,

    port, arm_type): ... class Arm: def __init__(self, name, host, port, arm_type): self.name = name self.host = host self.port = port self.arm_type = arm_type goo.gl/QJDG22
  7. This is getting tedious class Arm: def __init__(self, name, host,

    port, arm_type): self.name = name self.host = host self.port = port self.arm_type = arm_type def __repr__(self): return self.__class__.__name__ + '(name={}, host={}, port={}, arm_type={})'.format( self.name, self.host, self.port, self.arm_type) goo.gl/QJDG22
  8. How about comparison class Arm: ... def __eq__(self, other): if

    not isinstance(other, self.__class__): return NotImplemented return (( self.name, self.host, self.port, self.arm_type) == (other.name, other.host, other.port, other.arm_type)) goo.gl/QJDG22