8 ms·
I think it’s widely accepted that refactors should not change behavior. That’s my experience, at least.
by gcarvalho 2y ago
I 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 agoIf you change the polynomial, you change the order of calculations and hence change behaviour. You might get overflows in case of integers or different precision in case of floats. Nice to learn where the word originates from. Often the meaning of words change over time. E.g. today no horses need involved in bootstrapping.
- sevnin 2y agoHe said "I think" implying that he is not fully sure about the etymology. There is a history section on wikipedia for refactoring if you are interested.
- xigoi 2y agoA polynomial is a mathematical object. There are no integer overflows or float imprecisions in mathematics.
- nuancebydefault 2y agoYou are right but in fact the maths are only a means to an end, a model that isn't exactly equal to the final real world implementation in analog or digital electronics.