Verification ? new AcceptedDataAudit(data) : new CorruptedDataAudit(data)) Var auditEngine = InitializeAuditEngine(info) Var auditEngine = InitializeAuditEngine() Ĭollapsing the first region to concentrate on the second is not only risky: we can easily forget about the exception stopping the flow (there could be a guard clause with a return instead, which is even more difficult to spot), but also would have a problem if the code should be refactored this way: private void DoSomething() Imagine you have: private void DoSomething() Using regions in this case can also make the refactoring more difficult. If your method does A, then B, it's logical to create two regions, but this is a wrong approach instead, you should refactor the method into two separate methods. Regions, on the other hand, are intended to separate different things. If there are only ten lines in a method, you probably wouldn't use regions to hide five of them when working on other five.Īlso, each method must do one and one only thing. Don't use regions inside methods refactor instead They require more work which doesn't increase the quality or the readability of the code, which doesn't reduce the number of bugs, and which may only make the code more complicate to refactor. A code smell is a symptom which indicates that there is a problem in the design which will potentially increase the number of bugs: this is not the case for regions, but regions can contribute creating code smells, like long methods.Īn anti-pattern (or antipattern) is a pattern used in social or business operations or software engineering that may be commonly used but is ineffective and/or counterproductive in practice
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |