Martin page 110: Don't Return Nullīook Effective Java 2nd edition by Joshua Bloch page 201: Item 43: Return empty arrays or collections, not nullsīook Framework Design Guidelines 2nd edition by Krzysztof Cwalina and Brad Abrams page 256: DO NOT return null values from collection properties or from methods returning collections. This advice is also supported by some prominent and influential voices:īook Clean Code by Robert C. it prevents your car getting egged by co-workers and users of your classes. It prevents the aforementioned nonsense, and. ALWAYS return an empty enumerable/collection. It is considered a best practice to NEVER return null when returning a collection or enumerable. If(myInstance.CollectionProperty != null)įoreach(var item in myInstance.CollectionProperty)
0 Comments
Leave a Reply. |