4 ms·
I like the explicitness of 'this'. It basically guarantees that whenever I see a symbol, I know where it's coming from. If I see: `myFoo` Cool, it must have
by 2bitencryption 6y ago
I like the explicitness of 'this'.
It basically guarantees that whenever I see a symbol, I know where it's coming from.
If I see:
`myFoo`
Cool, it must have been declared somewhere in this scope of code.
If I see:
`this.myFoo`
Cool, it's declared as a field on the class and therefore exposed at a higher level (even if it's private, changing its value can have side effects later on outside this scope since it is persisted state on my class).
Note that this only really works when your linter guarantees it. But as a developer, I will always take a guarantee over a non-guarantee :)
- vsareto 6y agoI've never liked added explicitness for readability in tool heavy environments (which C#/VS is) since it tends to not add much value because those tools can impart the same information. If we were doing C# in a really basic text editor, I could understand the need for qualifying 'this' though.
- DaiPlusPlus 6y agoVisual Studio (without third-party extensions) still doesn't offer a way to color/highlight/style static member call-sites differently to instance member call-sites, that's why I always prefix instance member access with `this.` and why I always give static fields a name with a leading underscore.
- accoil 6y agoDoesn't Visual Studio make static/const members bold these days? I can't find when it started happening, but there is at least someone wanting to turn it off Jan 2019: https://developercommunity.visualstudio.com/idea/437785/allow-to-turn-off-bold-keywords-with-enhanced-colo.html https://developercommunity.visualstudio.com/idea/437785/allo...
- DaiPlusPlus 6y agoAh, yes - that's a new setting in VS2019 (I use VS2017 as my daily driver, but sometimes use VS2019). It looks like VS2019 will only let you style static members in bold - or not - and that's it. You can't use a different color or italics - just bold or non-bold. Hmpf.
- nicoburns 6y agoI like explicitness for readability because I hate tool heavy environments! Most Java/C# IDEs are quite resources hungry, and noticeably slow down my Macbook.
- lazypenguin 6y agoThat's a fair argument. However I'd counter by saying that code is often read in "tool light" environments, such as a diff in an email, code in an online repository, etc.
- apta 6y ago> If I see: `this.myFoo` > Cool, it's declared as a field on the class IDEs can highlight local fields and class members in different colors. Furthermore, in C# convention, member variables are preceded with an underscore (e.g. `_myFoo`).