Is extending String class with IsNullOrEmpty confusing?

后端 未结 12 1987
有刺的猬
有刺的猬 2020-12-06 01:40

Everyone knows and love String.IsNullOrEmpty(yourString) method.

I was wondering if it\'s going to confuse developers or make code better if we extend String class t

12条回答
  •  独厮守ぢ
    2020-12-06 02:33

    Let's look at the pro:s and con:s...

    1. More readable.

    Yes, slightly, but the improvement in readability is outweighed by the fact that it looks like you are calling an instance method on something that doesn't have to be an instance. In effect it's easier to read, but it's harder to understand, so the improved readability is really just an illusion.

    1. Less typing.

    Yes, but that is really not a strong argument. If typing is the main part of your programming, you are just not doing something that is remotely challenging enough for you to evolve as a developer.

    1. Can be confusing because yourString variable can be null and it looks like you're executing method on a null variable.

    True, (as mentioned above).

提交回复
热议问题