Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Let’s Refactor Some Ruby Code
Ana María Martínez Gómez
http://anamaria.martinezgomez.name | anamma06@gmail.com | @anamma_06
Ruby and I are turning 25
https://build.opensuse.or
g
https://github.com/openSUSE/open-build-
service
OBS = Open Build Service
Let’s Refactor Some Ruby Code
Scary comment
src/api/lib/activexml/node.rb
src/api/lib/activexml/node.rb
src/api/lib/activexml/node.rb
https://github.com/openSUSE/open-build-
service/pull/3947
src/api/lib/activexml/node.r
b
comments are a bad ideacomments are a bad idea
nodocnodoc
protectedprotected
Reusing code
piece_of_code_to_reuse (param1, param2)
piece_of_code_to_reuse
piece_of_code_to_reuse
"Param1_1",
params1_2
"Param2_1",
pa...
piece_of_code_to_reuse (param1, param2)
piece_of_code_to_reuse
piece_of_code_to_reuse
"Param1_1",
params1_2
"Param2_1",
pa...
https://github.com/openSUSE/open-build-
service/pull/4105
src/api/app/models/kiwi/image.rb
https://github.com/openSUSE/open-build-
service/pull/4119
src/api/app/models/kiwi/image.rb
Logical conditions
src/api/app/models/flag.rb
ONLY ONE OF THEM IS TRUE
https://github.com/openSUSE/open-build-
service/pull/2324
src/api/app/models/flag.rb
concat + uniq
https://github.com/openSUSE/open-build-
service/pull/4104
src/api/lib/backend/api/build_results/binaries.rb
https://github.com/openSUSE/open-build-
service/pull/4104
src/api/lib/backend/api/build_results/binaries.rb
https://github.com/openSUSE/open-build-
service/pull/4104
src/api/lib/backend/api/build_results/binaries.rb
https://github.com/openSUSE/open-build-
service/pull/4104
src/api/lib/backend/api/build_results/binaries.rb
a + ba + b
a.concat ba.concat b
a + b + ca + b + c
a.concat b, ca.concat b, c
a | ba | b
a.union ba.union b
a | b | ca | b...
https://bugs.ruby-
lang.org/issues/14097
StandStand
up!up!
array1.concat(array2,
array3).uniq!
array1 = (array1 | array2 |
array3)
array1.union(array2, array
3)
11
22
33
https://bugs.ruby-
lang.org/issues/14097
https://github.com/ruby/ruby/pull/1747
Yak
ShavingAny apparently useless activity which, by allowing you to overcome
intermediate difficulties, allows you to sol...
https://github.com/ruby/ruby/pull/1756
Ruby is using SVNRuby is using SVN
We work with peopleWe work with people
Every team works differentlyEvery team works differently
I need to be more patientI...
It is a
reasonable
proposal
https://bugs.ruby-lang.org/issues/14097https://bugs.ruby-lang.org/issues/14097
Rails helpers
https://github.com/openSUSE/open-build-
service/pull/5567
["Executive", "Developer", "Consultant", "Strategist", "Agent", ...
Can it be improved?Can it be improved?
https://github.com/openSUSE/open-build-
service/pull/5567
- improved code- improved code
- options_from_collection_for_select- options_from_collection_for_select
- itself- itself
-...
https://github.com/rails/rails/issues/3354
6
Rails helpers areRails helpers are
exposing privateexposing private
methods!m...
https://github.com/rails/rails/pull/33547
GETGET
INVOLVED!INVOLVED!
Thanks!
http://anamaria.martinezgomez.name | anamma06@gmail.com | @anamma_06
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Let's refactor some Ruby code - EuRuKo 2018
Prochain SlideShare
Chargement dans…5
×

Let's refactor some Ruby code - EuRuKo 2018

111 vues

Publié le

This year both Ruby and I are turning 25 years old. It is amazing to see all the great Ruby code that has been written over time. But we all also have to admit that at some point we have found, or written, Ruby code that was not that great. Even the code that was pretty good at one point, could now be improved, due to the evolution of Ruby.
In this talk I will speak about how it was facing some code in Ruby and RoR open source projects, how this code was refactored and what I learned while doing it.

The presentation is licensed under a CC-BY except the pictures of Ana dressed up, the picture of Evan, the picture with Matz and the gifs. Some pictures of the presentations are taken from https://www.pexels.com and licensed under CC 0. Thanks to all photographers that share they pictures under permissive licenses!

Publié dans : Logiciels
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Let's refactor some Ruby code - EuRuKo 2018

  1. 1. Let’s Refactor Some Ruby Code Ana María Martínez Gómez http://anamaria.martinezgomez.name | anamma06@gmail.com | @anamma_06
  2. 2. Ruby and I are turning 25
  3. 3. https://build.opensuse.or g https://github.com/openSUSE/open-build- service OBS = Open Build Service
  4. 4. Let’s Refactor Some Ruby Code
  5. 5. Scary comment
  6. 6. src/api/lib/activexml/node.rb
  7. 7. src/api/lib/activexml/node.rb
  8. 8. src/api/lib/activexml/node.rb
  9. 9. https://github.com/openSUSE/open-build- service/pull/3947 src/api/lib/activexml/node.r b
  10. 10. comments are a bad ideacomments are a bad idea nodocnodoc protectedprotected
  11. 11. Reusing code
  12. 12. piece_of_code_to_reuse (param1, param2) piece_of_code_to_reuse piece_of_code_to_reuse "Param1_1", params1_2 "Param2_1", params2_2 def # code to be reused which uses two parameters code to be reused which uses two parametersend
  13. 13. piece_of_code_to_reuse (param1, param2) piece_of_code_to_reuse piece_of_code_to_reuse "Param1_1", params1_2 "Param2_1", params2_2 def # code to be reused which uses two parametersend { "Param1_1" => params1_2, "Params2_1" => params2_2 } param1 = key.to_s# code to be reused which uses two parametersend .each do |key, param2| param1 = key.capitalize.to_s { param1_1: params1_2, params2_1: params2_2 }.each do |key, param2| { Param1_1: params1_2, Params2_1: params2_2 }.each do |key, param2|
  14. 14. https://github.com/openSUSE/open-build- service/pull/4105 src/api/app/models/kiwi/image.rb
  15. 15. https://github.com/openSUSE/open-build- service/pull/4119 src/api/app/models/kiwi/image.rb
  16. 16. Logical conditions
  17. 17. src/api/app/models/flag.rb ONLY ONE OF THEM IS TRUE
  18. 18. https://github.com/openSUSE/open-build- service/pull/2324 src/api/app/models/flag.rb
  19. 19. concat + uniq
  20. 20. https://github.com/openSUSE/open-build- service/pull/4104 src/api/lib/backend/api/build_results/binaries.rb
  21. 21. https://github.com/openSUSE/open-build- service/pull/4104 src/api/lib/backend/api/build_results/binaries.rb
  22. 22. https://github.com/openSUSE/open-build- service/pull/4104 src/api/lib/backend/api/build_results/binaries.rb
  23. 23. https://github.com/openSUSE/open-build- service/pull/4104 src/api/lib/backend/api/build_results/binaries.rb
  24. 24. a + ba + b a.concat ba.concat b a + b + ca + b + c a.concat b, ca.concat b, c a | ba | b a.union ba.union b a | b | ca | b | c a.union b, ca.union b, c
  25. 25. https://bugs.ruby- lang.org/issues/14097
  26. 26. StandStand up!up!
  27. 27. array1.concat(array2, array3).uniq! array1 = (array1 | array2 | array3) array1.union(array2, array 3) 11 22 33
  28. 28. https://bugs.ruby- lang.org/issues/14097
  29. 29. https://github.com/ruby/ruby/pull/1747
  30. 30. Yak ShavingAny apparently useless activity which, by allowing you to overcome intermediate difficulties, allows you to solve a larger problem Refactor OBS horrible code Add new method to Ruby Improve Ruby Array efficiency
  31. 31. https://github.com/ruby/ruby/pull/1756
  32. 32. Ruby is using SVNRuby is using SVN
  33. 33. We work with peopleWe work with people Every team works differentlyEvery team works differently I need to be more patientI need to be more patient
  34. 34. It is a reasonable proposal
  35. 35. https://bugs.ruby-lang.org/issues/14097https://bugs.ruby-lang.org/issues/14097
  36. 36. Rails helpers
  37. 37. https://github.com/openSUSE/open-build- service/pull/5567 ["Executive", "Developer", "Consultant", "Strategist", "Agent", "Producer", "Executive", "Officer", "Agent", "Director", "Orchestrator", "Administrator", "Officer", "Strategist", "Analyst", "Officer", "Liaison", "Designer", "Producer", "Orchestrator", "Director", "Representative", "Facilitator", "Strategist", "Representative", "Agent", "Orchestrator", "Associate", "Agent", "Coordinator", "Developer", "Strategist", "Technician", "Consultant", "Facilitator", "Planner", "Executive", "Strategist", "Facilitator", "Specialist", "Strategist", "Producer", "Executive", "Agent", "Planner", "Specialist", "Orchestrator", "Orchestrator", "Producer", "Agent"] [["Executive", "executive"], ["Developer", "developer"], ["Consultant", "consultant"], ["Strategist", "strategist"], ["Agent", "agent"], ["Producer", "producer"], ["Executive", "executive"], ["Officer", "officer"], ["Agent", "agent"], ["Director", "director"], ["Orchestrator", "orchestrator"], ["Administrator", "administrator"], ["Officer", "officer"], ["Strategist", "strategist"], ["Analyst", "analyst"], ["Officer", "officer"], ["Liaison", "liaison"], ["Designer", "designer"], ["Producer", "producer"], ["Orchestrator", "orchestrator"], ["Director", "director"], ["Representative", "representative"], ["Facilitator", "facilitator"], ["Strategist", "strategist"], ["Representative", "representative"], ["Agent", "agent"], ["Orchestrator", "orchestrator"], ["Associate", "associate"], ["Agent", "agent"], ["Coordinator", "coordinator"], ["Developer", "developer"], ["Strategist", "strategist"], ["Technician", "technician"], ["Consultant", "consultant"], ["Facilitator", "facilitator"], ["Planner", "planner"], ["Executive", "executive"], ["Strategist", "strategist"], ["Facilitator", "facilitator"], ["Specialist", "specialist"], ["Strategist", "strategist"], ["Producer", "producer"], ["Executive", "executive"], ["Agent", "agent"], ["Planner", "planner"], ["Specialist", "specialist"], ["Orchestrator", "orchestrator"], ["Orchestrator", "orchestrator"], ["Producer", "producer"], ["Agent", "agent"]]
  38. 38. Can it be improved?Can it be improved?
  39. 39. https://github.com/openSUSE/open-build- service/pull/5567
  40. 40. - improved code- improved code - options_from_collection_for_select- options_from_collection_for_select - itself- itself - but that’s not all...- but that’s not all...
  41. 41. https://github.com/rails/rails/issues/3354 6 Rails helpers areRails helpers are exposing privateexposing private methods!methods!
  42. 42. https://github.com/rails/rails/pull/33547
  43. 43. GETGET INVOLVED!INVOLVED!
  44. 44. Thanks! http://anamaria.martinezgomez.name | anamma06@gmail.com | @anamma_06

×