summaryrefslogtreecommitdiff
path: root/doc/CodingStyle
blob: a326e5c3f9995151b106ae46039fe88e6c2f6166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
The libdns coding style guide

* Use of tabs (real tabs, 8 positions long)
* Spaces only after comma's, and in between operators.
  And after keywords (if, while, for)
* Underscores to make long names readable
* prefix (exported) identifiers with 'ldns_'
* no unneeded parentheses after 'return'
* always curly brackets in if-statements
* use defines for (weird) constants, and masks
* type 'bool', constants 'true'/'false'. Don't compare bools for
  equality.
* always use LDNS_MALLOC/FREE etc, or the new/free/deep_free functions
* buffer can scale, so don't alloc the max size, but the min size
* make lint (uses splint) is your friend


* Return values:
	- status code (structure to fill is usually passed as a first argument)
	- new/pointer: return pointer or NULL on error
	- 'read' functions: ldns_status wire2thing(uint8_t *p, size_t max,
	                                           size_t pos, *thing);
	- void functions like ldns_rr_free
	- bool functions

* Parameter sequence: (dest, [dest_meta, ] src, [src_meta] etc)
* structure/union field names start with _ when "private"
* enum for rcode, opcode, types etc,
	example:
	enum ldns_rcode {
		LDNS_RCODE_OK = 0,
		...      = .,
		LDNS_RCODE_FIRST = LDNS_RCODE_OK,
		LDNS_RCODE_LAST = 15,	
		LDNS_RCODE_COUNT = LDNS_RCODE_LAST + 1
	}
* Everything by reference, all data structures an optional _clone() function
* arrays: ps[] with size_t p_count for the number of elements
* _size for size in bytes
* _free and _clone copies perform deep free/copy.

* Standard abbreviations, don't abbreviate other names:

    id          = identity
    rr          = resource record
    rrset       = resource record set
    rdata       = resource data
    rdf         = resource data field
    rcode       = result code
    qr          = query/resource bit
    aa          = authoritative answer
    tc          = truncated
    rd          = recursion disabled
    cd          = checking disabled
    ra          = recursion available
    ad          = authentic data
    qdcount     = question section count
    ancount     = answer section count
    nscount     = authority section count
    arcount     = additional section count

ldns-<tools>
* use exit(EXIT_FAILURE)/ exit(SUCCES)
*