4 ms·
Whenever I read articles like this, I happily reflect that C# is such an excellent language to work with that these tiny complaints (I would hesitate to call th
by ThePadawan 6y ago
Whenever I read articles like this, I happily reflect that C# is such an excellent language to work with that these tiny complaints (I would hesitate to call them "issues") are the only ones popping up.
One other advantage to the "this.Foo()" syntax is that this allows using the extension method "Foo", which otherwise could not be resolved by the compiler.
(I also briefly considered if extension methods invoked on "this" would bind more strongly than base types - however, that is never the case [0])
[0] https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods#binding-extension-methods-at-compile-time https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...
- bob1029 6y agoI have a similar perspective. For me, the first reaction after getting halfway through the article was "this is a pedantic distraction". I don't worry too much about these things. The whole point of something high level like C# is to be able to focus more on the problem domain than the language features. In most cases, I would just let VS clean these things up for me. I very rarely disagree with what the latest version of VS2019 suggests for code cleanup tasks.
- cgrealy 6y ago> One other advantage to the "this.Foo()" syntax is that this allows using the extension method "Foo", which otherwise could not be resolved by the compiler. I’d argue that calling an extension method of the class from within the class is a good indicator that said extension method should be added as a member... it’s not really an “extension” if it’s required for the class to compile. But it’s nothing I’d lose sleep over...
- wvenable 6y agoThe extension method might be on an interface of the class and not on the class type itself. That's really the only time I've ever had to use this.
- cgrealy 6y agoFair point.
- ThePadawan 6y agoNote that this is also how can "cheat" to get default but overrideable interface methods (before they were introduced in C# 8): https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUHqAQwFsBTAZwAdCBjUgAgGUB7MgYQnOFYEsAvQgCMANqQAyPQWEJgAnngDeeeivqoAzPR5RgpMADNaDFmQCSOvYbrLVS3Kodad9AEIz6C+gHNSwANz0AL42jk7A9ABizMwAFACUfiFBSUkaapgAbGro9AAipIYQwsAAogAeulDkPMxVSXahKmmomWH0ALKEXjw0McAAFjzkTKyk5roGRvRlcUkODY0OqADs0wB0bmCJ9o3BOyp7ewQkFNR09BJSMrIA8lCkiqkADCPsnNzE/EKil9Jy2w4kgB6IH0ACqUBorDIzgGQ3o3HozAAbnowDw4AwBgxMYVimFLFMyANmHB6AB3HgDeiyZgQMD0GjvXgCYA1KprYEAKlSmhaWQwHVu5Kg5Uq1Vq5Hqc1UzVa2nCnW6vThwxMYwsk3OMxlKgWiyaq3VHC4LO+4kkf1ka3yeNKFVIVXZ5DWSp6MRm9C59HQAN2ST2Di5QJS+zUfJy6tMxEownoIFeGomVgeYf1jjSCtc7gAvAA+egAVj9Kl14baUViszD8zLS1WqtdXXdCTLgdUhzwxzIVCm7Q8qXQmnTS3QORHjRaAE4YvdyRdLdc7qQ1lGY8J4mtK/FWzWOwG8IEgA=== https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUHqAQwFs...
- pmiller2 6y agoIIRC (and, it has been a long time so please be gentle with the down arrow if I'm wrong, lol), you can write extension methods in native code that you might want to call from within the class.
- Fellshard 6y agoThe language is good; the standard library drives me batty. So many things that simply do not work as stated, or that force you take very circuitous routes to arrive at very simple results.
- Someone1234 6y agoCan you provide some examples?
- Fellshard 6y agoI recall having particular trouble with strings, filesystems (especially watchers; though that may be a domain issue more than a lib issue); and in more recent impressions, the TPL (task parallel library) was nightmarish, its behaviour never adding up to what was documented.