Skip to content

Add section on variable style #61

Closed

Description

@eodeluga

It may be in general guidelines, but I could not find a general guideline on defining variables and I think there should be a section for this.

Is it best to use camelCase?
Is it best to UpperCase each word?

What is the general community view?

Activity

  1. dotps1 commented on Jul 6, 2016

    @dotps1

    i do UpperCaseEachWord for parameters for functions, and lowerCamelCase for variables inside functions.

  2. Jaykul commented on Jul 6, 2016

    @Jaykul
    Member

    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 ;-)

  3. mattmcnabb commented on Jul 7, 2016

    @mattmcnabb
    Contributor

    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.

  4. gerane commented on Jul 7, 2016

    @gerane
  5. gerane commented on Jul 7, 2016

    @gerane
  6. Jaykul commented on Jul 7, 2016

    @Jaykul
    Member

    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?

  7. rkeithhill commented on Jul 10, 2016

    @rkeithhill

    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.

  8. locked and limited conversation to collaborators on Jul 22, 2023
  9. converted this issue into a discussion #172 on Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions