How to name a function

    技术2022-05-20  44

    Generally, function names should be simple, understandable (self-description) and correct. There are some tips that should be paid attention. 1)    Names should elaborate “what it is to do”, NOT “How it is to do”

           You can refer to command & query separation @ http://www.pragprog.com/articles/tell-dont-ask; Think naming from the view of responsibilities rather than implementation. 2)    The name can be structured as Do_What (i.e. a noun following a verb). For example, LoadGrid is better than SendGridLoadLogic when you want to refresh a grid. 3)    The name for test cases can be structured as TestTarget_PreCondition_ExpertedResult. For example, “LoadGrid_NullDateRange_NoRowsReturned”.

    ==>Anyway, easy-reading is higher than easy-writing.


    最新回复(0)