Giter Club home page Giter Club logo

thib's People

Contributors

thibaultbetremieux avatar thibtrip avatar

Stargazers

 avatar

Watchers

 avatar  avatar

thib's Issues

Feedback for 2020/lightning_talks/split_class

Some feedback about the class splitting, as requested ๐Ÿ˜„

>>> from human import Human
>>> human = Human()
>>> human.legs.move()
แ••( แ› )แ•—

This reaching through objects is considered a bit of an anti-pattern in some circles (Law of Demeter). The reasoning goes something like this: Say you change the signature of Legs.move to have a required required argument, like an integer steps. Then you would have to change all the code which uses human.legs.move. Instead you could hide the legs as implementation detail and only have to change the one place inside the facade.

class Human():
    ...
    def move_legs(self):
        self._legs.move(3)

# everyone has the same community so this can be a class attribute
community = Community

Here you are assigning a global variable, why would you need to do that? If you want to use it as global then you can just import it? I would pass a singleton as parameter to __init__, since there might be humans which do not belong to the same community ๐Ÿ˜„.

def __init__(self):
# we do not need to expose this to the user ('_X' means its private and not supposed to be used)
self._brain = Brain()
self.legs = Legs(brain=self._brain)

If avoidable I would not construct objects in __init__ but rather inject the dependencies.

Maybe something like this?

class Brain():
    def __init__(arms, legs, ...):
         self._arms = arms
         self._legs = legs
   def move_legs():
         self._legs.move()
    ...

class Human():
    def __init__(brain):
        self._brain = brain
    def move_legs(self):
        self._brain.move_legs()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.