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

Use consistent coding style for powerGate cmdlets #232

Open
2 of 4 tasks
ThomasRossmeisl opened this issue Oct 19, 2022 · 2 comments
Open
2 of 4 tasks

Use consistent coding style for powerGate cmdlets #232

ThomasRossmeisl opened this issue Oct 19, 2022 · 2 comments

Comments

@ThomasRossmeisl
Copy link
Contributor

ThomasRossmeisl commented Oct 19, 2022

Description

Use -InputObject instead of pipe operator

Most of the powerGate cmdlets pipe their input object into the cmdlet. This results in very poor readability as it looks like an assignment on the first sight. Using the -InputObject parameter would increase readability.
For example:
image
could be
image

An exception can be made if there is an assignment prior to the pipe as in this case there is no risk of confusion
image

Use $null = instead of | Out-Null

In multiple places unused output is piped into | Out-Null. This is hard to read as the scripting guy has to look to the right to see that the output is handled, when usually they would look to the left to see an assignment.
image

Instead $null = should be used as this is more consistent and easier to read
image

Don't use positional parameters

Also cmdlet calls use the -InputObject parameter, but as a positional parameter. This also causes worse readability. Named parameters are preferred as they make it obvious on sight what parameters are used. They also make it easier to debug errors when invalid values like $null are passed.
image
should be
image

Consistently name variables

Some variables are not named in a way that reflects their content. In the following example the variable is named erpBomHeaderResult, but it actually contains an Erp-BOM header.
image
should be
image

Some variables are named, but actually never used. In this case the return value of the function should be assigned to $null. This makes it immediately clear that the value never is used.
image
should be
image

Tasks:

  • Use -InputObject instead of pipe operator
  • Use $null = instead of | Out-Null
  • Don't use positional parameters
  • Consistently name variables
@miltcapsimalis
Copy link

This is very helpful for those of us who didn't grow up using script languages like PowerShell. It would be cool to collect up a coolOrange style guide so guys like me don't make a mess when we do write scripts. I would not put excess time into it but maybe collect these into StackOverflow as you think of them?

@ThomasRossmeisl
Copy link
Contributor Author

ThomasRossmeisl commented Oct 20, 2022

Thank you for your feedback Milt. I fully agree. A consistent coding style is especially helpful for beginners and I think it also benefits veteran scripters.
If I recall correctly we started to write something up back when I was in the project team. Jakob informed me that they still have regular coding style meetings. I asked Jakob to invite me if they need some input.

Also I think it would be nice if we could provide a custom linter. That would make it easier to adhere to guidelines and could even be shared with customers. Though it probably is a lot of work to write one.

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

No branches or pull requests

2 participants