Passing variables between functions - naming conventions

doddwelldoddwell Member Posts: 65
Hello

This is a generic (probably picky!) question about the recommended naming conventions when passing variables between functions.

I have a form that calls FunctionA in a codeunit. FunctionA expects the parameter custNumber.
FunctionA calls FunctionB. FunctionB expects the parameter custNumber.

Should the parameters in both functions have the same name (custNumber) as per my example above? Or would you expect them to be different?

Thanks very much.

Comments

  • vaprogvaprog Member Posts: 1,141
    [Disclaimer: this is my view only and must not be regarded as authoritative]

    It's OK to name parameters to different functions the same. Standard NAV code does it all the time and there is little reason to transmogrify the names of parameters just to be different, especially if they are essentially the same, only in a different location.

    According to the style guide, the variable name should start with a capital letter, though.

    Function parameters and local variables should not be named the same as some global object. Even when the compiler is able to tell them apart, a human being might get confused or misled.
  • doddwelldoddwell Member Posts: 65
    Thanks Vaprog.

    I have been defining my variables with a leading Lower case letter (and my functions with a leading upper case letter). You are correct though (as per http://download.microsoft.com/download/8/D/F/8DF0E4EB-A660-4D64-A44B-0D15D579073A/NAV%20CAL%20Programming%20Guide.pdf), page 41.
  • Big_DBig_D Member Posts: 207
    Hi Doddwell

    Not following any Microsoft convention but we use 'l' for local variables, 'g' for global variables and 'p' for parameter variables, i.e.,

    Calling Function B

    FunctionB (lCustNumber);

    Function B

    FunctionB (pCustNumber)

    Good luck
    Big D signing off!
Sign In or Register to comment.