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.
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
Updates to code layout and formatting #115
Updates to code layout and formatting #115
Changes from all commits
8c11368
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Weakens the statement
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.
Hm, perhaps. The original statement seems to contradict prior assertions, however, implying vaguely that all space that can be omitted inside such expressions should... Which i do not think is wise or consistent with prior assertions.
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.
Well, frankly: you should not put spaces inside parentheses or square braces -- although it's sometimes acceptable when you have multiple parentheses together (particularly when it wraps across multiple lines).
I mean, for example, don't write:
Instead write:
What do you think of changing this to read:
Although after some performance testing, we've basically stopped writing
${x}
unless we're using non-standard variable names, and are using$($x)
when it's necessary to separate the variable from the text around it.In fact, at work we've decided all variables in strings should be wrapped in a sub-expression, so that we can more easily refactor using search-and-replace in our editor without worrying about whether there's an instance in a string when we change
$Thing
to$Thing.Name
or whatever.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.
Well, for one the
foreach ($x in $( Get-Content $file )) {
is no different toforeach ($x in ( Get-Content $file )) {
in general (in fact, most people I've spoken to have no idea what$()
really adds outside of the standard usage in strings).But overall I tend to agree, mostly. Excessive spacing in an expression can sometimes detract, though, as you mention, so there's a bit of a "do what works best for you" element here as well for some of the more complex expressions.
Example:
(Now granted, that is a highly contrived example, but the point is mainly that there are a great many places you could opt to place additional spaces -- but adding spaces everywhere makes the expression more difficult to read, because the expressions lose their grouped appearance which lends some intuitive clarity ("things that look like they're together work together" sort of idea).
Not sure about the
$($x)
vs${x}
myself. I too tend to use them only when necessary (e.g.,${c:\windows\drivers\etc\hosts}
, but I find myself preferring them to delimit variables in strings.It may also be worth a mention that some folks prefer to reserve that syntax for function parameters to distinguish them from purely local variables.
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.
We actually standardized on
$($x)
over${x}
for two reasons:$userName
to$User.Name
-- you can rename $userName to $User.Name with a simple search and replace, but only if you never wrote ${userName} anywhere...Not trying to put that in the best practices book (yet) though 😉