-
Notifications
You must be signed in to change notification settings - Fork 36
XML: Manage Command handlers as a function dictionary (WIP) #119
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
Open
uliska
wants to merge
1
commit into
master
Choose a base branch
from
xml-handle-handlers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are there any plans to expand this to more categories besides commands?
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 think so, once I'm more familiar with it there will probably more of 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.
There are of course other examples of multiple
elif
statements. But I'm not yet convinced that this is helpful as a general restructuring. The goal should be to make it easier to add new functionality and to maintain the existing code.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 haven't looked again yet at the code of this PR concretely, but I came across the issue when looking in other corners. I'm not convinced that my suggestion is the best implementation because it may seem to add some level of complexity that is contrary to the goal of making maintenance and development easier. But I'm now even more convinced that it would be good to have a dictionary based infrastructure for a number of things to replace the
elif
chains.One example is the
End()
function that provides endings for a number of different elements.Another example I came across is
Set()
. I would like to start supporting specific context properties. This would also require handlers for each supported property.Somehow I have the feeling that it would be the most natural approach to not use the token as the dictionary key but the element's class, and then instantiate an object of a corresponding class, which would handle the request. Such a could be maintained in its own file, so there's less penalty for implementing lots of special cases (e.g. context properties, element types to be ended ...). Maybe it would even make sense to make this subclasses of the classes in
ly.music.items
?However, this is more a random musing than a concrete suggestion. Maybe this won't work because there is no really common interface (i.e. does this need arguments or not, how many, etc).
OTOH I'm thinking if this couldn't be a way to provide an opportunity for people to support their
\userCommand
s. A base path could be passed as an argument, and if there is a certain file it will be included ... No idea if that would work, but it could prove very helpful.