We are using some utility methods in our company to simplify programming. So we
ID: 641995 • Letter: W
Question
We are using some utility methods in our company to simplify programming.
So we have following string extension:
public static bool IsNoE(this string s)
{
return string.IsNullOrEmpty(s);
}
This is just for convenience and the intention of this question is not to discuss the sense or senseless of such methods (maintaining, ...)
The question is about the naming.
Some people think the method should be named in this way:
public static bool IsNullOrEmpty(this string s)
{
return string.IsNullOrEmpty(s);
}
The argument for the first naming is:
It would not make sense to make extensions if they are not shorter to write.
The argument for the second naming is:
The only reason to add such extensions is just to support programming flow. (Writing a variable and then set the cursor back to the start to surround the variable with string.IsNull)
So why should I prefer one version over the other? Are there any naming conventions we can refer to?
Explanation / Answer
The first naming is just plainly wrong. Want a proof? What does the next piece of code do?
if (this.ah == PcX.Def)
{
this.Z.SecN.Coll();
}
The second naming is ok. It's explicit enough, but not too long. It's the one which is used by .NET Framework, so other developers won't be lost.
This being said, don't create aliases: you create additional code which has to be tested and maintained, while it doesn't bring anything useful to the project.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.