In my team, we work closely with a few software architects. They approve all design decisions of our projects, do some code reviews etc.
Our projects consist mainly of backend functionality implemented in PHP using the Symfony 2 framework. So syntactically, the code, naming conventions and project structure look almost identical to what Java would look like (Symfony 2 encourages such structure). I'm mentioning this because Java-specific conventions also apply in our case (if possible).
Recently, they suggested something that I find very strange: all methods should have conjunctions in their name e.g. getEntityOrNull, setValueOrException etc.
Such a naming convention feels very wrong to me, but I can't come up with any concrete arguments or online articles/pages that specifically challenge this.
The only things I came up with is:
- such information should be present in the method's annotations, like
@returnor@throws - the use of conjunctions ("and", "or" etc.) in method names usually suggest that the Single Responsibility Principle is not properly respected
What are some other concrete arguments against this naming convention?
the use of conjunctions ("and", "or" etc.) in method names usually suggest that the Single Responsibility Principle is not properly respectedThis 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.Int32.TryParseandInt32.Parse-- both parse a string into an integer, but the former returns a Boolean indicating success and the latter throws on failure.Try...,...OrNull,...OrDefault. @EricLippert That's not the only convention in .net. ConsiderSinglevs.SingleOrDefault, which is very close to theOrNullthe OP suggested.