Why give a meaningful name to functions and variables?
1. The code is written to the later self and others to see, easy to understand the variable name can be better read, and can see the coder's personal accomplishment and programming skills;
2. Good variable name is helpful to improve your English level (vocabulary, expression ability), English level is improved, the comments in the code is also very helpful;
3. The ability to develop their own words, and choose what kind of a word to express its most close to the meaning of the Code;
How do I give a meaningful name to a function and a variable?
1. Read the good code, understand how others take the variable name, and constantly accumulate, good memory is inferior to bad writing;
2. Read the relevant books, "Code Daquan", "Code Clean Road";
3. When you write, more elaborate, you can use the English dictionary, the most accurate words to express meaning;
4. When you have time to review your notes, deepen memory (should follow the brain's memory curve);
function naming principle:
The advantage of file name +filename_dosomething() name plus file name is that it is possible to repeat the definition when the function is not static declaration; It is better to capitalize the first letter of the word, Avoid confusing multiple words together. There are often words:
Reset resets a peripheral, such as a reset PHY chip _resetphy8201f
Init exit
_initconfig _initreg Chip_init Chip_exit
Start/run stop
Start or stop a state, such as turning the watchdog on or off, and the Begin end Difference
Execute
_executecmd
Reg Unreg
_regops: Register the operation function, this is commonly used to connect device-driven hierarchical relationship (common code processing modules layer and concrete operation method to implement chips layer, the bridge between the two is a module configuration pointer, which facilitates the portability of code).
_regcmd: Register proc Debug Interface function, Xxx_regcmd ("xxx", Xxx_executecmd, Xxxcmdusage);
Get Set
_setxxxstate _setxxxparam _setxxxrunparam _getxxxpos _setregbits _setgpiodir_setgpiolevel _SetXxxVal _GetCapacity
Write read
_readreg _readregcache (one is a read register and the other is read the register value stored in the array) _writereg
Dowrite Doread is called by write read
Dump _dumpreg _dumpinfo
Open Close
Input Output
Probe Remove
Create Delete
Enable disable to select _enablecs, read-write enable
Calc calculation (calculate) Calculation deviation
_calcoffset _calcelapse _calclength
Reverse forward
1. Flip, for example, if a bit rollover is required in the SPI transmission, reverse_8/16/32bits
2. Forward and backward
Backto back to a location, _backtozero, back to the origin.
Parse
_parseheader parsing a specific character in a string
Show
_showinfo _showstate
Variable naming principles:
Variable naming should follow the exact meaning of what is expressed in the code. The common words in the driver are:
1. Register parameter structure body T_REGPARAM:ADDR data num
2. Parameter configuration structure Body T_xxxconfig:
1) Some pin names attached to the peripheral and the host controller, Cspinidrstpinid
2) Chip types Type page size pagesize page total pagenum capacity capacity address Peugeot I2cflag read-write time-out timeout
3. Device object Structure Body T_xxxdev: a few parts.
1) Peripheral driver status, Spiflag I2cflag SPI I²c probe success
2) Register Array Regcache
Parameter configuration structure Body T_xxxconfig
3) Related structures interacting with modules
4) kernel-related drive mechanism
A. Waiting queue Wq waiting queue to determine the condition condition
B. Kernel Timer Timer
C. Mutex Mutex
D. Kernel Thread Task
E. Kernel bus communication mechanism related, device pointer this block is mainly used for bus communication use, I2c/spi Spidev Client Adapter
Give a meaningful name to the function and the variable