-
Notifications
You must be signed in to change notification settings - Fork 38
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
Remove component templates #491
Conversation
Another note: While fixing how this system interacts with the undo system, I accidentally discovered that boolean parameters on Components were being saved as 1 or 0 in the .cfg file. Fixing this solves #307 |
And this also fixes #431 |
class NetGraphTemplate(Template): | ||
cls = NetGraph | ||
config_params = dict() | ||
NetGraphTemplate = NetGraph |
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.
Although you removed the Template class, you still create a reference to the object named as the Template. Why is that?
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.
Backwards compatibility?
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. I'll add a comment to make that clear (and perhaps find a way to do it in one place, rather than in each Component file).
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.
Although you removed the Template class, you still create a reference to the object named as the Template. Why is that?
I've moved all that code to components/__init__.py
and added a comment describing why it's there. :)
I've added comments to component.py and value.py. Let me know if those help! |
@@ -335,7 +335,7 @@ Nengo.NetGraph.prototype.on_message = function(event) { | |||
var uid = data.uid; | |||
for (var i = 0; i < Nengo.Component.components.length; i++) { | |||
if (Nengo.Component.components[i].uid === uid) { | |||
Nengo.Component.components[i].remove(true); | |||
Nengo.Component.components[i].remove(true, data.report_back); |
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.
report_back
seems like a bit of an ambiguous variable name. Is the only use of this variable to check whether the item was being undone or deleted? Is it associated to a particular event and is it likely that it will always be associated to that event?
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.
Hmm.. the intent is that it's a flag to indicate whether the NetGraph should report back to the server that the removal happened. We don't want it to do so in this case, as the server is the one who asked for it to be removed in the first place. Not sure what a better name would be.
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.
How about server_removed
?
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.
Yuck... I usually prefer function parameters that indicate what the function is supposed to do, rather than function parameters that indicate the context in which someone else called the function. If report_back
isn't clear enough, I'd be more tempted to do something like indicate_client_should_report_removal_back_to_server
, but maybe not quite as silly as that. Can you say more about why you find report_back
to be ambiguous? I'm having trouble seeing what's unclear about it.
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.
Lol, Terry you have the most visceral reactions to bad naming suggestions.
Now that you've explained it to me, as well as your methodology for naming parameters, it makes sense to me. If it's not too much trouble adding a quick comment might be a good idea, especially considering how deep it is in the if-statements.
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.
:) Gah, rereading my comment it does come off as a bit... visceral. Sorry about that.
And now that I'm rereading it, I wonder if part of it is that both "report" and "back" have many meanings, so it's unclear without a comment even how to parse this (is "report" a verb or a noun? Is "back" a noun or a verb particle?) So it's way more potentially confusing than I was initially believing.
So how about notify_server
? That's a little less ambiguous to parse.... :)
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.
That sounds delightful. (:
On Sun, Jul 19, 2015 at 10:42 PM, tcstewar notifications@github.com wrote:
In nengo_gui/static/netgraph.js
#491 (comment):@@ -335,7 +335,7 @@ Nengo.NetGraph.prototype.on_message = function(event) {
var uid = data.uid;
for (var i = 0; i < Nengo.Component.components.length; i++) {
if (Nengo.Component.components[i].uid === uid) {
Nengo.Component.components[i].remove(true);
Nengo.Component.components[i].remove(true, data.report_back);
:) Gah, rereading my comment it does come off as a bit... visceral. Sorry
about that.And now that I'm rereading it, I wonder if part of it is that both
"report" and "back" have many meanings, so it's unclear without a comment
even how to parse this (is "report" a verb or a noun? Is "back" a noun or a
verb particle?) So it's way more potentially confusing than I was initially
believing.So how about notify_server? That's a little less ambiguous to parse.... :)
—
Reply to this email directly or view it on GitHub
https://github.com/nengo/nengo_gui/pull/491/files#r34966282.
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.
Changed! :) Thank you for pushing on this....
Other than my last two comments, this pull request LGTM. |
# Old versions of the .cfg files used Templates which had slightly different | ||
# names than the Components currently usef. This code is needed to | ||
# successfully parse those old .cfg files | ||
this_module = sys.modules[__name__] |
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.
I know this saves us a couple of lines, but this seems like a weird place to put in the mental effort to read/write this Python magic and realize what's going on. If I'm reading this all correctly, you could replace it with
SliderTemplate = Slider
ValueTemplate = Value
XYValueTemplate = XYValue
# and so on
which is 9 lines versus these 4, but it definitely takes less time to read and understand the 9 line version. There's also no reason to bother doing this for new components, so it doesn't matter if it gets out of date. Ideally, we'll remove the 9 lines eventually anyway.
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.
That is a really good point. :) I've updated it to use your much clearer approach.
self.replace_with = None | ||
|
||
def initialize(self, page, config, uid): |
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.
initialize
as a method name always make me cringe, since it seems like it should be done in __init__
. There are times when you need to defer parts of what could be called initialization, but regardless I would not call the method initialize
. If the docstring here is correct, then how about connect
?
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.
initialize as a method name always make me cringe, since it seems like it should be done in init.
:) fair enough.
I could see connect
working, although that might be a bit ambiguous with the actual socket connections and nengo connections going on. Perhaps attach
? or set_page
?
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.
I like attach
, but I don't know about set_page
since you're setting more than the page right? If you were just setting the page, I'd recommend making page
a property, but it's more than that.
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.
I just switched it over to attach
. :)
Aside from my inline nitpicks, this looks great to me! Should be much clearer for those implementing new components, which hopefully will be several people ;) |
I think I've responded to all the suggestions here.. anyone mind if I merge this? :) |
Go for it! On Tue, Jul 21, 2015 at 4:48 PM, tcstewar notifications@github.com wrote:
|
This gets rid of the Component/Template distinction that complicates the server-side code.
Now that Page and GUI have been reorganized, the entire reason for Templates is gone. They were originally there because the config file was shared across multiple Viz objects, and so the config file was processed before the actual Components themselves existed. So the config file actually configured these Component Templates, and the Components (when they were created when a page was actually generated) got their information from the Templates.
But now we don't look at the config file until after the Page is being created, so all that indirection is unnecessary, and so this PR gets rid of the Templates.
Some notes:
uid
s for the Component and the Template. The one for the component was justid(self)
and was used by the websocket infrastructure to figure out which component the browser is trying to talk to. The one for the Template was the python string that could be used to refer to the object. This is the one used in the .cfg file and is consistent with all the otheruid
values in the rest of the system. In the new code, alluid
s in the Python code are always python strings for referring to things, and in the places where we needid(self)
we just callid(self)
.