-
Notifications
You must be signed in to change notification settings - Fork 684
Move some internal functions into JerryDebugger. #2484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move some internal functions into JerryDebugger. #2484
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
jerry-debugger/jerry_client_ws.py
Outdated
"offsets": []}] | ||
new_function_list = {} | ||
# pylint: disable=too-many-branches,too-many-locals,too-many-statements | ||
def parse_source(self, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these functions are not to be called from outside of the class, then python coding guidelines suggest prefixing them with either one or two underscores, making them 'protected' or 'private' (aka weakly and strongly internal), respectively. Right now, this patch is actually exposing these functions rather than hiding them (it is turning protected module-level functions into public class methods).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so these should be def _parse_source(self, data)
? Is this a guideline or enforced in some way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is better called either _parse_source
or __parse_source
. If it is a non-public API of the class. These guidelines come from PEP8, the style guide for python. (As most things in Python, however, they are not enforced, only suggested. But the proper use of visibility is hard to enforce in any language, actually.)
Some excerpts from PEP8:
- _single_leading_underscore: weak "internal use" indicator. E.g. from M import * does not import objects whose name starts with an underscore.
- __double_leading_underscore: when naming a class attribute, invokes name mangling (inside class FooBar, __boo becomes _FooBar__boo; see below).
- Public attributes should have no leading underscores.
06ae2a9
to
1b2bcdb
Compare
Thank you. Changed back to single underscore. |
Is the commit message intended as is? ("script should not have any public symbols except the Debugger class"). Right now, the module has a lot of public symbols in addition to |
1b2bcdb
to
4263174
Compare
You are right. This is where you start disliking python. I moved the constant and added |
I don't think that python should be judged based on sentiments. There are quite often elegant ways to solve things in that language, too. E.g., the above cited PEP8 also gives suggestions for the current case.
I.e., in this case, prefixing all non-public globals with |
In this case |
Brevity doesn't help the discussion in this case.
|
4263174
to
761f246
Compare
As far as I know if something is only used by a single class it should be part of that class, at least in C to reduce the chance of symbol clashes. Anyway I moved the constants out from the debugger class, because pylint complained about a few of them. It said their format is incorrect without specifying why. Not exactly helpful. Btw are these constants are safe or the application imports them can damage them? |
C doesn't have classes. C++ has them. (As well as types within types, namespaces, etc.) And both in C and in C++, there is the concept of splitting the interface and the implementation into headers and sources. In the headers, yes, one usually follows such guidelines as you've mentioned above for the sake of OOP. In the sources, one may use implementation-specific global constants or helper functions internal to the module but not member of any class, if needed. Although Python does not split modules into two, it has solutions for defining what's public interface and what's implementation detail of a package, module, or class. Both The real question is, IMO, what's the ultimate goal of the rewrite? To make the Some extras:
As to your question "are these constants are safe or the application imports them can damage them?": I'm not completely sure what you mean. If another module uses Based on all the above, my position on this rewrite is:
|
I only wanted to move those functions in the original code, but then the underscore issue was raised. I will go back to the original code then. |
Wait. The "underscore issue" was raised for the unnecessary renaming of |
761f246
to
be4bc0f
Compare
Patch rolled back to the original version. |
68d1c12
to
114548a
Compare
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
114548a
to
48181a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The jerry_client_ws.py script should not have any public symbols except the Debugger class.