Skip to main content
Copy edited.
Source Link
Peter Mortensen
  • 31.6k
  • 22
  • 110
  • 133

My dirty secret  : I don't care what people sayssay, and I do it.    .NET Framework is spread with "XxxxCollection" (UIElementCollection for top of my head example).

So what stopstops me to say saying:

team.Players.ByName("Nicolas")

When I find it better than

team.ByName("Nicolas")

Moreover, my PlayerCollection might be used by other class, like "Club" without any code duplication.

club.Players.ByName("Nicolas")

Best practices of yesterday, might not be the one of tomorrow. There is no reason behind most best practicepractices, most are only wide agreement among the community. Instead of asking at the community if it will blame you when you do that ask yourself, what is more readable and maintainable  ?

team.Players.ByName("Nicolas") 

or

team.ByName("Nicolas")

Really. Do you have any doubt  ? Now maybe you need to play with other technical constraintconstraints that prevent you to use List< T >List<T> in your real use case. But don't add a constraint that should not exist. If Microsoft did not documenteddocument the why, then it is surely a "best practice" coming from nowhere.

My dirty secret  : I don't care what people says and I do it.  .NET Framework is spread with "XxxxCollection" (UIElementCollection for top of my head example).

So what stop me to say :

team.Players.ByName("Nicolas")

When I find it better than

team.ByName("Nicolas")

Moreover, my PlayerCollection might be used by other class, like "Club" without any code duplication.

club.Players.ByName("Nicolas")

Best practices of yesterday, might not be the one of tomorrow. There is no reason behind most best practice, most are only wide agreement among the community. Instead of asking at the community if it will blame you when you do that ask yourself, what is more readable and maintainable  ?

team.Players.ByName("Nicolas") 

or

team.ByName("Nicolas")

Really. Do you have any doubt  ? Now maybe you need to play with other technical constraint that prevent you to use List< T > in your real use case. But don't add constraint that should not exist. If Microsoft did not documented the why, then it is surely a "best practice" coming from nowhere.

My dirty secret: I don't care what people say, and I do it.  .NET Framework is spread with "XxxxCollection" (UIElementCollection for top of my head example).

So what stops me saying:

team.Players.ByName("Nicolas")

When I find it better than

team.ByName("Nicolas")

Moreover, my PlayerCollection might be used by other class, like "Club" without any code duplication.

club.Players.ByName("Nicolas")

Best practices of yesterday, might not be the one of tomorrow. There is no reason behind most best practices, most are only wide agreement among the community. Instead of asking the community if it will blame you when you do that ask yourself, what is more readable and maintainable?

team.Players.ByName("Nicolas") 

or

team.ByName("Nicolas")

Really. Do you have any doubt? Now maybe you need to play with other technical constraints that prevent you to use List<T> in your real use case. But don't add a constraint that should not exist. If Microsoft did not document the why, then it is surely a "best practice" coming from nowhere.

Source Link
Nicolas Dorier
  • 7.5k
  • 11
  • 61
  • 72

My dirty secret : I don't care what people says and I do it. .NET Framework is spread with "XxxxCollection" (UIElementCollection for top of my head example).

So what stop me to say :

team.Players.ByName("Nicolas")

When I find it better than

team.ByName("Nicolas")

Moreover, my PlayerCollection might be used by other class, like "Club" without any code duplication.

club.Players.ByName("Nicolas")

Best practices of yesterday, might not be the one of tomorrow. There is no reason behind most best practice, most are only wide agreement among the community. Instead of asking at the community if it will blame you when you do that ask yourself, what is more readable and maintainable ?

team.Players.ByName("Nicolas") 

or

team.ByName("Nicolas")

Really. Do you have any doubt ? Now maybe you need to play with other technical constraint that prevent you to use List< T > in your real use case. But don't add constraint that should not exist. If Microsoft did not documented the why, then it is surely a "best practice" coming from nowhere.