Comments (6)
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.
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.
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.
started with this issue in branch "stableApi"
from canmatrix.
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.
To me it looks good!
from canmatrix.
Related Issues (20)
- Convert arxml file to dbc file wrong HOT 6
- Wrong min/max scaling when signal has slope or offset HOT 1
- Python3.12 compatibility / drop 'future' dependency HOT 5
- Loading arxml with Ethernet data Performance is extremely bad on development branch(2023-12-15) HOT 6
- use Canmatrix create dbc HOT 7
- Convert excel to DBC with Canmatrix HOT 1
- Convert DBC to arxml failed HOT 3
- Renaming Node / ECU via rename_ecu should clear out any existing transmitter and receiver
- wrong with canmatrix.cli.compare.cli_compare
- when xsl2dbc,singal's offset γmini is uncorrect
- convert ARXML to DBC have error:<class 'decimal.DivisionUndefined'> HOT 1
- convert ARXML to DBC have error:<class 'decimal.DivisionUndefined'> HOT 2
- Convert dbc <=> xlsx - units are deleted HOT 1
- Convert dbc <=> xlsx - DLC is always reset to it's maximum of 8 bytes HOT 1
- Exporting ARXML to XLSX (CanCluster vs. J1939Cluster) HOT 6
- canmatrix.py --> decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>] HOT 6
- Speed up Decode and Encode timing
- ARXML to xlsx HOT 3
- System name for signal group in arxml
- Casting the frame id from scientific number format fails HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canmatrix.