News for hackers. Stuff that matters.
Re:Refactoring in C++: Top Techniques and Best Practices – T... by motorest on Friday December 13, 2024 @02:36AM (#42406655)
> This reads like nothing more than an advertisement of Clion’s refactoring features.

Yes, I think that's the whole point.

> Some of the tips are even quite dangerous and highly context dependent, like creating a base class when two classes share common functionality. That sounds like a refactoring nightmare to happen.

I don't see where that hypothetical danger lies. Deduplicating code is a basic refactorizarion step.

> I’m currently working through a difficult refactor and the most important tips I can give are:

I'm afraid you're going the wrong way about this. No wonder you associated "danger" with refactoring.

The basic steps you take to refactor legacy code are:

- identify code paths that are affected if you touch a specific component,

- identify invariants and expected state changes through that code path. If there is none, add your own (see code seams)

- add tests to verify those invariants (see software vise tests)

- proceed with refactoring.

If you want to learn more, I recommend you pick up the book "working effectively with legacy code" by Michael C Feathers.

Re:Refactoring in C++: Top Techniques and Best Practices – T... by rileymat2 on Friday December 13, 2024 @09:18AM (#42408592)
> I don't see where that hypothetical danger lies. Deduplicating code is a basic refactorizarion step.

Deduplication is one thing and fine, but creating inheritance hierarchies should not be used for simple code reuse, but for representing relationships.