255
votes
Accepted
What is a term for a function that when called repeatedly, has the same effect as calling once?
This type of function / operation is called Idempotent
Idempotence (UK: /ˌɪdɛmˈpoʊtəns/,[1] US: /ˌaɪdəm-/)[2] is the property of certain operations in mathematics and computer science whereby they ...
188
votes
Naming issues: Should "ISomething" be renamed to "Something"?
Whilst many, including "Uncle Bob", advise not to use I as a prefix for interfaces, doing so is a well-established tradition with C#. In general terms, it should be avoided. But if you are writing C#, ...
162
votes
Clean Code: long names instead of comments
Yes, you understand Clean Code right, but your examples are quite a bit over the top.
Here is what you start with:
PageReloaderForPagesDisplayingVectorGraphicsThatAreUsedInTheEditorComments
...
135
votes
Accepted
Naming of bool methods: Is vs. Can vs.?
Is vs. Can
According to the Microsoft naming convention recommendations, both "Is" and "Can" are OK (and so is "Has") as a prefix for a Boolean.
In plain English, "Is" would be used to identify ...
123
votes
Accepted
What's the difference between "to" and "as" method name prefixes?
A toXYZ() function is expected to do a conversion, and to return a new independent object (though immutability allows for optimization, java.lang.String.toString() just returns the object).
As an ...
68
votes
Accepted
Is it enough for methods to be distinguished just by argument name (not type)?
Sure there is a good reason to name it more explicitly.
It's not primarily be the method definition that should be self-explanatory, but the method use. And while findById(string id) and find(string ...
68
votes
Best Practice - Avoid naming class and field the same?
Bart van Ingen Schenau has some good advice, but I'd like to offer some additional advice.
Don't universally avoid naming a class and property the same, but definitely question it. Consider all of the ...
65
votes
Accepted
How to name something when the logical option is a reserved keyword?
For an enum option you should use title case like Default. Since C# is case-sensitive it will not collide with the reserved keyword. See .net Naming Guidelines.
Since all public members should be ...
60
votes
Translating external data to the language you're programming in
English is a lingua franca/lowest common denominator for a reason. Even if the reason is conceptually as weak as "Everybody does it", that's still a rather important reason.
Going against common ...
56
votes
Accepted
Should I use AND in a function name?
A function name that contains and is at the wrong level of abstraction.
I lean towards addResponseIdToDB() because otherwise the ‘side effect’ is a complete surprise. However:
responseIds = ...
50
votes
What is a term for a function that when called repeatedly, has the same effect as calling once?
The precise term for this (as Woofas mentions) is idempotence. I wanted to add that while you could call your func1 method idempotent, you could not call it a pure function. The properties of a pure ...
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 ...
41
votes
Naming issues: Should "ISomething" be renamed to "Something"?
The interface is the important logical concept, hence, the interface should carry the generic name. So, I'd rather have
interface Something
class DefaultSomething : Something
class MockSomething : ...
40
votes
Why are module-specific prefixes widely used for function names in C modules?
Why prefixes in the first place?
The prefix for function names is a C practice that intends to avoid naming conflicts.
This is especially suitable in big projects, where different teams could easily ...
40
votes
Best Practice - Avoid naming class and field the same?
Fields/properties/attributes within a class should describe something of the concept that you are modelling with that class. You should be able to ask questions like "What is the <property> ...
38
votes
Accepted
Why is the norm of a complex number in the C++ complex library actually the square of the norm?
This is not a C++ library issue but a question of mathematical terminology. In mathematics, a norm can mean different things:
What you call norm is the Euclidian norm, which is the distance to the ...
37
votes
In a fluent interface with "with", is cloning expected?
Looking at this code I’d have no idea. Semantically you did say it’s another pizza. But since this is of type Pizza and not a PizzaBuilder that gives you a pizza object only after you call the build ...
35
votes
Is it enough for methods to be distinguished just by argument name (not type)?
Advantages of FindById().
Future-proofing: If you start with Find(int), and later have to add other methods (FindByName(string), FindByLegacyId(int), FindByCustomerId(int), FindByOrderId(int), etc), ...
34
votes
Accepted
Translating external data to the language you're programming in
In this scenario, I would leave the enum values in Dutch:
public enum Department { BOUW, ONDERHOUD }
Because the logic using these constants will be matching against data that is also in Dutch. For ...
34
votes
C# namespace and class naming convention for libraries
There is a nice document that contains a lot of rules that you should follow to be in line with Microsoft: Framework Design Guidelines.
One thing that you should change: Do not name classes as their ...
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 ...
29
votes
Naming issues: Should "ISomething" be renamed to "Something"?
This isn't just about naming conventions. C# doesn't support multiple inheritance so this legacy use of Hungarian notation has a small albeit useful benefit where you're inheriting from a base class ...
29
votes
Clean Code: long names instead of comments
No, Uncle Bob is not saying that.
There is no part in his book saying that you have to put ALL COMMENTS in the class name, "the whole information" that you mentioned.
Probably you don't need a ...
27
votes
In a fluent interface with "with", is cloning expected?
No, the naming prefix with does not tell if it's cloning or mutating. There are popular examples of fluent interfaces using a mutating with and some language-specific conventions (e.g. Java) that ...
26
votes
What form of verb to use (imperative verb or third-person verb) in programming?
var val = obj.GetValue();
var val = obj.PlayOnAwake; // From Unity
It's not first-person, it's imperative. Simply put, it's a command.
GetValue() Get the value!
PlaySound() Play this sound!
...
25
votes
Why is the norm of a complex number in the C++ complex library actually the square of the norm?
Christophe's post, whilst fully correct, does not actually answer the question why the terms look like they do.
To give you definite answer for the reasons, you would have to ask someone from the C++...
24
votes
Accepted
Naming: Should you sacrifice briefness for clarity?
If brevity can be sacrificed for clarity, it should. But if verbosity can be sacrificed for clarity, even better.
addInvalidField (field, message) {
const foundInvalidField = this.invalidFields....
24
votes
How to name something when the logical option is a reserved keyword?
I would append an underscore (default_)
Pros:
simple
obvious(why else would you append an underscore?)
consistent
easy to use
works in all modern languages I know
closest to the logical option
Why I ...
24
votes
Accepted
How to name a Boolean variable that represents either of two options?
Don't use a Boolean. Use an enum. E.g TransactionType with instances Buy and Sell.
That is unambiguous and far easier to understand.
If you want to persist the data efficiently, the boolean can be a ...
24
votes
Accepted
Why was "self" chosen over "this" for the name of the first parameter of python methods?
The use of self can be traced back to Smalltalk, which is one of the eldest OO languages (the oldest according to python wiki) and influenced the python language designers:
There is evidence of a ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
naming × 656naming-standards × 96
c# × 61
coding-standards × 58
java × 50
coding-style × 46
variables × 38
design × 30
object-oriented × 28
terminology × 28
design-patterns × 26
functions × 23
programming-practices × 22
conventions × 22
methods × 21
javascript × 19
c++ × 18
python × 17
.net × 17
language-agnostic × 16
api-design × 15
clean-code × 15
packages × 15
php × 14
interfaces × 14