Skip to content

Commit 541204a

Browse files
pks-tgitster
authored andcommitted
Documentation: document naming schema for structs and their functions
We nowadays have a proper mishmash of struct-related functions that are called `<verb>_<struct>` (e.g. `clear_prio_queue()`) versus functions that are called `<struct>_<verb>` (e.g. `strbuf_clear()`). While the former style may be easier to tie into a spoken conversation, most of our communication happens in text anyway. Furthermore, prefixing functions with the name of the structure they operate on makes it way easier to group them together, see which functions are related, and will also help folks who are using code completion. Let's thus settle on one style, namely the one where functions start with the name of the structure they operate on. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7df3f55 commit 541204a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Documentation/CodingGuidelines

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,25 @@ For C programs:
541541
use your own debugger and arguments. Example: `GIT_DEBUGGER="ddd --gdb"
542542
./bin-wrappers/git log` (See `wrap-for-bin.sh`.)
543543

544+
- The primary data structure that a subsystem 'S' deals with is called
545+
`struct S`. Functions that operate on `struct S` are named
546+
`S_<verb>()` and should generally receive a pointer to `struct S` as
547+
first parameter. E.g.
548+
549+
struct strbuf;
550+
551+
void strbuf_add(struct strbuf *buf, ...);
552+
553+
void strbuf_reset(struct strbuf *buf);
554+
555+
is preferred over:
556+
557+
struct strbuf;
558+
559+
void add_string(struct strbuf *buf, ...);
560+
561+
void reset_strbuf(struct strbuf *buf);
562+
544563
For Perl programs:
545564

546565
- Most of the C guidelines above apply.

0 commit comments

Comments
 (0)