Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • generally, you can't Commented Sep 8, 2014 at 8:07
  • 7
    the use of conjunctions ("and", "or" etc.) in method names usually suggest that the Single Responsibility Principle is not properly respected This is not the case for the examples you listed, where the conjunction is used to clarify the mechanism used to handle failures, not to indicate it may do one thing or another. Even the most narrowly-defined function may have legitimate failure conditions, e.g. popping an empty stack. Commented Sep 8, 2014 at 15:04
  • 4
    Consider: (1) using "optional" rather than "or null". "GetOptionalEntity" sounds better to my ear than "GetEntityOrNull". (2) the .NET base class library uses the convention that if you have two methods that differ only in what they throw, name the one that cannot throw "TryBlah". For example, Int32.TryParse and Int32.Parse -- both parse a string into an integer, but the former returns a Boolean indicating success and the latter throws on failure. Commented Sep 8, 2014 at 17:04
  • I wouldn't use a suffix for the throwing variant, but I would use one for the null returning variant. Could be Try..., ...OrNull, ...OrDefault. @EricLippert That's not the only convention in .net. Consider Single vs. SingleOrDefault, which is very close to the OrNull the OP suggested. Commented Sep 9, 2014 at 14:26