[yast-devel] Simple example of refactoring
Hi, because we have now ruby I want to show really simple way how we can refactor existing code. I choose just simple example to be easy to understand and on other hand full working. [1] There is two interesting points in it. 1) using minitest for testing, its structure ( so you can imagine how it looks ) and how it can be easy integrated with automake ( nice part is that if you run `make check` then both testsuite is run, old and new one 2) Using ruby builtin regex, so we no longer need our own. If you have any question I welcome it or if you are interested how do different thing in ruby. Josef [1] https://github.com/yast/yast-yast2/compare/0e08c9b...43fd34e6?expand=1 -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On 08/19/2013 05:19 PM, Josef Reidinger wrote:
Hi, because we have now ruby I want to show really simple way how we can refactor existing code. I choose just simple example to be easy to understand and on other hand full working. [1]
There is two interesting points in it. 1) using minitest for testing, its structure ( so you can imagine how it looks ) and how it can be easy integrated with automake ( nice part is that if you run `make check` then both testsuite is run, old and new one 2) Using ruby builtin regex, so we no longer need our own.
Just to add some more info on this refactoring piece. Josef has used a standard Ruby Resolv [1] class to replace our built-in functionality. This will save our time in the future as we don't need to care about our own implementation and saves some space as well as our implementation was a duplicate to standard Ruby library which will be installed anyway. I like the idea and I expect that you will identify and replace more ;) This is actually something that anyone with a basic Ruby knowledge can do. It's could even be marked as, so called, junior job. Bye Lukas #1 http://ruby-doc.org/stdlib-1.9.2/libdoc/resolv/rdoc/Resolv.html -- Lukas Ocilka, Cloud & Systems Management Department SUSE LINUX s.r.o., Praha -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 20 Aug 2013 12:48:26 +0200 Lukas Ocilka <lukas.ocilka@suse.com> wrote:
On 08/19/2013 05:19 PM, Josef Reidinger wrote:
Hi, because we have now ruby I want to show really simple way how we can refactor existing code. I choose just simple example to be easy to understand and on other hand full working. [1]
There is two interesting points in it. 1) using minitest for testing, its structure ( so you can imagine how it looks ) and how it can be easy integrated with automake ( nice part is that if you run `make check` then both testsuite is run, old and new one 2) Using ruby builtin regex, so we no longer need our own.
Just to add some more info on this refactoring piece. Josef has used a standard Ruby Resolv [1] class to replace our built-in functionality. This will save our time in the future as we don't need to care about our own implementation and saves some space as well as our implementation was a duplicate to standard Ruby library which will be installed anyway.
I like the idea and I expect that you will identify and replace more ;) This is actually something that anyone with a basic Ruby knowledge can do. It's could even be marked as, so called, junior job.
Well, it is questionable if it is junior job, as there can be small differences between ruby and our implementation, so it needs a lot of testing of corner cases and good knowledge both implementations if there is differences. And to be honest in this change I heavily believe in tests because compare these two regexp is too much for my brain :) [1][2] Also I need to consider what is better to use as there is also IPAddr class in ruby, which for me is better to use, but it is different concept then our, so it is not so elegant to refactoring of IP module ( but I strongly recommend to use it to replace IP module in ruby code because you can use it as object ) [3] Josef [1] https://github.com/ruby/ruby/blob/ruby_2_0_0/lib/resolv.rb#L2172 [2] https://github.com/yast/yast-yast2/blob/0e08c9b93c2c730e79ea36451ea715a5746d... [3] http://www.ruby-doc.org/stdlib-2.0/libdoc/ipaddr/rdoc/IPAddr.html
Bye Lukas
#1 http://ruby-doc.org/stdlib-1.9.2/libdoc/resolv/rdoc/Resolv.html
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
# jreidinger@suse.cz / 2013-08-21 09:38:08 +0200:
On Tue, 20 Aug 2013 12:48:26 +0200 Lukas Ocilka <lukas.ocilka@suse.com> wrote:
On 08/19/2013 05:19 PM, Josef Reidinger wrote:
Hi, because we have now ruby I want to show really simple way how we can refactor existing code. I choose just simple example to be easy to understand and on other hand full working. [1]
There is two interesting points in it. 1) using minitest for testing, its structure ( so you can imagine how it looks ) and how it can be easy integrated with automake ( nice part is that if you run `make check` then both testsuite is run, old and new one 2) Using ruby builtin regex, so we no longer need our own.
Just to add some more info on this refactoring piece. Josef has used a standard Ruby Resolv [1] class to replace our built-in functionality. This will save our time in the future as we don't need to care about our own implementation and saves some space as well as our implementation was a duplicate to standard Ruby library which will be installed anyway.
I like the idea and I expect that you will identify and replace more ;) This is actually something that anyone with a basic Ruby knowledge can do. It's could even be marked as, so called, junior job.
Well, it is questionable if it is junior job, as there can be small differences between ruby and our implementation, so it needs a lot of testing of corner cases and good knowledge both implementations if there is differences.
it's not exactly a groundbreaking job, and anybody doing it will need to know (through tests) behavior of both implementations.
And to be honest in this change I heavily believe in tests because compare these two regexp is too much for my brain :) [1][2]
expanding the quantifiers into branches, we get resolv.rb: /0 |1 |1[0-9] |1[0-9][0-9] |2 |2[0-4] |2[0-4][0-9] |25 |25[0-5] |2[6-9] |[3-9] |[3-9][0-9] /x IP.rb: /[0-9] |[1-9][0-9] |1[0-9][0-9] |2[0-4][0-9] |25[0-5] /x with a bit of shuffling around, resolv.rb version becomes /0 |1 |2 |[3-9] |1[0-9] |2[0-4] |25 |2[6-9] |[3-9][0-9] |1[0-9][0-9] |2[0-4][0-9] |25[0-5] /x which reduces to /[0-9] |[1-9][0-9] |1[0-9][0-9] |2[0-4][0-9] |25[0-5] /x => they're the same.
[1] https://github.com/ruby/ruby/blob/ruby_2_0_0/lib/resolv.rb#L2172 [2] https://github.com/yast/yast-yast2/blob/0e08c9b93c2c730e79ea36451ea715a5746d...
-- roman -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (3)
-
Josef Reidinger
-
Lukas Ocilka
-
Roman Neuhauser