5 ms·
A good refactor does not change behaviour, I would like the author to start with that point. Take many more much smaller steps while doing so. Not touching a pi
by jv_be 2y ago
A good refactor does not change behaviour, I would like the author to start with that point.
Take many more much smaller steps while doing so.
Not touching a piece of code in the first 6 to 9 months is something I don’t really agree with. Breaking complex methods up by extracting variables and methods can really help learning the code, whilst not breaking it.
If you are worried about consistency, just pair up of practice ensemble programming instead of asynchronous code reviews. Leaving a new dev alone with the code and give them feedback about the things they did wrong after they went through everything is just not a great way to treat people in your team.
- kolme 2y agoA refactor does not change behavior, period. By definition. If something changed, it's not a refactor. It's a change. Like in the example where the caching was removed: NOT a refactor. Ore where the timeouts for the requests were changed: NOT a refactor. The definition of refactor: change the structure of the code without altering the behavior. It's like saying a crash is a bad landing.
- sevnin 2y ago"By definition" proceeds to define the word in a way that most people won't agree with. Okay mate. Your definition is ass. The person that wrote the article doesn't agree with you, I don't agree with you. I will still use the word refactor when I talk about simplifying the application such that code becomes simpler through simplifying and improving the design.
- gcarvalho 2y agoI think it’s widely accepted that refactors should not change behavior. That’s my experience, at least.
- sevnin 2y agoHuh, I guess that's true, even on wikipedia. I will have to stop using the word then. Though I'm pretty sure most people use it in day-to-day with much more abandon.
- FooBarBizBazz 2y agoThe metaphor, I think, is that your code is a mathematical function, and, to be even more specific and "toy example" about it, let's say it's a polynomial. If the old code was x^2 + x z + y x + y z then you notice that you can express the same polynomial as: (x + y)*(x + z) It's still the same polynomial, but you "separated concerns", turning it into a product of two simpler factors. Similar ideas apply to sets of tuples. Perhaps you were given {(1, 1), (1, 4), (2, 1), (2, 4), (3, 1), (3, 4)} and you notice that this can be expressed more simply as the Cartesian product: {1, 2, 3} x {1, 4} Again, a literal factoring. You can imagine how variations of this idea would apply to database tables and data structures. That's where I think the word "refactor" comes from.
- sevnin 2y agoMy man, thanks for the explanation but I understand the concept I just didn't agree on definition.
- FooBarBizBazz 2y agoSure. Whenever you post on a forum it's half for anybody else reading, right? I just thought it was interesting to consider the underlying metaphor; maybe people don't think about it. Metaphors, connotations, etymologies -- I find these interesting.
- sevnin 2y agoSure, I agree. You could even respond to me fully selfishly - treat me as a stepping stone just to form your argument, nothing wrong with that.
- nuancebydefault 2y ago
- nxicvyvy 2y agoThat's the definition most people use. https://www.google.com/search?q=refactoring%20definition https://www.google.com/search?q=refactoring%20definition
- whilenot-dev 2y ago> A refactor does not change behavior, period. By definition. Refactoring does not change the external behavior. If you can't change the internal behavior, then you can't reduce complexity. So with that in mind... - changing implicit caching => refactoring - changing implicit timeouts => refactoring - changing explicit caching => more than refactoring - changing explicit timeouts => more than refactoring Because the word external implies conceptual boundaries, I would personally also distinguish refactoring by levels: - system design - service design - program design - component design - module design - function design ...where this blog post only talks about the latter two.
- nuancebydefault 2y agoBy _your_ definition. If you apply it, a lot of effort is needed for little gain. The best refactors i've seen improved behavior while making code more concise.
- deleted 2y ago[deleted]