271
votes
Accepted
What is wrong with magic strings?
In a language that compiles, a magic string's value is not checked at compile time. If the string must match a particular pattern, you have to run the program to guarantee it fits that pattern. If you ...
246
votes
Why should 'boneheaded' exceptions not be caught, especially in server code?
Silent But Deadly
When writing enterprise software, you will eventually learn an essential truth: the worst bug in the world is not one that causes your program to crash. The worst bug in the world ...
227
votes
Accepted
Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?
The data itself is called "tramp data". It is a "code smell", indicating that one piece of code is communicating with another piece of code at a distance, through intermediaries.
Increases rigidity ...
149
votes
Is source code generation an anti-pattern?
Is source code generation an anti pattern?
Technically, if we generate code, it is not source even if it is text that is readable by humans. Source Code is original code, generated by a human or ...
Community wiki
128
votes
Term (or "pattern"?) for "Do something if it's not already done"
As NickWilliams has already said: the concept the OP describes is called idempotent (noun Idempotency). It is indeed common practice, especially in high-level APIs.
BUT: Rename the function.
Instead ...
110
votes
Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?
I don't think this, in itself, is an anti-pattern. I think the problem is that you are thinking of the functions as a chain when really you should think of each one as an independent black box (NOTE: ...
102
votes
Is putting general-use functions in a "helpers" file an anti-pattern or code smell?
Both Java and C# have the existence proof that this works: the Math class.
The danger is the "kitchen drawer" problem, where a class simply gathers new kitchen tools and implements, many of ...
101
votes
What is wrong with magic strings?
The summit of what the other answers have grasped at, is not that "magic values" are bad, but that they ought to be:
defined recognisably as constants;
defined only once within their entire domain ...
78
votes
Accepted
Is it considered an anti-pattern to read from STDIN from within a library?
As a general guideline, libraries should be totally disconnected from the environment. That means that they shouldn't perform operations on standard streams, on specific files, or have any expectation ...
76
votes
Is source code generation an anti-pattern?
Practical reasoning
OK, I know that code is data as well. What I don't understand is, why generate source code?
From this edit, I assume you are asking on a rather practical level, not ...
Community wiki
73
votes
Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?
BobDalgleish has already noted that this (anti-)pattern is called "tramp data".
In my experience, the most common cause of excessive tramp data is having a bunch of linked state variables that should ...
61
votes
Accepted
Is my company merging branches wrong?
Some suggestions:
There is nothing wrong in having a lot of feature or bugfix branches as long as the changes done in each branch are small enough you can still handle the resulting merge conflicts ...
59
votes
Why should 'boneheaded' exceptions not be caught, especially in server code?
Exceptions should be allowed to crash the system if the system has been left in an unrecoverable undefined state. If you can't put the system back in a defined state that ensures data integrity and ...
49
votes
What's the name of the antipattern opposite to "reinventing the wheel"?
Golden Hammer
The golden hammer is a tool chosen only because it is fancy. It is neither cost-effective nor efficient at performing the intended task.
source: xkcd 801
(Despite the down-votes, I stand ...
46
votes
Is source code generation an anti-pattern?
why generate code?
Because programming with punch cards (or alt codes in notepad) is a pain.
If it is being done for performance reasons, then that sounds like a shortcoming of the compiler.
True....
Community wiki
45
votes
Is source code generation an anti-pattern?
why generate source code
The most frequent use case for code generators I had to work with in my career were generators which
took some high level meta-description for some kind of data model or ...
Community wiki
43
votes
If nulls are evil, what should be used when a value can be meaningfully absent?
Lots of things are better to return than null.
An empty string ("")
An empty collection
An "optional" or "maybe" monad
A function that quietly does nothing
An object ...
43
votes
Why should 'boneheaded' exceptions not be caught, especially in server code?
It doesn't really matter if it's a "boneheaded" exception (e.g. a Java unchecked exception) or not.
The only question to ask yourself is:
"Can the program sensibly continue?"
A &...
42
votes
Is putting general-use functions in a "helpers" file an anti-pattern or code smell?
My criterion is: If you needed a function from the "helpers" file, would you find it? Or would you write your own version, use it, and put it into the "helpers" file together with ...
39
votes
Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?
I am not aware of a specific name for this, but I guess it is worth to mention that the problem you describe is just the problem of finding the best compromise for the scope of such a parameter:
as a ...
38
votes
What is wrong with magic strings?
They are hard to track.
Changing all may require changing multiple files in possibly multiple projects (hard to maintain).
Sometimes it's hard to tell what their purpose is just by looking at their ...
37
votes
Why is it wrong to comment out code and then gradually remove it to keep track of what I've already done and what remains to be done?
If you ultimately remove all of the commented out code, I see no real issue with this. Leaving commented code in your code base is a bad practice but that is not what you are doing if you work ...
36
votes
Is putting general-use functions in a "helpers" file an anti-pattern or code smell?
Putting commonly used functions into a single file is not on its own an antipattern. But there are many antipatterns associated with this:
Grouping functions whose only common property is reuse is ...
35
votes
Is there a better way to use C# dictionaries than TryGetValue?
Some good answers here on the general principles of hashtables/dictionaries. But I thought I'd touch on your code example,
int x;
if (dict.TryGetValue("key", out x))
{
DoSomethingWith(x);
}
As ...
35
votes
Is it an (anti-)pattern for a function to have an argument to decide which other function to call?
Does this pattern have a name,
That depends on who you ask. Some folk treat patterns as only applicable to OOP and see them as more like implementation patterns in that, for example the UML used in ...
34
votes
What's the name of the antipattern opposite to "reinventing the wheel"?
Robert Martin uses the term "Framework Bound" to refer to the most obvious negative consequence of this anti-pattern. As I don't think there's any common name for the pattern itself, a reference to ...
33
votes
Term (or "pattern"?) for "Do something if it's not already done"
Rename it to EnsureServerRunning.
Completely unambiguous and is clear that it makes sure it is running (if it isn't) without implying a restart if it is.
(Alternative: StartServerIfNotRunning?)
30
votes
Term (or "pattern"?) for "Do something if it's not already done"
Not really a design pattern but I would call your method idempotent. There term is usually used to refer to remote calls but the description seems the match what you are doing.
Idempotent Methods. ...
30
votes
Accepted
Is there a better way to use C# dictionaries than TryGetValue?
Dictionaries (C# or otherwise) are simply a container where you look up a value based on a key. In many languages it's more correctly identified as a Map with the most common implementation being a ...
28
votes
What is wrong with magic strings?
Real life example: I am working with a third party system wherein "entities" are stored with "fields". Basically an EAV system. As it is fairly easy to add another field, you get ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
anti-patterns × 238design-patterns × 82
object-oriented × 28
java × 22
patterns-and-practices × 17
c# × 14
code-smell × 14
architecture × 13
programming-practices × 12
coding-style × 12
dependency-injection × 11
object-oriented-design × 10
design × 9
php × 9
python × 9
refactoring × 9
exceptions × 8
singleton × 7
javascript × 6
terminology × 6
inheritance × 6
c++ × 5
.net × 5
single-responsibility × 5
parameters × 5