New answers tagged

2

This looks like a factory method of which is not necessarily an anti pattern. You're always going to need an if-condition somewhere, and the purpose of factory method is to centralise the scattered condition check into a single place. If this is the only place in your code where you need to check model_arch, this isn't an anti pattern at all and the factory ...


5

Not all bad code has a predefined type or name. Sometimes, it's easier to express what the code does wrong instead of what arbitrary name we've chosen for it. This code violates the Open-Closed Principle, which states that objects should be open for extension, but closed for modification. Whenever you extend your codebase (i.e. adding an extra kind of layer),...


1

you would write for each class tests in a separate file that ensure compatibility for an implementation Don't be dogmatic about this. If you have two implementations which under all circumstances should have the same functionality, then just write one set of and run the tests twice with the different implementations.


0

In addition to your desire to be DRY you should consider scope. You may isolate your expression in a method but it will end up being out of place and noisy to other scopes, which will see it but to which it will be meaningless. Therefore I would be hesitant to put it in a method if it would not save a whole lot of repetition. If you do wrap it in a method ...


0

If there is lots of code to evaluate the Boolean expression, at some point you should extract it just because of the amount of code. I assume that’s not the case. Something like “hasThreeRepeatedDigits”: What the code does and its purpose are the same. If someone else needs to check for three repeated digits, duplicating the code is just a tiny inefficiency, ...


Top 50 recent answers are included