-
-
Notifications
You must be signed in to change notification settings - Fork 412
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
Support a cleaner syntax for SCRIPT transformation #3476
Conversation
…file.script)` Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This breaks the |
Thanks for the feedback. I believe I can fix that. |
…stry Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
I've added some extra code to include all the supported scriptTypes loaded in the transformation registry. If we are going to infer the scriptengine / language from the extension here too, we can remove the support for .script completely, although it will be a breaking change, but it is one that actually improves usability as it simplifies the UI by reducing errors. Currently, the user can select the wrong language especially in the UI when all they see was In the case of managed provider, the language is defined when creating the transformation, and the user should not need to choose/decide again when loading/selecting the transformation. I am merely mentioning this as an observation. It is not the goal / purpose / scope of this PR to make such a drastic change, but I'd be happy to expand the scope of this PR if deemed necessary. |
I don't understand where you see the "extra burden", selecting the language is a common task when configuring openHAB. If you add a rule with a script action, you have to select the language, too. As I already said: I believe this is wrong and complicates things all the way for the benefit of a few. |
It seems quite clear to me:
versus:
It greatly simplifies the UI and eliminates one possible error. To me .script is the complicated way. However, as I said, I'm not here to advocate for changing the use of .script in this PR. People can continue to use .script exclusively and have no trace of per-language extensions showing in their system should they choose to do so.
Indeed this is a matter of opinion and I'm at the opposite end of that opinion. As I understand it, openHAB is a community project, so is there a democratic process in making a decision or is it a case of the decision is made only by certain individuals? Should we create a poll or something to see whether this only benefits "a few" or the "majority"? Again, I'm quite happy to leave |
Do what you want, I won't veto that. But I'm pretty sure that this will end in a full nightmare for @rkoshak when support is needed. |
You keep saying that inferring the script type is somehow more complicated than having to specify it, without giving any actual examples of what is more complicated. Up to this point I thought you meant that it would make the implementation and interfaces complicated, but this comment makes me think maybe you have something in mind that not having to specify the script language will somehow be more complicated for the user to use. Do you have a specific example in mind where you think a user might be confused? |
Every time there are several ways to do the same thing this ends up with people mixing instructions from different places. The result is that they start complaining something is "not working". I have said everything I have to say in this issue. My opinion is that it's a mistake to give up simple design principles (which have proven to be easy to understand for a long time) to add additional ways for doing what is already possible with what we have. |
Wow, that argument basically reads like "we shouldn't make simpler ways to do things, because sometimes people will get confused." Why was Main UI (and Paper UI before it) even written if you could already administer openHAB completely via files?! @jimtng even posited that we could entirely get rid of having to choose the scripting language at all (when referencing transformations, not when writing new ones). That would mean there are no additional ways to do the same thing (though there would be a small period of additional support burden if there needs to be manual steps when updating openHAB, but the transformation could still undocumented support the old way), not adding to the support burden. I still haven't seen an argument I understand for not making the user repetitively specify the scripting language violates "simple design principles". |
Because it's much harder to mess things up in UI configuration than in files. Look at the forum: 2/3 of the issues are related to file based configuration. It should be removed completely, but that is probably not something I can get a majority of maintainers to support. What I'm saying is that "map transformation uses If you want to go that route, do it fully: remove |
Got it. You believe file based configuration should be removed completely, so anything that improves the file-based experience isn't worth doing. I'm not being facetious or sarcastic here. It helps me to understand from the point of view your arguments come.
I think our argument is that people don't ask "what extension does a script transformation use? obviously it's .script! now I'm going throw some javascript in there", they say "I have a javascript transformation. that's implicitly a .js file. now which transformation do I use for this? oh, script, okay!"
Why are you thinking about the file extension at all when creating a transformation in the UI??
Yes, @jimtng suggested that, since it would also simplify the UI way. |
I didn‘t say that and this really marks the end of the discussion for me. |
I've watched this thread and the other one. From my perspective, the Also, when users create a SCRIPT transformation, I'm not sure they are thinking about it as a SCRIPT transform so much as a jRuby transform or a Rules DSL transform. I know that's the mental model I fall into when I think about it. Whether or not that is reasonable I can't say, but it's what I do. @J-N-K, I'm sure you think about it as one thing given you wrote it that way and have the most familiarity with it. The SCRIPT part isn't as important to the end user as the language the transform is written in because it's the language that is going to dictate the syntax. The SCRIPT transformation itself, mentally, is like the engine that the scripts run in. It also really seems odd and redundant, in the profile case, to have to choose the language. It seems like the language the transform is written in should be somehow inferred from the script itself. Why does the user need to choose the language when creating the script and then have to remember and choose it again when applying it? (Not to mention that screen seems to indicate that you can't have the incoming and outgoing transform script for a profile written in different languages). But even if we kept it where the user selects the language, wouldn't it be nice if upon selecting the language only those scripts written in that language were shown to select from. So I am sympathetic to the arguments made by @jimtng and @ccutrer. However, I don't really know what the scripts will look like when defined in the UI. I don't understand the implications of what's being proposed and how that is different (from the end user's perspective) so I can't really weigh in on the counter argument without more of an idea how that will look. As far as I can tell, at least on build #3383, we don't have a UI for creating transformation scripts yet. But from what I can gather, the filename is part of the scripts' UID and therefore it: 1. must conform to the UID restrictions for allowable characters (meaning we can't have It's already somewhat of a problem that applying it on a label follows At a high level:
That's my perspective, for what it's worth. |
:(. I hope I didn't offend you. My personality is that I'm a direct and frank person, but I'm honestly not trying to be offensive, insulting, sarcastic, etc. Now I'm brainstorming here: WHAT IF? What if the script transformation, instead of being a proper transformation service itself was simply a meta-transformation service that listens for new instances of script engines to be registered, and when they are it dynamically registers a new transformation service instance specifically for that engine? Then we could properly say "the JS transformation" or the "Ruby transformation." They would be referenced as "JS(mytransform.js)" from file-based configuration, which has the double-effect of making the proper extension match the transformation's name, which seems to be very important to @J-N-K, as well as restoring some semblance of backwards compatibility with openHAB 3.4's JS transform (though you'd have to install the JS automation addon, instead of the JS transformation provider; honestly I see this as a good change, because then it's up to each addon to document its support of transformations, as opposed to the SCRIPT transformation which has poor discoverability in the docs because it's not actually an addon at all - it's part of core). The UI would automatically change to simply choosing "JS transformation" instead of "script transformation" and then "JS". Other transformation providers wouldn't need any change to satisfy any (now unnecessary) interface changes to support a single service supporting multiple file types. There are probably other pitfalls to this approach that I'm unaware of, and would be happy to have them pointed out to me. |
Thanks for the pointers. I think that would be the ideal scenario, which would address all the issues raised here. |
This won't happen. We would be in a situation even worse than before when we had only "JS Transformation": "Why can I use JS, DSL, Groovy and Ruby but not Python?". The transformation is universal and this will not change. A required metadata for scripting addons contradicts that. |
@rkoshak if we were to change the While (b) sounds nice, eventually we'll have to drop it anyway (when?) and we'll simply delay the inevitable. You know that if we maintain support, people will not go out of their way to change it until it breaks. |
I don't really have a position either way really largely because I don't know whether/how either choice impacts the UI created script transformations. If we did "b", I would not leave it out of the docs. If it's supported, it should be documented, even if it's marked as deprecated in the docs. I really don't like undocumented features. If we do a, we should make sure it's done before OH 4.0 release. It's a breaking change for sure. |
I didn't say any required metadata. I said meta-transformation service. One in core, that's not actually a concrete transformation service, but would enumerate script engines as they're registered, and dynamically create a new transformation service for that script engine. So Python would automatically get one, even though it's not maintained. |
How do you create a UI script transformation? AFAIK it isn't implemented yet. If/when it's implemented, it should contain information about the scriptType / engine that it uses. The UI transformation being created in the UI will be retrieved through its scriptUID as a |
This sounds very cool, although the implementation would be a bit "more complex" than the currently "static" Thinking out loud here: once implemented, the I think practically, from the end user's point of view, this is the smoothest and easiest to understand transition from the old JS transformation. |
There is an open PR created for it to add a transformations registry and the other stuff required in core. I'm not sure the status of it beyond a lot of work has been put into it. Once that's done there will need to be changes to MainUI to support it too which I don't think exists. |
Ah yes, I found that PR. I believe it can be adapted. |
superseded by #3487 |
Support
SCRIPT(file.rb)
syntax as an alternative, not a replacement, toSCRIPT(rb:file.script)
Also
SCRIPT(file.rb?param1=x)
works likeSCRIPT(rb:file.script?param1=x)
The original syntax is still fully supported, so this is not a breaking change.
This makes changing from JS transformation to SCRIPT transformation as easy as changing
JS(myscript.js)
toSCRIPT(myscript.js)
Discussed in #3465
I understand that @J-N-K disagreed with this proposal. However, I feel very strongly about making the script transformation syntax more elegant and intuitive for file-based scripts and I have created this PR as a PoC to demonstrate what I wish to achieve.
Unrelated to the matter, some extra error checks were added to the regex pattern to avoid errors, e.g. when an inline transformation script had a
?
character as part of the code, it would've been extracted as parameters, which shouldn't be the case.If this doesn't negatively affect anything else, I'd appreciate further considerations for this PR. If there are any potential issues that I'm not aware of, I'll try to address them also.