Skip to content

Naming of boolean setters/getters #33026

@akien-mga

Description

@akien-mga

We have a lot of inconsistency in the current codebase on how we name boolean setters and getters, and especially those we expose to the scripting API.

We should aim at fixing that for 4.0, breaking compatibility where needed. Related to #16863.

Current uses are of the form:

bool stuff = false;

void set_stuff(p_enable);
void set_stuff(p_enabled);
void set_stuff_enabled(p_enable);
void set_stuff_enabled(p_enabled);
void set_stuff_enabled(p_stuff);

bool get_stuff();
bool get_stuff_enabled();
bool is_stuff();
bool is_stuff_enabled();

Can also be more tricky if the boolean name is verb, like:

bool process = false;

void set_process(p_enabled);
void set_processing(p_enabled);

bool get_process();
bool get_processing();
bool get_process_enabled();
bool get_processing_enabled();
bool is_process();
bool is_processing();
bool is_process_enabled();
bool is_processing_enabled();

I'm not sure what style we should settle on, but it needs to be consistent.

Here's a proposal to start the discussion:

  • Name boolean themselves as nouns, e.g. processing instead of process, which solves some of the issues shown above.
  • Use p_enabled as parameter in the setter.
  • Use set_<boolean> for the setter, and is_<boolean>_enabled as getter.

Example:

bool processing = false;
void set_processing(p_enabled);
bool is_processing_enabled();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions