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

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.


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


By _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.


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


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


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.


That's the definition most people use.

https://www.google.com/search?q=refactoring%20definition




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

Search: