Questions tagged [anti-patterns]

A programming anti-pattern is a commonly used solution to a specific programming problem, often claiming being an actual design pattern. But such a solution usually leads to adverse effects on an application scalability, testability and maintenance.

An anti-pattern can be thought of as a "worst of breed" solution to a problem in that it may "work" for its intended purpose, but have unwanted side effects or incur technical debt. Anti-patterns can arise from improper education, insufficient experience or simple ignorance.

SQL-Injection

In short, this is an anti-pattern of applying unfiltered user input directly to a database query string. This may seem like a quick and easy solution to querying data, however it can lead to data corruption, security breeches, and so-forth.

Example:

query-string = "select * from users where id='" + userid + "';"

Assuming the userid variable came directly from the user, an attacker can cause issues by setting the value to something that would cause unexpected behavior:

userid = "' or 1=1;drop table users"

Tight coupling

Instead of keeping two distinct parts of an application separate (CSS and HTML; Business Logic and the View in an MVC application), the parts are mingled such that a change in one necessitates a change in the other.

Example:

CSS

.yellow { color: yellow; }

HTML

<div class="yellow">foo</div>

In order to change the formatting, either the content (HTML) must be changed by substituting a different class name, or the class definition (CSS) must be changed to something that doesn't match its name.

Others

Wikipedia has other examples.

440 questions
4
votes
7 answers

What is interface bloat?

Can someone explain to me what interface bloat in OOP is (preferably with an example).
Aly
  • 15,865
  • 47
  • 119
  • 191
4
votes
0 answers

What's the Name of this Anti-Pattern?

What's the name of the anti-pattern illustrated by this example? if (something()) { return true; } else { return false; } It's a DRY violation but I've seen this specific one so much I'm wondering if it has a name.
Josh Johnson
  • 10,729
  • 12
  • 60
  • 83
4
votes
2 answers

Are void return methods that change the state of their argument an anti-pattern?

Are methods that return void but change the state of their arguments (ie. provide a hidden or implicit return value) generally a bad practice? I find them difficult to mock, which suggests they are possibly a sign of a bad design. What patterns…
MalcomTucker
  • 7,407
  • 14
  • 72
  • 93
4
votes
2 answers

What are the patterns in html/javascript RIA development?

When building big GUI based applications in other languages like C# or Java, we have various patterns like MVP, MVC, MVVM, and even complete guidance packages like Prism (WPF/Silerlight) that help us keep our code maintainable, extendable and keep…
Egil Hansen
  • 15,028
  • 8
  • 37
  • 54
4
votes
1 answer

Confused over using IOC container, service locator and factory

Suppose I have a BaseForm which depends on an ILogger or IResourceManager or something like that. Currently it resolves the correct implementation of the required service using the service locator which I know is an anti-pattern. Is using the…
4
votes
3 answers

How to replace nested switch statements

I got asked to write a little PHP script that takes some POSTed input from a few drop down boxes which give some selectable criteria and at the end, spits out one or more string variables containing unique codes. The variable names are of the form…
Biggles
  • 47
  • 2
  • 7
3
votes
6 answers

High Availability and Disaster Recovery Software AntiPatterns

If you had to audit a Java application for worst-practices when it comes to high-availability and disaster recovery, you would probably look for hardcoded IP addresses and suboptimal caching of bind handles. What else should be considered?
3
votes
1 answer

TFS -- Sustainability of Cascading Branches

Branching guidance usually describes an immortal "Main" branch, with features branched from Main, and merged back to Main, and Releases branched from Main, with further branches of a Release as necessary for Service Packs, RTMs, etc. The guidance…
3
votes
1 answer

Is "static Domain helper class" Ambient Context Anti-Pattern?

As defined in the Manning book by Steven van Deursen and Mark Seemann, "Dependency Injection Principles, Practices, and Patterns" (which I recommend as must-read), there is one specific anti-pattern that was interesting to me, and that is Ambient…
3
votes
0 answers

Get value of field with lombok builder

Is it possible to retrieve the value of a field on a builder which was generated by lombok? final var builder = Something.builder(); try { // ... something that might break } catch (Throwable t) { builder.error("Something went wrong."); …
Josh M.
  • 26,437
  • 24
  • 119
  • 200
3
votes
2 answers

'value' from props and 'thisValue' in state, antipattern?

I've been finding myself writing a lot of code recently that looks like this: const SomeComponent: React.FunctionComponent = props => { const { value } = props; const [thisValue, setThisValue] = React.useState(value); …
dwjohnston
  • 11,163
  • 32
  • 99
  • 194
3
votes
3 answers

When is it OK to use an Enum's name()

Variables' name can be changed and shouldn't affect logic. But name() method in Enum returns a constant name as a value so it can break existing code. Should I avoid using name()? For example, public enum Example1 {FOO, BAR} Refactoring FOO name to…
user2652379
  • 782
  • 3
  • 9
  • 27
3
votes
5 answers

Is having a global Config class a bad thing?

Currently in my personal website I'm building I'm using a global static Config class to hold everything configurable I might need to change that is semi-global. So right now it looks about like this: public static class Config { public static…
Earlz
  • 62,085
  • 98
  • 303
  • 499
3
votes
2 answers

Is this an anti-pattern or violates it some design-principles?

I try myself with design-patterns & -principles and have a question. Before, sorry for the bad coding-style habit !! I have an interface like ITest in this case: public interface ITest { public void method1(); } and then implement the methods…
3
votes
2 answers

Using setTimeout to avoid re-renders in React

There is a pattern that I use often that I feel must be an anti-pattern but I don't know a better alternative. Occasionally my components may receive one or more events that mean that a re-render is necessary. Sometimes it is the case that I do not…
Jack Allan
  • 14,554
  • 11
  • 45
  • 57