anti-patterns

Javascript - if with asynchronous case

孤街浪徒 提交于 2019-11-26 12:33:54
问题 My question is a bit regards concept. A lot of times there is this such situation: if(something){ someAsyncAction(); }else{ someSyncAction(); } // Continue with the rest of code.. var a = 5; The problem with this such case is clear, i don\'t want the var a = 5 to be call unless someAsyncAction() or someSyncAction() will done, now, cause soAsyncAction() is asynchronous the only way (i can think of) to solve this situation is something like that: var after = function(){ // Continue with the

Are subversion externals an antipattern?

耗尽温柔 提交于 2019-11-26 12:19:54
问题 Subversion lets you embed working copies of other repositories using externals, allowing easy version control of third-party library software in your project. While these seem ideal for the reuse of libraries and version control of vendor software, they aren\'t without their critics: Please don\'t use Subversion externals (or similar in other tools), they are an anti-pattern and, therefore, unnecessary Are there hidden risks in using externals? Please explain why they would they be considered

Any reason not to use '+' to concatenate two strings?

北战南征 提交于 2019-11-26 12:16:10
问题 A common antipattern in Python is to concatenate a sequence of strings using + in a loop. This is bad because the Python interpreter has to create a new string object for each iteration, and it ends up taking quadratic time. (Recent versions of CPython can apparently optimize this in some cases, but other implementations can\'t, so programmers are discouraged from relying on this.) \'\'.join is the right way to do this. However, I\'ve heard it said (including here on Stack Overflow) that you

Singleton with Arguments in Java

☆樱花仙子☆ 提交于 2019-11-26 11:32:09
I was reading the Singleton article on Wikipedia and I came across this example: public class Singleton { // Private constructor prevents instantiation from other classes private Singleton() {} /** * SingletonHolder is loaded on the first execution of Singleton.getInstance() * or the first access to SingletonHolder.INSTANCE, not before. */ private static class SingletonHolder { private static final Singleton INSTANCE = new Singleton(); } public static Singleton getInstance() { return SingletonHolder.INSTANCE; } } While I really like the way this Singleton behaves, I can't see how to adapt it

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

泄露秘密 提交于 2019-11-26 09:19:48
All of us who work with relational databases have learned (or are learning) that SQL is different. Eliciting the desired results, and doing so efficiently, involves a tedious process partly characterized by learning unfamiliar paradigms, and finding out that some of our most familiar programming patterns don't work here. What are the common antipatterns you've seen (or yourself committed)? Juliet I am consistently disappointed by most programmers' tendency to mix their UI-logic in the data access layer: SELECT FirstName + ' ' + LastName as "Full Name", case UserRole when 2 then "Admin" when 1

Python: is using “..%(var)s..” % locals() a good practice?

我们两清 提交于 2019-11-26 07:24:23
问题 I discovered this pattern (or anti-pattern) and I am very happy with it. I feel it is very agile: def example(): age = ... name = ... print \"hello %(name)s you are %(age)s years old\" % locals() Sometimes I use its cousin: def example2(obj): print \"The file at %(path)s has %(length)s bytes\" % obj.__dict__ I don\'t need to create an artificial tuple and count parameters and keep the %s matching positions inside the tuple. Do you like it? Do/Would you use it? Yes/No, please explain. 回答1: It

Unit testing Anti-patterns catalogue

。_饼干妹妹 提交于 2019-11-26 06:50:20
问题 anti-pattern : there must be at least two key elements present to formally distinguish an actual anti-pattern from a simple bad habit, bad practice, or bad idea: Some repeated pattern of action, process or structure that initially appears to be beneficial, but ultimately produces more bad consequences than beneficial results, and A refactored solution that is clearly documented, proven in actual practice and repeatable. Vote for the TDD anti-pattern that you have seen \"in the wild\" one time

Why are data transfer objects (DTOs) an anti-pattern?

夙愿已清 提交于 2019-11-26 03:03:34
问题 I\'ve recently overheard people saying that data transfer objects (DTOs) are an anti-pattern . Why? What are the alternatives? 回答1: Some projects have all data twice . Once as domain objects, and once as data transfer objects. This duplication has a huge cost , so the architecture needs to get a huge benefit from this separation to be worth it. 回答2: DTOs are not an anti-pattern. When you're sending some data across the wire (say, to an web page in an Ajax call), you want to be sure that you

Singleton with Arguments in Java

我与影子孤独终老i 提交于 2019-11-26 02:28:30
问题 I was reading the Singleton article on Wikipedia and I came across this example: public class Singleton { // Private constructor prevents instantiation from other classes private Singleton() {} /** * SingletonHolder is loaded on the first execution of Singleton.getInstance() * or the first access to SingletonHolder.INSTANCE, not before. */ private static class SingletonHolder { private static final Singleton INSTANCE = new Singleton(); } public static Singleton getInstance() { return

What's wrong with awaiting a promise chain?

丶灬走出姿态 提交于 2019-11-26 02:20:20
I’m working on an Angular 6 application and I’ve been told the following is an anti-pattern: await someFunction().then(result => { console.log(result); }); I realize that it is pointless to await a promise chain. If someFunction() returns a promise, you don’t need a promise chain if you’re awaiting it. You can do this: const result = await someFunction(); console.log(result); But I’m being told awaiting a promise chain can cause bugs, or that it will break things in my code. If the first code snippet above does the same thing as the second snippet, what does it matter which one is used. What