Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,637 members, 7,955,318 topics. Date: Saturday, 21 September 2024 at 10:33 PM |
Nairaland Forum / Science/Technology / Programming / Code Refactoring (842 Views)
Code Refactoring by harryobas: 7:35pm On Jul 08, 2012 |
Code refactoring is a "disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior",undertaken in order to improve some of the nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve the maintainability of the source code. According Joshua Kerievsky, by continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you'll find that it is easier to extend and maintain code. |
Re: Code Refactoring by ektbear: 6:37am On Jul 09, 2012 |
Refactoring is pretty key. You have some long-azz function that does many things: break it into pieces. You find yourself copying and pasting your code and thus have two similar functions: refactor. |
Re: Code Refactoring by Nobody: 7:17pm On Jul 10, 2012 |
i'll share a little of my experience, i have this logic working get settings value from DB, check the display combo box if it's there if it's there, set default selection to it, to do this in the language/toolkit am using, it requires i call a findText() method which will return the index as int, then i'll setCurrentIndex to the index. if it's not there, add the settings to the combo box and set current index to it, it will be correct to search for the index so i can setCurrentIndex to it This went well, Oh! i have 3 more of such to do. at first i copied and repasted the whole code and started changing the widget names when it struck me, why not have a function hold that logic and i'll pass the names in as parameters. (since python actually pass object references around instead of the actual object) so i ended up with this
Now compare the above to the disaster i would have ended up with below.
It becomes even more work when there is a need to modify the logic later on trust me, there is joy in knowing you did it right and well |
Re: Code Refactoring by ektbear: 12:42am On Jul 11, 2012 |
Or a simpler instance of where refactoring can be used: 1. class A def really_long_function_that_does_multiple_things end end 2. class A end class B def long_function_that_modifies B's instance of A that could be made a separate method of the class A end end Things of this nature are what I've seen pretty frequently in my personal experiences. |
(1) (Reply)
How Can Do This On A Java Derby Resultset / 2013 Google Cloud Platform Developer Challenge / Fresh Spamming Tools
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12 |