Coder Social home page Coder Social logo

Comments (6)

ebroecker avatar ebroecker commented on May 13, 2024

Hi Christian,

While technical it is possible to access the '_'-variables from outside it's definitively a very good idea to strive to a stable API.

I don't like the idea to rename the attributes.

I'd prefer property-functions.

@altendky : what Do you think?
@christiansandberg : what would be your favorite?

from canmatrix.

christiansandberg avatar christiansandberg commented on May 13, 2024

I also think property functions is the most elegant and backwards-compatible way to do it.

Maybe also add iteration support to the list type classes (FrameList, BoardUnitListe, SignalGroup, and Frame).

for frame in matrix.frames:
    print(frame.name)
    for signal in frame:
        print(signal.name)

from canmatrix.

altendky avatar altendky commented on May 13, 2024

Unlike other languages you don't have to make every last setter and getter function ahead of time in Python.

class MyClass():
    def __init__(self):
        self.my_property = 42

can be refactored without user knowledge to:

class MyClass():
    def __init__(self):
        self._my_property = 42

    @property
    def my_property(self):
        # do something more here like count how many accesses if you want
        return self._my_property

    @my_property.setter
    def my_property(self, value):
        # check the new value to confirm validity or notify another class or whatever
        self._my_property = value

In both cases you can interact with my_property such as:

mc = MyClass()
mc.my_property = 10
a = mc.my_property

So, for the members that are just _ prefixed but do not presently need to have any extra in the accessors than just the assignment and return, just remove the _. They can be refactored to have accessors later using @property.

All that said, I have not read up on the PEP's related to this. PEP8 doesn't even mention properties. Google's Python style says to "Use properties for accessing or setting data where you would normally have used simple, lightweight accessor or setter methods."

For iteration? Maybe those classes should just inherit from list and add their custom functions? This would avoid creating a bunch of pass through functions like:

def __len__(self):
    return self._fl.__len__()

def __getitem__(self):
    return self._fl.__getitem__()

from canmatrix.

ebroecker avatar ebroecker commented on May 13, 2024

started with this issue in branch "stableApi"

from canmatrix.

ebroecker avatar ebroecker commented on May 13, 2024

any comments/wishes to branch stableApi?

all attributes have their properties now.

if no futher wishes, I'll close this issue the next days and merge stableApi to master.

from canmatrix.

christiansandberg avatar christiansandberg commented on May 13, 2024

To me it looks good!

from canmatrix.

Related Issues (20)

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.