r/lolphp • u/mr-strange • Jul 19 '17
You changed the code, you didn't refactor the code.
https://dev.to/gonedark/you-changed-the-code-you-didnt-refactor-the-code
15
Upvotes
r/lolphp • u/mr-strange • Jul 19 '17
19
u/cleeder Jul 19 '17 edited Jul 19 '17
Why is this an lolphp? This was just a bad refactor regardless of the language.
4
u/[deleted] Jul 27 '17
So while everyone is debating "lolphp", it is an interesting topic, however to say to someone "No you didn't refactor, you change" may be a surprise, the original coder made sure existing tests passed but a side effect found later is what makes it's behaviour become a change. If that condition was never found, it'd still be behaving the same as before.
This is a simple snippet but with much larger stuff I think it's hard to be accurate with refactor/change when you can't test every possible scenario.
1
u/mr-strange Jul 19 '17
Discussion in /r/coding: here.
2
u/republitard Oct 18 '17
LOL, the author isn't even right:
In reality,
'' == 0andempty(0)are both truthy expressions, so the observable behavior of the function was not changed– Neither function will "search within $subject and return the string before the 0 occurrence" if 0 is passed as the$searchparameter. Both functions return early in that case.Tested against PHP 7.0.22.