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

Constant variables placement with in a script. #142

Open
ebmarquez opened this issue Oct 23, 2019 · 1 comment
Open

Constant variables placement with in a script. #142

ebmarquez opened this issue Oct 23, 2019 · 1 comment

Comments

@ebmarquez
Copy link

What is the general guidance on the use of Constance and where to place them within a script?
For example, I need to declare a URI of $api = "http://127.0.0.1:500/api/path". Is it better to place this variable next to the invoke-RestMethod or place it at the beginning of the script since it's a constant?

@brianmullinsbsd
Copy link

I prefer at the top of the script. The purpose of constants is to be able to reuse them throughout the code, and not have paths. uri's, etc that periodically need updating being spread throughout. Leaving them at the top allows you to make them more visible to the maintainer. I always try to document them well, and that documentation could include clues to where they are used throughout the code, although that documentation in-and-of-itself could become difficult to maintain.

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

No branches or pull requests

3 participants