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 ...
Rufus's user avatar
  • 1,487
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#, ...
David Arno's user avatar
  • 39.3k
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 ...
Mike Nakis's user avatar
  • 32.2k
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 ...
John Wu's user avatar
  • 26.5k
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 ...
Deduplicator's user avatar
  • 9,031
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 ...
Kilian Foth's user avatar
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 ...
Greg Burghardt's user avatar
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 ...
JacquesB's user avatar
  • 59.6k
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 ...
Kilian Foth's user avatar
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 = ...
candied_orange's user avatar
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 ...
Neil's user avatar
  • 22.8k
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 ...
martin's user avatar
  • 363
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 : ...
wallenborn's user avatar
  • 1,980
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 ...
Christophe's user avatar
  • 77.2k
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> ...
Bart van Ingen Schenau's user avatar
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 ...
Christophe's user avatar
  • 77.2k
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 ...
candied_orange's user avatar
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), ...
Peter's user avatar
  • 3,748
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 ...
bishop's user avatar
  • 730
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 ...
nvoigt's user avatar
  • 7,767
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 ...
Jules's user avatar
  • 17.8k
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 ...
Robbie Dee's user avatar
  • 9,815
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 ...
RubioRic's user avatar
  • 407
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 ...
Christophe's user avatar
  • 77.2k
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! ...
Flater's user avatar
  • 49.8k
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++...
Doc Brown's user avatar
  • 207k
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....
candied_orange's user avatar
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 ...
Siphor's user avatar
  • 773
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 ...
marstato's user avatar
  • 4,578
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 ...
Christophe's user avatar
  • 77.2k

Only top scored, non community-wiki answers of a minimum length are eligible