[yast-devel] Never include anything in global namespace
Hi, I just would like to remind that noone should include/extend anything to global namespace in his ruby code. It affects clients, modules, libs and also includes. The most visible part is `include Yast` which cause that all modules living in Yast namespace start living in global namespace and start colliding with ruby classes and modules. But also other smaller modules can cause problem. example of code that can break complete installation is https://github.com/yast/yast-network/blob/11d9c4b7435bb34f5c40c8c19d8c68c587... So please do not do it. Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Fri, Feb 28, 2014 at 03:41:14PM +0100, Josef Reidinger wrote:
I just would like to remind that noone should include/extend anything to global namespace in his ruby code. It affects clients, modules, libs and also includes. The most visible part is `include Yast` which cause that all modules living in Yast namespace start living in global namespace and start colliding with ruby classes and modules. But also other smaller modules can cause problem.
Sadly Ruby uses the term include for something fundamentally different to most other languages, most prominently C (and YCP). No wonder mistakes like that happen. Also see: http://stackoverflow.com/questions/318144/what-is-the-difference-between-inc... "Oddly enough, Ruby's require is analogous to C's include, while Ruby's include is almost nothing like C's include." http://ruby.about.com/b/2008/10/23/a-quick-peek-at-ruby-include-vs-require.h... "This can be confusing as the include verb is used very differently in other languages." Regards, Arvin -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Fri, 28 Feb 2014 16:02:04 +0100 Arvin Schnell <aschnell@suse.de> wrote:
On Fri, Feb 28, 2014 at 03:41:14PM +0100, Josef Reidinger wrote:
I just would like to remind that noone should include/extend anything to global namespace in his ruby code. It affects clients, modules, libs and also includes. The most visible part is `include Yast` which cause that all modules living in Yast namespace start living in global namespace and start colliding with ruby classes and modules. But also other smaller modules can cause problem.
Sadly Ruby uses the term include for something fundamentally different to most other languages, most prominently C (and YCP). No wonder mistakes like that happen.
Also see:
http://stackoverflow.com/questions/318144/what-is-the-difference-between-inc...
Thanks for links. I understand that it can be confusing, so I do not blame anyone, I just want to point to it, so do not repeat such problem ( or less often ).
"Oddly enough, Ruby's require is analogous to C's include, while Ruby's include is almost nothing like C's include."
It is strange to compare object language to C. If I need to find something similar it is like "using" in C++. There is same rule for using "using" in header files, but of course there is some differences. Josef
http://ruby.about.com/b/2008/10/23/a-quick-peek-at-ruby-include-vs-require.h...
"This can be confusing as the include verb is used very differently in other languages."
Yes, it is often used as mixins, but it include everything from target module so even nested classes and constants like it happen in this case. Usual use case is e.g. Enumerable or Comparable mixin. Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (2)
-
Arvin Schnell
-
Josef Reidinger