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

fx cop & FZ editor part 1 of many #11241

Merged
merged 6 commits into from
May 14, 2021
Merged

fx cop & FZ editor part 1 of many #11241

merged 6 commits into from
May 14, 2021

Conversation

crutkas
Copy link
Member

@crutkas crutkas commented May 12, 2021

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

  • Linked issue: FxCop for FancyZone editor #8463
  • Communication: I've discussed this with core contributors in the issue.
  • Tests: Added/updated and all pass
  • Installer: Added/updated and all pass
  • Localization: All end user facing strings can be localized
  • Docs: Added/ updated
  • Binaries: Any new files are added to WXS / YML

Contributor License Agreement (CLA)

A CLA must be signed. If not, go over here and sign the CLA.

Comment on lines +230 to +231
private double _dragX;
private double _dragY;
Copy link
Contributor

@enricogior enricogior May 13, 2021

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?

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

@crutkas crutkas merged commit 319adcb into master May 14, 2021
@crutkas crutkas deleted the dev/crutkas/fxCopEditor branch May 14, 2021 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants