Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent naming conventions for delegate instances #33959

Closed
Vaskaran opened this issue Feb 10, 2023 · 3 comments · Fixed by #36428
Closed

Inconsistent naming conventions for delegate instances #33959

Vaskaran opened this issue Feb 10, 2023 · 3 comments · Fixed by #36428
Assignees
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-csharp/svc fundamentals/subsvc Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@Vaskaran
Copy link

Vaskaran commented Feb 10, 2023

Here the delegate instances are following the pascal casing naming convention. But the following link: https://learn.microsoft.com/en-us/dotnet/api/system.func-1?view=net-7.0 shows the use of the camel casing naming convention. Which one should we follow?Any thoughts?


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 123092

@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Feb 10, 2023
@issues-automation issues-automation bot added fundamentals/subsvc dotnet-csharp/svc Pri1 High priority, do before Pri2 and Pri3 labels Feb 10, 2023
@BillWagner
Copy link
Member

The text is correct in both places, but should be clarified. Delegate types and methods that are delegate targets are PascalCased. variables that are instances of a delegate type are camelCased.

I'll add this as an enhancement to udpate this article.

@BillWagner BillWagner added the doc-enhancement Improve the current content [org][type][category] label Feb 10, 2023
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label Feb 10, 2023
@Vaskaran
Copy link
Author

Vaskaran commented Feb 22, 2023

etho

Thanks for the response. "variables that are instances of a delegate type are camelCased." -This is clear. For example, the following is clear:
Del exampleDel2 = DelMethod;

The confusion arises for the following examples. Please note the following two cases:
Case-1(PascalCase is used ):
[Taken from :https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions]

public static Func<int, int, int> FuncExample2 = (x, y) => x + y;

Case-2(camelCase is used ):
[Taken from https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions]

Func<int, int, bool> testForEquality = (x, y) => x == y;

or, see the following line:

Func<int, int, int> constant = (_, _) => 42;

Additional Example/info:
Consider the following code. Visual Studio IDE shows the name violation for the method "show" [which is correct behavior], but it is silent about the delegate method:

namespace Test
{
    class Sample
    {
        // IDE shows the name Violation in this case(correct behavior)
        public static void show(int A) { WriteLine(A); }

        public static Func<int, int, int> FuncExample1 = (x, y) => x + y;
        // IDE does not show name violation about the following...
        public static Func<int, int, int> funcExample2 = (x, y) => x + y;

    }
}

So, a littlebit info on this issue can help us.

Finally, I have formulated a question with a simple case-study that can help to clear the confusion:
Consider the following program[I am using top-level statement]:

using static System.Console;
Action<int, int> adder =
    (x, y) => WriteLine($"{x} + {y} = {x + y}");
Func<Action<int, int>> totalMaker = () =>
{
   WriteLine("The totalMaker is called.");
    return adder;
};
totalMaker()(10, 15);

-Does this program follow the intended and correct naming convention?

@BillWagner
Copy link
Member

Adding to the July sprint as I'm updating this article.

@BillWagner BillWagner added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Jun 30, 2023
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Jul 1, 2023
@BillWagner BillWagner moved this from 🔖 Ready to 🏗 In progress in dotnet/docs July 2023 sprint Jul 24, 2023
@BillWagner BillWagner moved this from 🏗 In progress to 👀 In review in dotnet/docs July 2023 sprint Jul 27, 2023
BillWagner added a commit to BillWagner/docs that referenced this issue Jul 27, 2023
Fixes dotnet#30626: Clarify (again) that these are our guidelines, not yours. Point out that it's not the VS default, but a configuration option.
Fixes dotnet#30642: Again, our style.
Fixes dotnet#30799: Change constant style from ALL_CAPS to PascalCase to match runtime repo.
Fixes dotnet#33959: Update variable names so delegate types are PascalCased and instances of a delegate are camelCase. Add clarifying text for the same.
@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label Jul 27, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in dotnet/docs July 2023 sprint Jul 31, 2023
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-csharp/svc fundamentals/subsvc Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants