question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Private field naming convention

See original GitHub issue

In this issue I’d like to align the private field name convention in our project.

I’ve found that in one places we prefix private fields with underscore, while in other we don’t. That is a pretty confusing and we should align the single styling for this project.

Usually, I prefer to start private fields with the underscore character:

private class SomeClass
{
    private readonly int _someValue;

    public SomeClass(int value)
    {
        this._someValue = value;
    }
}

However I would be fine if we agree to live without them (like most of the code is written in kernel) as we enforce the this keyword (so it’s clear that it’s the field):

private class SomeClass
{
    private readonly int someValue;

    public SomeClass(int value)
    {
        this.someValue = value;
    }
}

@moodmosaic @adamchester Do you have any opinion regarding the naming convention? I’m fine with whatever we follow - the only wish is to have a consistency.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
zvirjacommented, Nov 5, 2017

Well, I don’t believe in that 😃 However, who knows… 😏

0reactions
moodmosaiccommented, Nov 5, 2017

It was quite surprising, but internally they follow a convention to prefix fields with my - like myManager, myRepository.

Sounds like they’re coming from VB? 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Field Naming Guidelines?
Following Microsoft's naming conventions, private fields should be prefixed with an underscore. For example: private int _myValue;. Good luck!
Read more >
Naming Convention for Private / Public Fields [duplicate]
Convention for naming private instance fields is up to you but it should be consistent in the whole project (or all company projects)....
Read more >
NET documentation C# Coding Conventions
Learn about commonly used coding conventions in C#. Coding conventions create a consistent look to the code and facilitate copying, ...
Read more >
Configure Visual Studio to Name Private Fields with ...
Configure Visual Studio to Name Private Fields with Underscore · Click on Tools in the menu. · Click on Options. · Click on...
Read more >
Naming convention for private static fields? : r/dotnet
Docs seem to point out that all static fields should start with uppercase and no prefix, but also they point out that all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found