[yast-devel] YaST in ruby and UI terms
Hi, I would like to discuss one think that is related to creating UI in YaST in ruby. In YCP it uses terms. In ruby generic terms looks like: term(:VBox,...) but it is not much nice for me, so I create few shortcuts for known UI elements and it looks like this: VBox(...) There is a problem. In UI is often used terms `id and `opts, but it doesn't start with uppercase and there is high chance to collide with existing methods ( beside id collide with ruby id method ). So I propose to translate it to ID(:id) and OPTS(:strechable,:notify) alternative can be Opts and Id. what is your opinion? Thanks Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
* Josef Reidinger <jreidinger@suse.cz> [Jun 25. 2013 11:35]:
Hi, I would like to discuss one think that is related to creating UI in YaST in ruby. In YCP it uses terms. In ruby generic terms looks like:
term(:VBox,...)
but it is not much nice for me, so I create few shortcuts for known UI elements and it looks like this:
VBox(...)
Agreed, the latter one looks so much nicer.
There is a problem. In UI is often used terms `id and `opts, but it doesn't start with uppercase and there is high chance to collide with existing methods ( beside id collide with ruby id method ).
Usage of object#id is not a problem if 'id' is defined in object's class.
So I propose to translate it to ID(:id) and OPTS(:strechable,:notify)
Ugh, all caps is reserved for constants in Ruby.
alternative can be Opts and Id. what is your opinion?
libyui-bindings has more complete examples (https://github.com/kkaempf/libyui-bindings/tree/master/swig/ruby/examples) which could help guiding a decision. Klaus -- SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5, 90409 Nürnberg, Germany -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 25 Jun 2013 12:28:19 +0200 Klaus Kaempf <kkaempf@suse.de> wrote:
* Josef Reidinger <jreidinger@suse.cz> [Jun 25. 2013 11:35]:
Hi, I would like to discuss one think that is related to creating UI in YaST in ruby. In YCP it uses terms. In ruby generic terms looks like:
term(:VBox,...)
but it is not much nice for me, so I create few shortcuts for known UI elements and it looks like this:
VBox(...)
Agreed, the latter one looks so much nicer.
There is a problem. In UI is often used terms `id and `opts, but it doesn't start with uppercase and there is high chance to collide with existing methods ( beside id collide with ruby id method ).
Usage of object#id is not a problem if 'id' is defined in object's class.
So I propose to translate it to ID(:id) and OPTS(:strechable,:notify)
Ugh, all caps is reserved for constants in Ruby.
OK, good argument.
alternative can be Opts and Id. what is your opinion?
libyui-bindings has more complete examples (https://github.com/kkaempf/libyui-bindings/tree/master/swig/ruby/examples) which could help guiding a decision.
To be honest, I don't like this examples, it looks like old C gtk where create every element is pain. Compare this examples with elegance of translated YCP code - https://github.com/kobliha/yast-services-manager/blob/master/src/clients/ser... I just want to get rid of annoying id, header and opt term. So after your comments I propose to create shortcuts Id, Opt and Header that creates such terms. Any objections? Josef
Klaus
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
* Josef Reidinger <jreidinger@suse.cz> [Jun 25. 2013 13:26]:
libyui-bindings has more complete examples (https://github.com/kkaempf/libyui-bindings/tree/master/swig/ruby/examples) which could help guiding a decision.
To be honest, I don't like this examples, it looks like old C gtk where create every element is pain.
Lol - I don't like it either. It should just server as an example for the discussion.
Compare this examples with elegance of translated YCP code - https://github.com/kobliha/yast-services-manager/blob/master/src/clients/ser...
Thanks, thats helpful. I was missing this context.
I just want to get rid of annoying id, header and opt term. So after your comments I propose to create shortcuts Id, Opt and Header that creates such terms.
This is one (nice) way to solve this. ComboBox( term(:id, IDs::DEFAULT_TARGET), term(:opt, :notify), _('Default System &Target'), [] ) would change to ComboBox( Id(IDs::DEFAULT_TARGET), Opt(:notify), _('Default System &Target'), [] ) Another, probably more Ruby-like, is using hashes (as trailing arguments): ComboBox _('Default System &Target'), [], :id => IDs::DEFAULT_TARGET, :opt => :notify, [I removed the parantheses for ComboBox for readability] (see http://mikepackdev.com/blog_posts/8-tuesday-tricks-splatting for example) Comments ? Klaus -- SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5, 90409 Nürnberg, Germany -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 25 Jun 2013 13:47:40 +0200 Klaus Kaempf <kkaempf@suse.de> wrote:
* Josef Reidinger <jreidinger@suse.cz> [Jun 25. 2013 13:26]:
libyui-bindings has more complete examples (https://github.com/kkaempf/libyui-bindings/tree/master/swig/ruby/examples) which could help guiding a decision.
To be honest, I don't like this examples, it looks like old C gtk where create every element is pain.
Lol - I don't like it either. It should just server as an example for the discussion.
Compare this examples with elegance of translated YCP code - https://github.com/kobliha/yast-services-manager/blob/master/src/clients/ser...
Thanks, thats helpful. I was missing this context.
It is locilka attempt to try ruby code from scratch and can nicely demonstrate how will look translated code. Real translated code is available only on installation DVDs and in source RPMs in YaST:Head:ruby project. But from M4 you will be able to see it everywhere :)
I just want to get rid of annoying id, header and opt term. So after your comments I propose to create shortcuts Id, Opt and Header that creates such terms.
This is one (nice) way to solve this.
ComboBox( term(:id, IDs::DEFAULT_TARGET), term(:opt, :notify), _('Default System &Target'), [] )
would change to
ComboBox( Id(IDs::DEFAULT_TARGET), Opt(:notify), _('Default System &Target'), [] )
Another, probably more Ruby-like, is using hashes (as trailing arguments):
ComboBox _('Default System &Target'), [], :id => IDs::DEFAULT_TARGET, :opt => :notify,
I agree that hash is more ruby way ( and I also consider it), but it is problem for automatic translation. Ruby bindings use UI-bindings ( so it use Y2 component system to call UI function ) and such functions needs term. And I cannot automatic determine what is hash and what is hash that should be translated to term. Also challenge can be argument reordering as now order can be different then using trailing hash. I don't say that it is not possible, but it is currently out of scope ( as it include define special class heirarchy for UI and implement its translation via ui-bindings or call it directly via ruby-bindings, but there is risk, that there can be some bugs that is not in UI-bindings ). So improve UI creation in YaST is for different usefull project.
[I removed the parantheses for ComboBox for readability]
(see http://mikepackdev.com/blog_posts/8-tuesday-tricks-splatting for example)
Comments ?
I know this ruby feature and it is really nice, but not much usable when we need to communicate via Y2 component system. Also there is now challenge with default parameters, but I plan to fix it as ruby1.9 can say number of possible arguments and I can create overloaded method. So I implement first solution. Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On 25/06/13 13:47, Klaus Kaempf wrote:
ComboBox _('Default System &Target'), [], :id => IDs::DEFAULT_TARGET, :opt => :notify,
I like this idea. Ruby 2.0 supports keyword (named) parameters, and hashes are automatically converted to keyword arguments IIRC. http://blog.rubyhead.com/2013/02/26/ruby-2-0-getting-started-named-parameter... Why I like it, because id, opts are optional. In the sense that opts are optional by definition and id is not, but we could auto-generate one if it is not present. -- Duncan Mac-Vicar P. - http://www.suse.com/ SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5, 90409 Nürnberg, Germany -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (3)
-
Duncan Mac-Vicar P.
-
Josef Reidinger
-
Klaus Kaempf