contrib : expand naming guidelines [no ci]

This commit is contained in:
Georgi Gerganov 2025-01-11 15:50:59 +02:00
parent 610a03a8c4
commit e7bc61bc53
No known key found for this signature in database
GPG key ID: 449E073F9DC10735

View file

@ -29,6 +29,8 @@
# Naming convention # Naming convention
- Use `snake_case` for function, variable and type names
- Use sized integer types in the public API
- Naming usually optimizes for common prefix (see https://github.com/ggerganov/ggml/pull/302#discussion_r1243240963) - Naming usually optimizes for common prefix (see https://github.com/ggerganov/ggml/pull/302#discussion_r1243240963)
```cpp ```cpp
@ -41,19 +43,42 @@
int number_big; int number_big;
``` ```
- The general pattern is `subject_verb_object`: - Enum values are always in upper case and prefixed with the enum name
```cpp ```cpp
llama_model_init(); // sub: "llama_model", vrb: "init", obj: "" enum llama_vocab_type {
llama_sampler_chain_remove(); // sub: "llama_sampler_chain", vrb: "remove", obj: "" LLAMA_VOCAB_TYPE_NONE = 0,
llama_sampler_get_seed(); // sub: "llama_sampler", vrb: "get", obj: "seed" LLAMA_VOCAB_TYPE_SPM = 1,
llama_set_embeddings(); // sub: "llama_context", vrb: "set", obj: "embeddings" LLAMA_VOCAB_TYPE_BPE = 2,
llama_n_threads(); // sub: "llama_context", vrb: "", obj: "n_threads" LLAMA_VOCAB_TYPE_WPM = 3,
llama_adapter_lora_free(); // sub: "llama_adapter_lora", vrb: "free", obj: "" LLAMA_VOCAB_TYPE_UGM = 4,
LLAMA_VOCAB_TYPE_RWKV = 5,
};
``` ```
- The `get` verb is optional - The general naming pattern is `<class>_<method>`, with `<method>` being `<action>_<noun>`
- The `_context` suffix of the subject is optional
```cpp
llama_model_init(); // class: "llama_model", method: "init"
llama_sampler_chain_remove(); // class: "llama_sampler_chain", method: "remove"
llama_sampler_get_seed(); // class: "llama_sampler", method: "get_seed"
llama_set_embeddings(); // class: "llama_context", method: "set_embeddings"
llama_n_threads(); // class: "llama_context", method: "n_threads"
llama_adapter_lora_free(); // class: "llama_adapter_lora", method: "free"
```
- The `get` `<action>` can be omitted
- The `<noun>` can be omitted if not necessary
- The `_context` suffix of the subject is optional
- Use `init`/`free` for constructor/destructor `<action>`
- Declare structs with `struct x {}` instead of `typedef struct x {} x`
- In C++ code omit the `struct` keyword whenever it is not necessary
- Use `_t` suffix when ...
- Follow the existing code style, in case of doubt use `clang-format` to format the added code
- (TODO: abbreviations usage)
# Resources # Resources