Refactoring if/else logic

You should use Strategies, possibly implemented within an enum, e.g.: enum UserType { ADMIN() { public void doStuff() { // do stuff the Admin way } }, STUDENT { public void doStuff() { // do stuff the Student way } }; public abstract void doStuff(); } As the code structure within each outermost if branch … Read more

Visual Studio: Is there a “move class to different namespace” refactoring?

Visual Studio 2019 provides at least 2 built-in options: ‘Move to namespace…’ refactoring can be triggered on any class, and VS will prompt for the target namespace. ‘Change namespace to…’ refactoring is provided for when the current file namespace doesn’t match with the folder structure. This can be used to move individual classes to a … Read more

How do I deal with “signed/unsigned mismatch” warnings (C4018)?

It’s all in your things.size() type. It isn’t int, but size_t (it exists in C++, not in C) which equals to some “usual” unsigned type, i.e. unsigned int for x86_32. Operator “less” (<) cannot be applied to two operands of different sign. There’s just no such opcodes, and standard doesn’t specify, whether compiler can make … Read more