anti-patterns

Error codes within exception vs exceptions hierarchy

风流意气都作罢 提交于 2019-12-03 12:04:01
问题 Do you think it is ok to use error codes within exception to specify error type? Please take a look on this code: public class MyException extends Exception { public static final String ERROR_CODE_INVALID_NAME = ""; public static final String ERROR_CODE_INVALID_ID = ""; ... private String errorCode; public MyException(String message, String errorCode) { super(message); this.errorCode = errorCode; } public String getErrorCode() { return errorCode; } } I know that it is better to use enum

Performance anti patterns

℡╲_俬逩灬. 提交于 2019-12-03 11:55:27
问题 I am currently working for a client who are petrified of changing lousy un-testable and un-maintainable code because of "performance reasons". It is clear that there are many misconceptions running rife and reasons are not understood, but merely followed with blind faith. One such anti-pattern I have come across is the need to mark as many classes as possible as sealed internal ... *RE-Edit: I see marking everything as sealed internal (in C#) as a premature optimisation.* I am wondering what

Is there a name for this anti-pattern/code smell?

偶尔善良 提交于 2019-12-03 10:55:47
Let me start by saying that I do not advocate this approach, but I saw it recently and I was wondering if there was a name for it I could use to point the guilty party to. So here goes. Now you have a method, and you want to return a value. You also want to return an error code. Of course, exceptions are a much better choice, but for whatever reason you want an error code instead. Remember, I'm playing devil's advocate here. So you create a generic class, like this: class FunctionResult<T> { public T payload; public int result; } And then declare your functions like this: FunctionResult<string

C#: Enum anti-patterns [closed]

a 夏天 提交于 2019-12-03 10:04:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago . There has been talk of Enums in general violating Clean Code-principles, so I'm looking for people's favorite Enum anti-patterns and alternative solutions for these. For example I've seen code like this: switch(enumValue) { case myEnum.Value1: // ... break; case myEnum.Value2: //

How to overcome the anti-pattern “Big Ball of Mud”?

柔情痞子 提交于 2019-12-03 09:57:27
What causes a computer program to turn into a Big Ball of Mud ? Is it possible to recover from this anti-pattern? Are there proven refactoring methods that can be applied? A Big Ball Of Mud normally occurs because of one of the following: Change of Requirement s - You architect a solution with one set of requirements, which over time change and now, you are probably catering to a different audience who wants to use the same product with slightly different requirements. You bake those requirements into the same product and you end up with a BBOM. Change of Developers - The original product has

What is the name of this bad practice / anti-pattern?

不问归期 提交于 2019-12-03 08:06:30
问题 I'm trying to explain to my team why this is bad practice, and am looking for an anti-pattern reference to help in my explanation. This is a very large enterprise app, so here's a simple example to illustrate what was implemented: public void ControlStuff() { var listOfThings = LoadThings(); var listOfThingsThatSupportX = new string[] {"ThingA","ThingB", "ThingC"}; foreach (var thing in listOfThings) { if(listOfThingsThatSupportX.Contains(thing.Name)) { DoSomething(); } } } I'm suggesting

Misused design patterns

ぐ巨炮叔叔 提交于 2019-12-03 06:38:35
问题 Are there, in the canonical Gang of Four list, any design patterns that you often find misused, misunderstood or overused (other than the highly debated Singleton)? In other words, is there a design pattern you would advise to think twice before using? (And why?) 回答1: The singleton pattern .. global state often leads to problems when testing Any code depending on the singleton gets harder and harder to test because that dependency isn't easily mocked.. 回答2: Factory Patterns... I was

What is the worst abuse you've seen of LINQ syntax? [closed]

拟墨画扇 提交于 2019-12-03 06:06:31
Closed . This question is opinion-based. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . On a recent Dot Net Rocks podcast , Jon Skeet mentioned possible abuses of LINQ syntax. What examples have people seen where crazy things are being done with LINQ? It has to be a ray-tracer implemented in a single LINQ expression . Clever, beautiful, and scary all at the same time! Jon Skeet Here are my own abuses - purely for the sake of having a laugh at a geek night, and

Rich Domain Model and ORM

假装没事ソ 提交于 2019-12-03 05:46:50
问题 Martin Fowler considers Anemic Domain Model as an anti-pattern. Rolling the Persistence Model as the Domain Model seems severely off too due to Object Relational Impedence Missmatch. For persistence and normalization sakes, we tend to break down classes to very small tiny pieces, slapping methods on top of these classes is silly. Plus persistence rarely changes, but business logic changes a fair bit. So we need a DomainModel that builds on the persistence model (instead of being one and the

Is it an antipattern to use angular's $watch in a controller?

↘锁芯ラ 提交于 2019-12-03 05:35:49
问题 In my never ending quest to do things the "proper" angular way, I have been reading a lot about how to have controllers observe the changes in models held in angular services. Some sites say using a $watch on a controller is categorically wrong: DON'T use $watch in a controller. It's hard to test and completely unnecessary in almost every case. Use a method on the scope to update the value(s) the watch was changing instead. Others seem fine with it as long as you clean up after yourself: The