Skip to content

Add DotNet style guide basic layout #20

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

Merged
merged 1 commit into from
Apr 18, 2017

Conversation

matiasbeckerle
Copy link
Contributor

@matiasbeckerle matiasbeckerle commented Apr 17, 2017

Background

We were discussing a lot in several pull requests across different projects. This PR aims to set a base for putting the conclusions about style stuff. Please feel free to add, modify, delete, suggest, comment, whatever.

Changes

  • Added a new folder and readme file for DotNet.
  • Added a basic layout for specifying a simple rule (use of var).
  • Added reference in the root readme.

Pending

  • All the rules. LOL

Notes

  • As you may see, this is only a layout proposal so feel free to comment about it. Looked for some other references but I couldn't find any nice markdown based on C# (even in awesome lists) so I started a new one. Maybe we got the chance of having lot of forks, who knows!
  • Once I got the approval for this one, rules will come in (slowly).
  • I will add a couple of reviewers but feel free to add anyone!

Copy link
Member

@AlphaGit AlphaGit left a comment

Choose a reason for hiding this comment

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

Some suggestions:

  • I would move resources below the rules, since the most "meat" this guide will have will be the rules.
  • I would give a definite name to "Some Title", maybe "General" for now and we can redefine later (so that until we do that, it doesn't look "wrong")
  • Great start! Thanks for putting this together.

DotNet/README.md Outdated
IUserService userService = new UserService();

// Allowed because the variable is poorly named from legacy code
Graph g = new Graph();
Copy link
Member

Choose a reason for hiding this comment

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

I think that this scenario could be removed, it is normal to break the rules in exceptional cases like legacy code.

Choose a reason for hiding this comment

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

+1. Each team should decide if legacy code should be adjusted (gradually or all at once) or not depending on each project's context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will remove.

DotNet/README.md Outdated
IUserService userService = new UserService();

// Allowed because the variable is poorly named from legacy code
Graph g = new Graph();
Copy link
Member

@andresmoschini andresmoschini Apr 18, 2017

Choose a reason for hiding this comment

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

BTW, I would like to see an example of this Eric Lippert's sentence:

Use explicit types if doing so is necessary for the code to be correctly understood and maintained.

Personally, I prefer to always use var.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄 Agree. Maybe if you try a comment on the blogpost, who knows... Eric seems to leave really cool responses as @mvazquez-ms points every day.

Copy link
Contributor

@mvazquez-ms mvazquez-ms Apr 19, 2017

Choose a reason for hiding this comment

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

BTW, I would like to see an example of this Eric Lippert's sentence:

Use explicit types if doing so is necessary for the code to be correctly understood and maintained.

I have one example in mind where explicit type is slightly more readable than var. (For the record, I prefer var 99.99% of the time)

A method receiving a Func<T1,T2,TResult>

public void SomeMethod(Func<int, int, bool> intComparer)
{
    // do something with intComparer
}
// Explicit Type
Func<int, int, bool> greaterThanComparer = (x, y) => x > y;
SomeMethod(greaterThanComparer);

// Implicit Type 1 (this won't compile as type cannot be inferred)
var lessThanComparer = (x, y) => x < y;
SomeMethod(lessThanComparer);

// Implicit Type 2 (I find this harder to read than the explicit type version)
var lessThanComparer = new Func<int, int, bool>((x, y) => x < y);
SomeMethod(lessThanComparer);

// Local Function (unusual syntax)
bool equalityComparer(int x, int y) => x == y;
SomeMethod(equalityComparer);

(Also, for this scenario to be valid, the expression should be a bit more complex or require to be re-used somehow, otherwise we can just use it like: SomeMethod((x, y) => x > y); )

Of course this is a rare scenario, and it's OK if someone still prefers the implicit type version..

Copy link
Member

@andresmoschini andresmoschini Apr 19, 2017

Choose a reason for hiding this comment

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

Thanks @mvazquez-ms!

@andresmoschini
Copy link
Member

Nice initiative @matiasbeckerle, thanks!

I want to mention that VS2017 supports some editorconfig extensions that could be useful to document and encourage the usage of some of the guidelines. See more details in:

@mvazquez-ms
Copy link
Contributor

Nice! We really need this.

The only comment I have so far is I think we should name it C# style-guide. DotNet is too broad, and if we put anything DotNet-related here, it will become huge. (e.g. On 3.0, we had tons of rules for XAML code, that's DotNet)

@matiasbeckerle
Copy link
Contributor Author

Agree with you @mvazquez-ms. Actually I forgot to put that question on the PR description, as usually forgot something. I will rename this one. Thanks.

@matiasbeckerle
Copy link
Contributor Author

Thank you @andresmoschini for the .editorconfig thing. I also believe we will have a resharper file too (as I told you today).

@matiasbeckerle
Copy link
Contributor Author

Thanks @AlphaGit, appreciated. Agree on both things:

  • I will move those below.
  • I will rename the title, it only was a placeholder. BTW I'm the worst grouping stuff so I will need naming ideas in the near future.

@matiasbeckerle matiasbeckerle merged commit edcfd58 into MakingSense:master Apr 18, 2017
@matiasbeckerle
Copy link
Contributor Author

Thank you all for participating, commenting, smiling or thumbing up! Appreciated. Feel free to join in upcoming discussions!

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

Successfully merging this pull request may close these issues.

6 participants