GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add links on best practice guidelines in coding guideline by iSazonov · Pull Request #4983 · PowerShell/PowerShell

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Oct 3, 2017

Copy link
Copy Markdown
Collaborator

Add links on Microsoft best practice guidelines.
Add a recommendation to avoid initializing by 0 or null.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov
Add links on best practice guidelines in coding guideline
31882c6
@iSazonov Ilya (iSazonov) assigned Dongbo Wang (daxian-dbw) Oct 3, 2017
@iSazonov
Ilya (iSazonov) requested a review from Dongbo Wang (daxian-dbw) October 3, 2017 09:43
@iSazonov
Fix spelling
71a2c7f
daxian-dbw
Dongbo Wang (daxian-dbw) requested changes Oct 4, 2017
View reviewed changes
Comment thread docs/dev-process/coding-guidelines.md Outdated
as it obscures the functional changes of the PR.
A separate PR should be submitted for such refactoring without any functional changes.

* Avoid initializing variables, fields and auto-implemented properties to zero or null because C# guarantees its are initialized to zero.

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017

Copy link
Copy Markdown
Member

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.

I feel this one is not important to be put here. For example, some developers might always make sure all local variables are initialized before use, which is fine and won't actually cause any overhead -- IL code will have the assignment but JIT will be smart enough to not do the assignment.

Instead, I think we should mention the Interlocked type here, which I saw in Managed Threading Best Practices:
Consider using the Interlocked class instead of the lock statement to atomically change simple states. The Interlocked class provides better performance for updates that must be atomic.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 4, 2017

Copy link
Copy Markdown
Collaborator Author

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.

Will add Interlocked.

We should have a consensus about initializations - it seems your positions is different from the Paul Higinbotham (@PaulHigin) position.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

I think null/zero initializations for local variables doesn't matter perf-wise. Personally, I prefer to always initialize local variables before use, but that's not something should be enforced to everyone.
For type fields, I saw some are initialized to 0, but rarely see people initialize them to null, but either way, I won't pick it in code review.
For auto properties, I never saw people initialize it to null or zero (maybe there are but rare).

Overall, I think we should just remove this item.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 5, 2017

Copy link
Copy Markdown
Collaborator Author

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.

Removed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread docs/dev-process/coding-guidelines.md Outdated

* Avoid initializing variables, fields and auto-implemented properties to zero or null because C# guarantees its are initialized to zero.

* Follow Microsoft best practise guidances:

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017

Copy link
Copy Markdown
Member

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.

Let's not say follow because some of those guidelines are contradicting with our coding convention. For example, the naming guideline in the first link below says "do not use "g_" or "s_" to indicate static fields", while we require static fields to start with s_ or t_.

I think it's better to say: "Here are some useful links for your reference:"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 4, 2017

Copy link
Copy Markdown
Collaborator Author

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.

Fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread docs/dev-process/coding-guidelines.md Outdated
* [Collections](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/guidelines-for-collections)
* [Exceptions](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/exceptions)
* [Best Practices for Developing World-Ready Applications](https://docs.microsoft.com/en-us/dotnet/standard/globalization-localization/best-practices-for-developing-world-ready-apps) - Unicode, Culture, Encoding and Localization.
* [Best Practices for System.Net Classes](https://docs.microsoft.com/en-us/dotnet/framework/network-programming/best-practices-for-system-net-classes)

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017

Copy link
Copy Markdown
Member

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 one seems to focus on full .NET instead of .NET Core, so it mainly talks about things related to WebRequest and WebResponse.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 4, 2017

Copy link
Copy Markdown
Collaborator Author

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.

I added just for WebRequest and WebResponse.
Remove?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

WebRequest and WebResponse are mostly deprecated, and HttpClient is the way to go. So I think we can remove this link.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 5, 2017

Copy link
Copy Markdown
Collaborator Author

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.

Removed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread docs/dev-process/coding-guidelines.md Outdated
* [Exceptions](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/exceptions)
* [Best Practices for Developing World-Ready Applications](https://docs.microsoft.com/en-us/dotnet/standard/globalization-localization/best-practices-for-developing-world-ready-apps) - Unicode, Culture, Encoding and Localization.
* [Best Practices for System.Net Classes](https://docs.microsoft.com/en-us/dotnet/framework/network-programming/best-practices-for-system-net-classes)
* [Best practices for exceptions](https://docs.microsoft.com/en-us/dotnet/standard/exceptions/best-practices-for-exceptions)

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017

Copy link
Copy Markdown
Member

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.

Please use capital P for practices and capital E for exceptions to be consistent with others.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 4, 2017

Copy link
Copy Markdown
Collaborator Author

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.

Fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread docs/dev-process/coding-guidelines.md
* [Best Practices for Developing World-Ready Applications](https://docs.microsoft.com/en-us/dotnet/standard/globalization-localization/best-practices-for-developing-world-ready-apps) - Unicode, Culture, Encoding and Localization.
* [Best Practices for System.Net Classes](https://docs.microsoft.com/en-us/dotnet/framework/network-programming/best-practices-for-system-net-classes)
* [Best practices for exceptions](https://docs.microsoft.com/en-us/dotnet/standard/exceptions/best-practices-for-exceptions)
* [Best Practices for Using Strings in .NET](https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings)

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017

Copy link
Copy Markdown
Member

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.

I have been very confused about when to use InvariantCulture vs. Ordinal, and I believe there are many other developers like me :) I think this one is very useful.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread docs/dev-process/coding-guidelines.md Outdated
* [Best practices for exceptions](https://docs.microsoft.com/en-us/dotnet/standard/exceptions/best-practices-for-exceptions)
* [Best Practices for Using Strings in .NET](https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings)
* [Best Practices for Regular Expressions in .NET](https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices)
* [Serialization guidelines](https://docs.microsoft.com/en-us/dotnet/standard/serialization/serialization-guidelines)

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017

Copy link
Copy Markdown
Member

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.

Please use capital G for guidelines.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Oct 4, 2017

Copy link
Copy Markdown
Collaborator Author

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.

Fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov
Address feedback
b900581
daxian-dbw
Dongbo Wang (daxian-dbw) requested changes Oct 4, 2017
View reviewed changes
Comment thread docs/dev-process/coding-guidelines.md Outdated
as it obscures the functional changes of the PR.
A separate PR should be submitted for such refactoring without any functional changes.

* Avoid initializing variables, fields and auto-implemented properties to zero or null because C# guarantees its are initialized to zero.

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

I think null/zero initializations for local variables doesn't matter perf-wise. Personally, I prefer to always initialize local variables before use, but that's not something should be enforced to everyone.
For type fields, I saw some are initialized to 0, but rarely see people initialize them to null, but either way, I won't pick it in code review.
For auto properties, I never saw people initialize it to null or zero (maybe there are but rare).

Overall, I think we should just remove this item.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread docs/dev-process/coding-guidelines.md Outdated
* [Collections](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/guidelines-for-collections)
* [Exceptions](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/exceptions)
* [Best Practices for Developing World-Ready Applications](https://docs.microsoft.com/en-us/dotnet/standard/globalization-localization/best-practices-for-developing-world-ready-apps) - Unicode, Culture, Encoding and Localization.
* [Best Practices for System.Net Classes](https://docs.microsoft.com/en-us/dotnet/framework/network-programming/best-practices-for-system-net-classes)

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 4, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

WebRequest and WebResponse are mostly deprecated, and HttpClient is the way to go. So I think we can remove this link.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Ilya (iSazonov) and others added 2 commits October 5, 2017 08:28
@iSazonov
Remove unapproved additions
7365525
@daxian-dbw
Remove 'System.NET' as it's been removed from doc
e5e7a99
daxian-dbw
Dongbo Wang (daxian-dbw) approved these changes Oct 5, 2017
View reviewed changes
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit ec1106a into PowerShell:master Oct 5, 2017
@iSazonov
Ilya (iSazonov) deleted the coding-guidence branch October 6, 2017 03:45
@iSazonov Ilya (iSazonov) mentioned this pull request May 3, 2018
Quote Multipart/Form-Data Field Names #6782
Merged
8 of 11 tasks
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@iSazonov @daxian-dbw
Add links on best practice guidelines in coding guideline (PowerShell…
d495b51
…#4983)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@iSazonov @daxian-dbw
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.