Comments (7)
Yep, I agree with that. In general, camelCase for variables, but PascalCase for parameter names because parameters are expected to be PascalCase and it affects tab-completion/intellisense, etc.
I'm not sure the style guide needs to specify a preference for capitalization though, apart from function names and parameters -- although I will admit I have a strong preference for $camelCase
vs $python_style_separated_words
;-)
from powershellpracticeandstyle.
I tend to use PascalCase everywhere, mainly because it looks more formal. Also, if I define a parameter with PascalCase, tab-completion copies that in the body of the function so that's generally what I stick with.
@Jaykul do you have any arguments for a certain style, like camelCase? I've seen some who attempt to differentiate variable scope with casing, but it seems too complex and delicate to support.
from powershellpracticeandstyle.
I don't think there are any arguments for certain styles that can't be countered. Clearly it's "easier" to type lower case letters, but $variable
vs $Variable
is hard to argue considering that leading $
...
The fact is that the built-in variables are also all over the map. Most people tend to use all upper case for "constants" but PowerShell uses all lower case: $null
, $true
, $false
, $args
, $input
... and then sometimes uses upper case: $PID
, $HOME
, $PSHOME
, $PWD
and $LASTEXITCODE
... but all the preference variables are PascalCase: $ConfirmPreference
, $DebugPreference
, $ErrorActionPreference
, $InformationPreference
, $MaximumAliasCount
, $MaximumDriveCount
, $MaximumErrorCount
, $MaximumFunctionCount
, $MaximumHistoryCount
, $MaximumVariableCount
, $ProgressPreference
, $PSBoundParameters
, $PSCommandPath
, $PSCulture
, $PSDefaultParameterValues
, $PSEdition
, $PSEmailServer
, $PSScriptRoot
, $PSSessionApplicationName
, $PSSessionConfigurationName
, $PSSessionOption
, $PSUICulture
, $PSVersionTable
, $VerbosePreference
, $WarningPreference
, $WhatIfPreference
.....
And then there's $PROFILE
in powershell.exe, but $profile
in ISE?
from powershellpracticeandstyle.
i do UpperCaseEachWord for parameters for functions, and lowerCamelCase for variables inside functions.
from powershellpracticeandstyle.
from powershellpracticeandstyle.
from powershellpracticeandstyle.
Is there more than just previous language experience that would make camelCase better?
Probably not but for us C# devs, it's hard to shake. I still tend to use camelCase for local variables and PascalCase for everything else (parameters, script/global variables).
It might be better to ask the VB crowd about casing conventions for variables, since VB also has case-insensitive variable names IIRC. I suspect there probably should be a recommendation to use the same casing for a variable everywhere e.g. if I initialize $foo try to use $foo everywhere instead of $FOO or $Foo or $FoO.
from powershellpracticeandstyle.
Related Issues (20)
- Add Gotcha :: Breaking from the pipeline HOT 3
- Question: Best Practice fot HOT 3
- Indentation advice is bad/wrong HOT 9
- Constant variables placement with in a script. HOT 1
- Is it better to use $PSItem vs $error[0] or $_ HOT 2
- Add Set-Variable vs. $foo = "bar" best practice HOT 2
- Correct formatting HOT 5
- Unquoted strings HOT 3
- Indentation on Comment-Based help HOT 5
- Consider revising PERF-02 HOT 1
- Naming-Conventions refers to a broken link
- Guidance on External Module Dependencies HOT 3
- Suggestion - explain why the second command in PERF-01 is faster
- Capitalization of function parameter type HOT 2
- Broken link and sentence fragment on naming conventions page
- Module structure HOT 4
- Avoid Using Semicolons (`;`). HOT 3
- Parameter Comments and Get-Help HOT 2
- Begin/Process/End or Process only. No Process/End, Begin/End, Begin/Process. HOT 5
- Indentation for lines after a pipe character HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powershellpracticeandstyle.