I like the way you refactored the old snippet.
However, I think it is often important to consider during refactoring what is being improved. The performance? Testability? Readability?
I have a bad feeling about just refactoring because new methods exist or because the number of LOC is being reduced.
For example, I think the readability is improved by how you refactored the code.
Personally I would go even further and extract the lambda functions. IMO this improves readability, reusability and testability of the considered module. But I'm sure there are plenty of people who don't like it:
The main goal here was readability, I had to look at the old code for a good minute to understand what was happening.
Might be because the new declarative methods are just more of a "naming" thing to me.
Anyhow,
I really like your way, it makes sense to extract the function, might also improve them being re-used by other code, so valid point!
As for the article,
I'm considering renaming it to "Modernizing code" because the refactor is a bit obsolete, other than readability it doesn't change anything.
I think you already greatly improved the codebase. And also generally speaking, stressing the importance of refactoring is a very good point to be made in general!
I like the way you refactored the old snippet.
However, I think it is often important to consider during refactoring what is being improved. The performance? Testability? Readability?
I have a bad feeling about just refactoring because new methods exist or because the number of LOC is being reduced.
For example, I think the readability is improved by how you refactored the code.
Personally I would go even further and extract the lambda functions. IMO this improves readability, reusability and testability of the considered module. But I'm sure there are plenty of people who don't like it:
Hey/Hoi Jan,
The main goal here was readability, I had to look at the old code for a good minute to understand what was happening.
Might be because the new declarative methods are just more of a "naming" thing to me.
Anyhow,
I really like your way, it makes sense to extract the function, might also improve them being re-used by other code, so valid point!
As for the article,
I'm considering renaming it to "Modernizing code" because the refactor is a bit obsolete, other than readability it doesn't change anything.
I think you already greatly improved the codebase. And also generally speaking, stressing the importance of refactoring is a very good point to be made in general!
Agreed, that title would nicely show your intent!
Extracting the lambda functions using meaningful and descriptive function names makes the intention clear - even more readily "grokable" and readable