Comments (16)
Results checklist:
- C++
- C#
- Java
- JavaScript
- Perl
- PHP
- Python
- Ruby
from kaitai_struct.
Current status:
Perl
I'm totally unable to grasp what particular combination of =item
, =cut
, =over
, =head1
, etc, is required to generate documentation for a class. Actually, I don't even get if it's a good idea to generate POD interleaved with code (as documentation suggests), or just POD section at the end of file (as majority of modules do). @sergeyzelenyuk, could you lend a hand here?
Python
I've stumbled upon generation of docstrings for plain attributes (i.e. not declared anywhere). This SO question suggests that stuff's still bad with that sort of documentation in Python: one can either place it into class-related docstring (which is unparseable and can't be used in any IDE), or one has to generate weird constructs with @property
for that. @dgladkov, any ideas on what shall be used here?
from kaitai_struct.
I've added doc
attribute to type specification as well. Now classes can be annotated too, including top-level class, which probably should be most important piece of documentation.
from kaitai_struct.
Python docstrings are more or less there (probably "less", as there is no attribute docstrings generated, as Python seem to lack attribute documentation).
from kaitai_struct.
Python properties do have docstrings, read this:
https://stackoverflow.com/questions/16025462/what-is-the-right-way-to-put-a-docstring-on-python-property
I unchecked Python on the list for you.
from kaitai_struct.
The problem is that we don't generate these trivial getters and we don't really hide actual instance members by using something like that:
@property
def x(self):
"""Get x"""
return getattr(self, '_x', 42)
So, shall we start generating them and rename actual members to something like _m_foo
? I'd be worried about the performance at the very least.
from kaitai_struct.
Can you show me what is actually being generated by current implementation?
from kaitai_struct.
For example, https://github.com/kaitai-io/ci_targets/blob/master/compiled/python/docstrings.py
from kaitai_struct.
Hmm arent we talking about (already) solved problem?
from kaitai_struct.
I'm not sure what you're implying. The fact that Python now lacks docstrings for properties that are not implemented using @property
getter method still stands. These are usually encountered as regular seq attributes.
For example, compare these attributes in Ruby, and note that Python counterpart lacks such lines at all. This line in _read()
is sufficient to create property and that's all.
from kaitai_struct.
I am too sleepy to see straight, thanks for putting up with me. So in the example "self.one" is a field (not a property), and fields do not have docstrings? I think you mixed the terminology? Fields (class attributes) and properties are 2 different terms. In python example you linked, properies are documented, fields are not. There is no such thing as "properties without @Property" as far as terminology goes, but I got what you mean. So you suggest to use read-only properties instead of attributes? I'd say yes, there is no cost/drawback in using properties instead. Except slight more generated code.
from kaitai_struct.
Are you sure? It seems to me that performance drop significant, i.e.
import timeit
class FooWithField:
def __init__(self):
self.pew = 42
class FooWithPropertyRaw:
def __init__(self):
self._m_pew = 42
@property
def pew(self):
"""Get pew"""
return self._m_pew
class FooWithPropertyGetAttr:
def __init__(self):
self._m_pew = 42
@property
def pew(self):
"""Get pew"""
return getattr(self, '_m_pew')
foo1 = FooWithField()
foo2 = FooWithPropertyRaw()
foo3 = FooWithPropertyGetAttr()
print(timeit.timeit(lambda: foo1.pew)) # => 0.092588186264
print(timeit.timeit(lambda: foo2.pew)) # => 0.212033987045
print(timeit.timeit(lambda: foo3.pew)) # => 0.277426958084
So, just adding @property
+ method with simple return is ~2.3x more expensive than just a field. Doing "proper" attribute getting using getattr
is ~3x more expensive.
from kaitai_struct.
Ah right, I remember using fields and properties years back when I was a C# fan. Then it had same performance, and I do remember reading about it. I didnt quite check for Python. Good thinking there.
You are misinterpreting the numbers. Its not 2.3x times slower, its +0.12 microsecond slower. This amount adds to parsing time, and user handling of that data, both are much heavier than that. A drop in the bucket, so to speak. I think docs might be worth an extra microsecond, dont you think?
There is nothing proper in third example. I would not recommend it over second out of readability alone. Discount it.
from kaitai_struct.
One more drawback/advance (depends on application) is laziness. For debugging it is certainly a drawback since when debugging we need to find all the issues like incorrect enum values or invalid characters/wrong encodings. So we run our format against a set of files and look for exceprions.
from kaitai_struct.
Correct "exceprions". I dont understand what properties have to do with it. Properties are not lazy, nor make parsing lazy by any meaning. Can you explain by example?
from kaitai_struct.
I have confused them with instances which are currently generated via properties.
from kaitai_struct.
Related Issues (20)
- Warning about encoding name is reported even for types without explicit `encoding`
- `_root` / `_parent` chain broken by recursive use of the top-level type
- `bytes.to_s(encoding)` should validate the passed encoding
- Using enum members as int is broken in ruby HOT 3
- Add explanation to errors `spec_build_failed` and `format_build_failed` on https://ci.kaitai.io/ HOT 1
- C++: the type of all integer constants wrongly deduced as `int32_t` HOT 1
- ci.kaitai.io: use snake_case for test names instead of PascalCase HOT 1
- Java: byte array elements propageted to `int` as signed values (0xFF -> -1 instead of 255)
- Unclear expected values for integer division HOT 4
- Invalid Java code generated: Incompatible types: possible lossy conversion from int to byte HOT 3
- Ruby, Lua: missing `require`s not detected by tests due to `require` leaks HOT 1
- Invalid Java code generated: Switch selectors cannot be of type "long" HOT 1
- Recursive decoding of value HOT 3
- Python: Fix missing `assertRaisesRegexp` method in Python 3.12
- C++11: segfault in debug mode for arrays HOT 1
- Construct: the order of `Computed` fields matter
- How to disable building documentation and JS?
- Health of the project?
- Support for Julia HOT 1
- Error: Could not find or load main class io.kaitai.struct.JavaMain 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 kaitai_struct.