Skip to content
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

Merged
merged 16 commits into from
Jul 21, 2015
Merged

Remove component templates #491

merged 16 commits into from
Jul 21, 2015

Conversation

tcstewar
Copy link
Collaborator

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:

  • This slightly changes the .cfg file format, in that it is no longer necessary to refer to ValueTemplate in that file, and it's just Value instead. For backwards compatibility, ValueTemplate still works (otherwise all old .cfg files would fail).
  • There used to be two separate uids for the Component and the Template. The one for the component was just id(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 other uid values in the rest of the system. In the new code, all uids in the Python code are always python strings for referring to things, and in the places where we need id(self) we just call id(self).

@tcstewar
Copy link
Collaborator Author

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

@tcstewar
Copy link
Collaborator Author

And this also fixes #431

class NetGraphTemplate(Template):
cls = NetGraph
config_params = dict()
NetGraphTemplate = NetGraph
Copy link
Collaborator

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backwards compatibility?

Copy link
Collaborator Author

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).

Copy link
Collaborator Author

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. :)

@tcstewar
Copy link
Collaborator Author

If this is going to be one of the final design-level iterations, it would be nice to have some comments/docstrings to specify the design-scope and purpose of the Component.

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);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about server_removed?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.... :)

Copy link
Collaborator

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.

Copy link
Collaborator Author

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....

@Seanny123
Copy link
Collaborator

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__]
Copy link
Member

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.

Copy link
Collaborator Author

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):
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

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.

Copy link
Collaborator Author

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. :)

@tbekolay
Copy link
Member

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 ;)

@tcstewar
Copy link
Collaborator Author

I think I've responded to all the suggestions here.. anyone mind if I merge this? :)

@Seanny123
Copy link
Collaborator

Go for it!

On Tue, Jul 21, 2015 at 4:48 PM, tcstewar notifications@github.com wrote:

I think I've responded to all the suggestions here.. anyone mind if I
merge this? :)


Reply to this email directly or view it on GitHub
#491 (comment).

tcstewar added a commit that referenced this pull request Jul 21, 2015
@tcstewar tcstewar merged commit 13f46f0 into master Jul 21, 2015
@tcstewar tcstewar deleted the remove-component-templates branch July 21, 2015 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants