antsouchlos / OxygenEngine2

MIT License
0 stars 1 forks source link

Setting a naming convention for identifiers #3

Open antsouchlos opened 2 years ago

antsouchlos commented 2 years ago

I think it is long overdue to agree on some common conventions for OxygenEngine.

I'll start with proposing a convention for identifiers, even though I am sure @philsegeler won't be happy with everything. At least we will have a base upon which to start a discussion.

Proposed naming conventions

General

No function or class name should ever be prefixed with e.g. oe_, csl_, etc. Instead simply use namespaces. And never ever start any identifier with an underscore.

Functions

Function names should be written in snake_case. This applies to both free and member functions:

void do_smth() {
    // ...
}

class SomecCass {
public:
    void some_action() {
        // ...
    }
}

Classes

All class names should be written in CamelCase:

class SomeClass {
    // ...
};

Member variables

Member variables should be prefixed with m_ to signal they are class members, not local variables

class SomeClass {
private:
    int m_some_integer;
    std::array<char, 256> m_buffer;
};

Template parameters

There is no distinction between class and function template names.

All template parameter names should be written in snake_case. Type template parameters should be suffixed with _t, non-type template parameters should be prefixed with t_:

template<typename arg_t, unsigned t_count>
void do_smth(arg_t arg) {
    // ...
}
philsegeler commented 2 years ago

My thoughts:

General

See below

Functions

We previously agreed on using snake case for API and user-facing functions and classes and CamelCase+prefixes for internal classes and functions. In my es2_renderer branch i have already rewritten the nre::gpu::... functions to fit this style.

On the other hand, maybe having different conventions and prefixes is confusing, but i don't think oe::TaskManager or oe::sdl::WindowSystem for example looks well at all. I could maybe consider snake_case for everything though (classes included), if we are to keep one convention and remove prefixes, like this:

oe::task_manager, oe::sdl::window_system

Classes

Same as above.

Member variables

A better thing in my view would be to suffix with _, like

namespace oe{
    class some_class {
    private:
        int some_integer_;
        std::array<char, 256> buffer_;
    };
};

This already exists to some degree in the code and this also makes special syntax highlighting by text editors (particularly the one i am using, Kate) possible, while with m_, it doesn't.

Template parameters

No objections or anything particular to the _t and t_, but for functions same as above.

antsouchlos commented 2 years ago

Snake Case for everything it is then

I also don't see any issues with using _ as a suffix instead of m_ as a prefix for member variables.

philsegeler commented 2 years ago

A rewrite to snake_case can only happen AFTER i have finished with the feature/es2_renderer branch though. Keep that in mind. I don't think that a basic ES 2 renderer is far off though, i have almost finished rewriting the shaders and will only need to rewrite adapt the renderer now.

antsouchlos commented 2 years ago

No worries, let's just find some convention first. The rewriting of the code to fit the agreed upon convention can follow at a later stage, when it is practical.

But I take it we have agreed on the first proposed convention, with the following changes?

philsegeler commented 2 years ago

Yes exactly. Those and no prefixes, everything in namespaces. I strongly object your supposed way of formatting namespaces though (in the other issue).

antsouchlos commented 2 years ago

Reopening until changes are implemented

antsouchlos commented 2 years ago

Actually, having snake_case for class names, function names and variables might be a bit confusing.

One Idea would be to change the convention for class names to snake_case with a _t suffix. Since this would clash with the template parameter naming convention, however, here is a new proposal for that one:

CamelCase for template parameters. If they are class template parameters, add a _-suffix to indicate they belong to a class:

template<typename Arg_, int NonTypePar_>
class some_class_t {
public:
    some_class_t() = default;

    template<typename FuncArg, int FuncNontTypePar>
    void do_smth() {}
};
philsegeler commented 2 years ago

Yes, now it makes more sense. Also names ending in _t are highlighted differently in my text editor.

philsegeler commented 2 years ago

Please update the wiki with the new naming conventions for classes and template parameters we agreed on

antsouchlos commented 2 years ago

Done