News for hackers. Stuff that matters.
Re:Good Refactoring vs. Bad Refactoring by kolme on Tuesday August 20, 2024 @05:08AM (#41298229)
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.

Re:Good Refactoring vs. Bad Refactoring by sevnin on Tuesday August 20, 2024 @06:02AM (#41298517)
"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.
Re:Good Refactoring vs. Bad Refactoring by gcarvalho on Tuesday August 20, 2024 @06:13AM (#41298565)
I think it’s widely accepted that refactors should not change behavior. That’s my experience, at least.
Re:Good Refactoring vs. Bad Refactoring by sevnin on Tuesday August 20, 2024 @07:04AM (#41298830)
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.
Re:Good Refactoring vs. Bad Refactoring by FooBarBizBazz on Tuesday August 20, 2024 @09:45AM (#41300015)
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.

Re:Good Refactoring vs. Bad Refactoring by sevnin on Tuesday August 20, 2024 @09:57AM (#41300133)
My man, thanks for the explanation but I understand the concept I just didn't agree on definition.
Re:Good Refactoring vs. Bad Refactoring by FooBarBizBazz on Tuesday August 20, 2024 @10:26AM (#41300378)
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.
Re:Good Refactoring vs. Bad Refactoring by sevnin on Tuesday August 20, 2024 @02:36PM (#41302700)
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.
Re:Good Refactoring vs. Bad Refactoring by nuancebydefault on Tuesday August 20, 2024 @06:11PM (#41304621)
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.

Re:Good Refactoring vs. Bad Refactoring by sevnin on Wednesday August 21, 2024 @01:40AM (#41307115)
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.
Re:Good Refactoring vs. Bad Refactoring by xigoi on Wednesday August 21, 2024 @05:05PM (#41314181)
A polynomial is a mathematical object. There are no integer overflows or float imprecisions in mathematics.
Re:Good Refactoring vs. Bad Refactoring by nuancebydefault on Thursday August 22, 2024 @04:24PM (#41324095)
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.
Re:Good Refactoring vs. Bad Refactoring by nxicvyvy on Tuesday August 20, 2024 @06:15AM (#41298576)
That's the definition most people use.

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

Re:Good Refactoring vs. Bad Refactoring by whilenot-dev on Tuesday August 20, 2024 @06:36AM (#41298691)
> 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.

Re:Good Refactoring vs. Bad Refactoring by nuancebydefault on Tuesday August 20, 2024 @06:06PM (#41304577)
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.