News for hackers. Stuff that matters.
Re:Want cleaner code? Use the rule of six by atoav on Sunday September 25, 2022 @05:13AM (#32969961)
I build most of my classes that way in python.

    class Motor:
        def __init__(self):
            self.max_speed = 10.0
            self.clockwise = True
            self.controller = Controller()

        def set_max_speed(self, max_speed: float=10.0) -> 'Self':
            self.max_speed = max(0.0, max_speed)
            return self

        def start(self) -> 'Self':
            self.controller.start()
            return self

        etc..

Then you can use it as follows:

    motor = Motor().set_max_speed(5.0).start()
There is nothing stopping you from building iterators that work the same way

There are no comments on this comment yet.