Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think it’s widely accepted that refactors should not change behavior. That’s my experience, at least.


Huh, 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.


The 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.


If 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.


He 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.


A polynomial is a mathematical object. There are no integer overflows or float imprecisions in mathematics.


You 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.


My man, thanks for the explanation but I understand the concept I just didn't agree on definition.


Sure. 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.


Sure, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: