-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fx cop & FZ editor part 1 of many #11241
Conversation
private double _dragX; | ||
private double _dragY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be allowed to set default values for private properties.
If we want to enforce all initializations to be moved in the constructor, it has to be done before this PR can be merged.
Assuming that an un-initialized property is implicitly initialized to 0 or null is also not acceptable because when we do a code review how can we know if the default initialization to 0/null is intentional or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how the code base for anything that is .NET is already designed minus this code base. tons of other vars through FZ are like this already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to explicitly initialize variables, otherwise code reviews and code maintainability become problematic and a source of bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't understand what is the reasoning to make illegal to:
- initialize a variable outside of the constructor
- not allow to initialize explicitly a variable to zero or null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you 100% can init a var outside the constructor. This rule is saying don't init to default value.
https://github.com/microsoft/PowerToys/blob/master/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs#L58 is an example of where it is set to non-default
Why? it is the c# style. We could set the rule to be ignored but i don't see why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is very simple: if default initialization is implicit it's impossible to read the code and understand if it was done intentionally or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how the entire solution is done. There are a lot of things that could be crisper but right now, this is part of the c# style guidelines and the guidelines this project adheres to. If we want to change it, please lets create an issue and have a discussion.
For now, this is our standard we are adhering to as the entire solution already does.
Summary of the Pull Request
What is this about:
First few bits for FxCop and FZ Editor
What is include in the PR:
How does someone test / validate:
Quality Checklist
Contributor License Agreement (CLA)
A CLA must be signed. If not, go over here and sign the CLA.