none
Naming Sub Routines Standards RRS feed

  • Question

  • All

    This is not a technical question but just a general request to see if there is any best practice regarding naming standards for sub routines.

    If you have an application that has say 30 plus  sub routines do any of  you any specific naming standards? Obviously you give each routine a meaningful name - but I was considering adding a prefix perhaps S10, S20, S30 and so on just to be able to order the routines.

    it seems ok but I am not sure this is best practice - any suggestion of what others might use would be helpful and interesting.

    thanks,

    Peter

    Friday, January 27, 2017 9:28 AM

Answers

  • Hi,

    I can share my personal preference.. though this not something which I have read somewhere but i find it helpful :

    1. Ofcourse meaningful name

    2. At the same time I name them based on the type of it.. Example:

         I start the name with the action name which it is going to do - 

         If a function is supposed to return the name of a worksheet then - GetWorkSheetName()

         If a function going to return a boolean (true/false) then - IsWorksheetOpen()

         If a function going to performs a specific task then - SaveWorksheet(), CloseWorksheet(), CalculateInterestRate()

    Therefore mostly my function names start with a verb/action etc and later explaining that verb/action. With this while coding I know like it will be returning a value or what type of value etc. 

    This is something I follow. 

    As you mentioned with the prefix S10, S20 you can put but it all depends on what is the later part of the naming convention because S10, S20 does not say anything about the function.

    Also, I am not sure what do you mean by "Order of the Subroutines"? and what is purpose. But if it is for giving an idea to call them in the right sequence then this is absolutely fine I guess.


    Vish Mishra

    • Marked as answer by py1 Friday, January 27, 2017 11:24 AM
    Friday, January 27, 2017 10:22 AM

All replies

  • Hi,

    I can share my personal preference.. though this not something which I have read somewhere but i find it helpful :

    1. Ofcourse meaningful name

    2. At the same time I name them based on the type of it.. Example:

         I start the name with the action name which it is going to do - 

         If a function is supposed to return the name of a worksheet then - GetWorkSheetName()

         If a function going to return a boolean (true/false) then - IsWorksheetOpen()

         If a function going to performs a specific task then - SaveWorksheet(), CloseWorksheet(), CalculateInterestRate()

    Therefore mostly my function names start with a verb/action etc and later explaining that verb/action. With this while coding I know like it will be returning a value or what type of value etc. 

    This is something I follow. 

    As you mentioned with the prefix S10, S20 you can put but it all depends on what is the later part of the naming convention because S10, S20 does not say anything about the function.

    Also, I am not sure what do you mean by "Order of the Subroutines"? and what is purpose. But if it is for giving an idea to call them in the right sequence then this is absolutely fine I guess.


    Vish Mishra

    • Marked as answer by py1 Friday, January 27, 2017 11:24 AM
    Friday, January 27, 2017 10:22 AM
  • thanks - helpful
    Friday, January 27, 2017 11:24 AM