Hot answers tagged

248 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 ...
user avatar
  • 1,337
189 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#, ...
user avatar
  • 38.1k
158 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 ...
user avatar
  • 31.4k
127 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 ...
user avatar
  • 24.6k
122 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 ...
user avatar
  • 8,137
69 votes
Accepted

How to name a method that both performs a task and returns a boolean as a status?

In .NET, you often have pairs of methods where one of them might throw an exception (DoStuff), and the other returns a Boolean status and, on successful execution, the actual result via an out ...
user avatar
  • 624
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 ...
user avatar
66 votes
Accepted

Should I always use "is" as prefix for boolean variables?

Not really, as booleans are not always used to indicate that an object "is" something. "has" is an equally valid prefix "was", "can" are also valid in particular circumstances, also, I have seen the ...
user avatar
64 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 ...
user avatar
  • 54.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 ...
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 = ...
user avatar
52 votes

Naming conventions DAL, BAL, and UI Layer

Preface Hopefully this is obvious, but... in the suggested namespaces below, you would replace MyCompany and MyProject with the actual names of your company and project. DTOs I would recommend ...
user avatar
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 ...
user avatar
  • 363
49 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 ...
user avatar
  • 22.3k
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 : ...
user avatar
  • 1,972
39 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 ...
user avatar
  • 66.8k
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 ...
user avatar
  • 66.8k
37 votes
Accepted

Is it a bad practice to give two very different files with the same general purpose the same name?

Consider the cost/benefit ratio of your two options: Would reusing the same name cause confusion or naming conflicts? Probably not, since they're in different folders. The name "player_stats/...
user avatar
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 ...
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), ...
user avatar
  • 3,678
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 ...
user avatar
  • 731
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 ...
user avatar
  • 17.3k
33 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 ...
user avatar
  • 6,845
28 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 ...
user avatar
  • 9,607
28 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 ...
user avatar
  • 397
27 votes

Should one always know what an API is doing just by looking at the code?

Your desire not to split it out into three method calls is completely understandable, but you do have other options besides boolean parameters. You could use enums: falconPeer.SetVisibility(...
user avatar
  • 371
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 ...
user avatar
  • 66.8k
26 votes

Why do we use non-descriptive internal codenames?

We don't reference people by their characteristics as it takes all day to list them in enough detail to be unambiguous and the characteristics can change. What if they get a haircut? Instead we give ...
user avatar
  • 1,802
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++...
user avatar
  • 184k
25 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! ...
user avatar
  • 37.3k

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