anti-patterns

What are the most common SQL anti-patterns? [closed]

冷暖自知 提交于 2019-12-17 01:19:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . All of us who work with relational databases have learned (or are learning) that SQL is different. Eliciting the desired results, and

Scaling singletons

坚强是说给别人听的谎言 提交于 2019-12-13 15:14:45
问题 After having some difficult hours mulling over some architecture issues for my server-based application, I feel I am going to have to use singletons to accomplish my goal. Purely for the following reasons (justifying my smell): I don't need to pass expensive objects deep into a call stack I can perform functions on singleton management objects within any context. (A lot of the code already exists and therefore I am unwilling to rewrite extensive chunks of otherwise working code) Apart from

Symfony2 / Doctrine queries in loops

你离开我真会死。 提交于 2019-12-13 06:51:56
问题 I'm cleaning up some old code written by someone else because we're having problems with time-outs, especially with customers who are pushing the limits of our system. I know this is an anti-pattern, and the code is full of variations of this: $userIDs = [100,101,107,208, ...]; // tons of users, but not all users in a company. $companyID = 4356; foreach ($userIDs as $id) { $user = $em->getRepository('AdminBundle:Users') ->getUser($id, $companyId); $user->removeGroup($group); $em->persist(

Are single implementer interfaces for unit testing an antipattern?

夙愿已清 提交于 2019-12-12 10:32:04
问题 In regards to unit testing, I was taught that production code shouldn't have test-related code in it. Well, I feel like I'm breaking that rule every time I try to unit test. I have a class internal to my assembly, Xyzzy . I want to dependency inject it into another class and then stub it so I can test that the other class in isolation, so I make an interface, IXyzzy . Oops, now I have code in production that's really only there for test. Even worse, I've kind of gone against what interface is

Update fields from superclass

吃可爱长大的小学妹 提交于 2019-12-12 00:07:47
问题 From point of various patterns is it acceptable to change fields in superclass from its descendants. For example: class A { int barA; } class B extends A { private void testMethod() { barA = 4; } } Thanks in advance! 回答1: No, it's generally not a good idea. If I understand what you are asking, it would normally be done like public class A{ private int val; protected void setVal(int i){ val = i; } public int getVal(){ return val; } } public class B extends A{ public void test(){ this.setVal(4)

anemic domain model versus domain model

不问归期 提交于 2019-12-09 04:21:29
问题 Being confused again after reading about this anti-pattern and the many concerns about it here on SO. If I have a domain model and capture the data that must be persisted in a data transfer object, does that make my domain model a wrapper around the data? In that case I would be using an anemic domain model. But if I add enough domain logic on that wrapper, at what point does it become a real domain model then? I get the impression that capturing what must be persisted in a domain model

DI Control-Freak anti-pattern: Having trouble understanding

巧了我就是萌 提交于 2019-12-07 04:29:39
问题 I'm reading Dependency Injection in .NET by Mark Seemann and I can not for the life of me get my head wrapped around this: Although the new keyword is a code smell when it comes to VOLATILE DEPENDENCIES, you don't need to worry about using it for STABLE DEPENDENCIES. The new keyword isn't suddenly "illegal" in general, but you should refrain from using it to get instances of VOLATILE DEPENDENCIES. Maybe it's because I still can't get my head wrapped around ambient context being an injection

Is replacing a list element an anti-pattern?

落花浮王杯 提交于 2019-12-06 20:07:22
问题 I have a module that works on paths represented as lists. Most of the functions do typical recursive list processing, but now I need one that sometimes mutates a path. So, I wrote this replace function: module List = let replace f sub xs = let rec finish acc = function | [] -> acc | x::xs -> finish (x::acc) xs let rec search acc = function | [] -> None | x::xs -> if f x then Some(finish ((sub x)::xs) acc) else search (x::acc) xs search [] xs which works like this: let xs = List.init 10 id let

Creating custom events - Object Sender or Typed Sender?

风格不统一 提交于 2019-12-05 21:10:33
问题 I searched through the archives and I found lots of questions about what sender is and why you should use the pattern but I didn't see anything about a custom event and the type if sender. Say I am creating a custom class called Subscription and it implements ISubscription and I have some event args called SubscriptionEventArgs. If Subscription had an event called Changed what is wrong about the event signature Changed(ISubscription sender, SubscriptionEventArgs e)? A little code to help

Where did variable = null as “object destroying” come from?

左心房为你撑大大i 提交于 2019-12-05 09:28:16
问题 Working on a number of legacy systems written in various versions of .NET, across many different companies, I keep finding examples of the following pattern: public void FooBar() { object foo = null; object bar = null; try { foo = new object(); bar = new object(); // Code which throws exception. } finally { // Destroying objects foo = null; bar = null; } } To anybody that knows how memory management works in .NET, this kind of code is painfully unnecessary; the garbage collector does not need