8000 Cleanup TestConnectionCommand by vexx32 · Pull Request #10439 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@vexx32
Copy link
Collaborator
@vexx32 vexx32 commented Aug 24, 2019

PR Summary

Style pass only as part of #10044

PR Context

Rewriting the Test-Connection Command a good bit. @iSazonov suggested I split it up into stages to make reviewing the PR changes much easier.

This is part 1, only containing style fixes. There are no functional changes.

Feel free to review commit-by-commit for easier diffs. 🙂

PR Checklist

/// <summary>
/// The implementation of the "Test-Connection" cmdlet.
/// </summary>
[Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = ParameterSetPingCount, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using ParameterSet prefixes looks good to me - this makes code more readable and understandable.
Otherwise a code reader will have to review all code in the file to find that a const is used in Parameter() attribute as a parameter set.

I'd remove the commit.

Copy link
Collaborator Author
@vexx32 vexx32 Aug 26, 2019

Choose a reason for hiding this comment

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

Is the <Name>Set form not sufficient to convey that intention here? Every context they're used is either in a [Parameter] attribute or in a switch (ParameterSetName) construct -- both of which are more than sufficient to indicate that they're used in parameter sets.

Since attribute values must be constant values, I think it's reasonable to assume that readers will be able to infer this information. (Plus, most code editors have a "Show/Peek Definition" in their right-click context menu, and these constants are defined immediately below here, at the top of the class.)

As I was reading through this file I found that the overly long names of the constants tended to make them confusing to read, and they're typically surrounded by at least one mention of [Parameter] or something similar, rendering the Parameter segment of the name pretty redundant in context.

It's also not a pattern I see anywhere else in the repo?

Copy link
Collaborator

Choose a reason for hiding this comment

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

C# best practice is to use informative names without abbreviations. As result we sometimes have long names.
I see different patterns in our code. You could look AddMember.cs, AddType.cs, ConvertFromMarkDownCommand.cs.
It would be nice to have one patter but we haven't.
As for my request one example is that we frequently use switch statements for parameter sets and it would be good at first glance to understand that a constant with the parameter set name is used there.

Copy link
Collaborator Author
@vexx32 vexx32 Aug 26, 2019

Choose a reason for hiding this comment

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

I guess that makes some sense, and yeah I hear you on the inconsistent patterns there. With the switch statements, these are usually used as switch (ParameterSetName) {}, so I think it's pretty clear there as well given that that's the context of the switch statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adjusted the names here to be clearer. 🙂 👍

/// <summary>
/// Force using IPv4 protocol.
/// </summary>
[Parameter(ParameterSetName = DefaultPingSet)]
Copy link
Collaborator 10BC0

Choose a reason for hiding this comment

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

I'd do not remove this - later we could add new parameter sets in the cmdlet. I did not implement them because of bugs in CoreFX.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which possibilities exist that would be agnostic to IPv4/v6?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand you question. I mean that later it would be easier to add new features in the cmdlet (like PathPing). (I am thinking about enhanced version of the cmslet with remoting support: user in A point could ping/traceroute/... C from B)

Copy link
Collaborator Author
@vexx32 vexx32 Aug 26, 2019

Choose a reason for hiding this comment

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

Is there significant advantage to having that from this cmdlet? This would have to be supported by PSRemoting anyway, so I don't know why we'd do that here -- users have Invoke-Command already, and the native APIs utilised by .NET core (and by extension, us) don't have this capability, so we'd be leaning on that already.

Basically, I'm asking -- why do these parameters need to have the sets specified when not all parameters are written this way? I think it makes more sense to have the command written to its current capability, and then when we implement new features we can add them or adjust parameters as needed.

Can we reasonably predict possible future scenarios here with accuracy? I don't think it makes a lot of sense to complicate parameter binding here at this point in time. 😕

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤷‍♂ not particularly an issue I suppose, we could debate this all day. It isn't hurting anything by leaving it in; I reverted this commit.

Thanks! 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

This would have to be supported by PSRemoting anyway

It seems we have a tracking issue to have remoting common parameters for all cmdlets.
With this we could get functionality like Test-NetConnection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would be awesome!

Something to note: The original implementation has a -Source command. It seems the win32 APIs for ICMP echo actually support a similar parameter, but there it is used to designate the NIC that is used to send the ICMP request.

However, .NET Core does not expose this capability to us at present. Hopefully we can get that in future as well! 😊

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems the win32 APIs for ICMP echo actually support a similar parameter,

It is WMI.

/// The implementation of the "Test-Connection" cmdlet.
/// </summary>
[Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
[OutputType(typeof(PingReport), ParameterSetName = new string[] { DefaultPingSet })]
Copy link
Collaborator

Choose a reason for hiding this comment

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

It do not make the code more readable for me.
I'd remove the commit.

/// </summary>
[Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
[Cmdlet(VerbsDiagnostic.Test, "Connection", DefaultParameterSetName = DefaultPingSet,
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135266")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need the new line? I'd revert.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mostly readability, long lines tend to get lost in the mix here. It's also a common pattern with a fair few cmdlets in the repo to put the HelpUri on the following line.

🤷‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe text width up to 120-144 is good for modern displays.

< DCA4 input type="hidden" name="_method" value="put" autocomplete="off" />

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, I'll revert this one. 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@iSazonov the width here if this stays on a single line is 150; should I leave this on two lines? 😕

Copy link
Collaborator
@iSazonov iSazonov Aug 27, 2019

Choose a reason for hiding this comment

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

My request is not blocking. If you see a problem on your screen - make two line or multi-line format.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I'll leave this one as-is for now. Two lines is (I think) sufficient. Thanks! 🙂

@vexx32
Copy link
Collaborator Author
vexx32 commented Aug 27, 2019

We're ignoring Codacy's complaints per @iSazonov's comment here: #10439 (comment)

It flags the type specifier as unnecessary, which is technically correct, but stripping it out isn't particularly elegant in this context.

@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Aug 27, 2019
@iSazonov iSazonov added this to the 7.0.0-preview.4 milestone Aug 27, 2019
@vexx32
Copy link
Collaborator Author
vexx32 commented Aug 30, 2019

@adityapatwardhan is there anything more you need from me on this one?

Would like to get this one wrapped up soon if possible, I have a few follow ups to this I would like to get done by 7.0 release. Thanks! 💖 😊

@adityapatwardhan adityapatwardhan merged commit 27c48a7 into PowerShell:master Sep 3, 2019
@adityapatwardhan
Copy link
Member

@vexx32 Thank you for your contribution!

@vexx32 vexx32 deleted the TestConnection/Style branch September 3, 2019 20:15
TravisEz13 pushed a commit to TravisEz13/PowerShell that referenced this pull request Sep 14, 2019
@ghost
Copy link
ghost commented Sep 19, 2019

🎉v7.0.0-preview.4 has been released which incorporates this pull request.:tada:

Handy links:

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

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0