manim icon indicating copy to clipboard operation
manim copied to clipboard

Clean Up Manim's API

Open JasonGrace2282 opened this issue 1 year ago • 1 comments

Currently, it's difficult to tell which methods are internal to Manim, and which are designed to be used by an end user. Once the API of Manim is solidified, it's easier to make more drastic changes without having to worry about breaking user code, because all you have to do is keep the public interface stable (ish).

Renaming methods to start with an _ to avoid them being documented is not a good solution, as the documentation should be for both developers and end users.

JasonGrace2282 avatar May 30 '24 17:05 JasonGrace2282

Because python support multi-inheritance there is possibility to use this kind of pattern to separate Internal and ui methods and information in code.

from __future__ import annotations

class ModelUi:
    '''Methods intented for end users'''
    def set_color(self:Model):
        print("supertype UI")

class ModelApi:
    def trade_info(self:Model):
        return self.info
    
class Model(ModelUi, ModelApi):

    '''Internal use only'''

class SubModelUI(ModelUi):
    def set_color(self:SubModel):
        print("subtype UI")

class SubModel(Model, SubModelUI):
    '''Internal use only'''
    pass


super = Model()
sub = SubModel()

super.set_color()
sub.set_color()

OliverStrait avatar Aug 15 '24 16:08 OliverStrait