Skip to content

Conversation

@Nigusu-Allehu
Copy link
Member

@Nigusu-Allehu Nigusu-Allehu commented Oct 27, 2025

Bug

Fixes: #6804 (comment)

Description

Update coding guidelines as discussed in #6804 (comment)

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@Nigusu-Allehu Nigusu-Allehu requested a review from a team as a code owner October 27, 2025 23:16
@Nigusu-Allehu Nigusu-Allehu self-assigned this Oct 27, 2025
Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I overall don't see that a problem exists today with spacing with if-statements, have we looked into Roslyn analyzers first before taking an AI approach? As others pointed out, there's a lot of cases where we would not want extra spacing.

Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed offline - I'm neutral on this so if it's important to others to have a rigid guideline here, I'll trust you'll work out the right strategy.

@donnie-msft donnie-msft dismissed their stale review October 28, 2025 23:06

Discussed offline

Comment on lines 95 to 106
Don't
```csharp
// Blank spaces do not help readability
for (int i = 0; i < 5; i++)
{

if (i % 2 == 0)
{

Console.WriteLine($"{i} is even.");

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is the only "Don't" example: a time when blank lines would not be appropriate. However, this example introduces blank lines in the middle of the code block which is not part of the proposed guideline so it's showing an example that isn't an exception to the proposal. The proposed guideline is to put spaces before a control block separating any statements above it.

if (...)
```

Blank lines make it easier for readers to see where one group of statements ends and another begins.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases, this is true. In others, I disagree as I mentioned in our meeting yesterday. In some cases, a statement and a control block serve as a group of code that is best read when together, without excessive blank spaces, such as in this contrived code example:

public int CalculateScore(int points, int modifier)
{
    List<Player> activePlayers = GetActivePlayers();
    if (activePlayers.Count == 0)
    {
        return -1;
    }

    int score = points * modifier;
    if (score > 1000) {
        score = 1000; // score capped at 1000.
    }

    return score;
}

Copy link
Contributor

@jebriede jebriede Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree with having a blank space between control blocks. This can be handled with a coding guideline (and analyzer) to ensure that there is a blank line after every control block unless that next line is a curly brace closing another block.

}
if (isNewRecord){
Console.WriteLine("Congratulations!");
}else{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example introduces a different issue than what the proposal is talking about. The issue of brace placement and spacing between braces should not be part of this example and should be demonstrated separately in a different coding guideline.

@Nigusu-Allehu Nigusu-Allehu marked this pull request as draft November 4, 2025 23:06
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Nov 12, 2025
@dotnet-policy-service
Copy link
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants