Proposal: BKE_library and BKE_main API naming: prefixes conventions #72604

Closed
opened 2019-12-20 16:04:12 +01:00 by Bastien Montagne · 10 comments

The purpose of this task is not to actually rename all our functions in those headers right now. But rather to define (and document, in a comment in those headers) proper rules for the BKE_xxx prefixes we should use for these 'public' APIs.

In the past years, me and the few other devs that had to work in that area tried to sanitize a bit old names, but looking at current code state I have the feeling this was at best a mixed success so far.


Current situation


Besides old, never-yet-renamed functions, currently we seem to motsly follow those rules for new/renamed functions:

BKE_main.h (affecting Main structure itself) BKE_main_
BKE_library.h (ID management) low-level ID-only BKE_libblock_ Those are ID-generic functions
data-block level BKE_id_ Those take into account the type of data-blocks
Main level BKE_main_id_ Those potentially affect all data-blocks in given bmain
Library data-blocks BKE_library_ Those are specific to Library data-blocks
BKE_library_query.h (queries over Main database) BKE_library_
BKE_library_remap.h (remapping of IDs) Actual remapping BKE_libblock_ Those are ID-generic functions
Callbacks BKE_library_callback_ For ID users outside of Main area
BKE_library_idmap.h (mapping from ID type/name to id) BKE_main_idmap_ Only used in reafile.c for in undo code currently
BKE_library_override.h (library overrides) On a single ID BKE_override_library_
On the whole Main BKE_main_override_library_

Remarks


  • BKE_library_idmap.h should really be name BKE_main_idmap.h, this is not really related to ID management (though it could be useful there in some cases), this is just an alternative 'view' of given Main content.
  • library is a confusing term, since it is used for both a specific datablock type, and as the generic ID management word.
  • libblock (when only considering the actual generic ID part of a data-block) versus id (when considering the whole data-block, including its type-specific stuff) is rather confusing and somewhat misleading. Also because we do not use libblock wording anywhere else in Blender codebase afaik. Not sure we’d benefit much about changing that now though, given how deep those functions go allover Blender codebase?

Proposal


First, rename BKE_library_idmap.h to BKE_main_idmap.h (and same for the .c implementation of course).
Then rename BKE_library files to use BKE_lib prefix instead (changing BKE_library.h to BKE_lib_id.h to avoid having too common/collision-risky name).
Finally split out Library data-blocks-specific functions into their own BKE_library file.

Then document this convention in respective headers, based on following principles:

  • File naming scope:
    ** BKE_main files are for operations over the Main database itself, or generating extra temp data to help working with it. Those should typically not affect the data-blocks themselves.
    ** BKE_library files are for operations over data-blocks themselves, although they might alter Main as well (when creating/Renaming/deleting an ID e.g.).
  • Use a common small prefix referring to a same header file:
    ** BKE_main_ is kind of obvious.
    ** BKE_lib_ for all the BKE_library files, to keep it short, and distinguish it from actual Library data-block specific code.
BKE_main.h (affecting Main structure itself) BKE_main_ -> BKE_main_
BKE_main_idmap.h (mapping from ID type/name to id) BKE_main_idmap_ -> BKE_main_idmap_
BKE_lib_id.h (ID management) low-level ID-only BKE_libblock_ -> BKE_lib_libblock_
data-block level BKE_id_ -> BKE_lib_id_
Main level BKE_main_id_ -> BKE_lib_main_
BKE_lib_query.h (queries over Main database) BKE_library_ -> BKE_lib_query_
BKE_lib_remap.h (remapping of IDs) Actual remapping BKE_libblock_ -> BKE_lib_remap_libblock_
Callbacks BKE_library_callback_ -> BKE_lib_remap_callback_
BKE_lib_override.h (library overrides) On a single ID BKE_override_library_ -> BKE_lib_override_library_
On the whole Main BKE_main_override_library_ -> BKE_lib_override_library_main_
BKE_library.h (Library IDs) Library data-blocks BKE_library_ -> BKE_library_

This should be enforced for all new functions added there, as well as any future cleanup/renaming.

The purpose of this task is not to actually rename all our functions in those headers right now. But rather to define (and document, in a comment in those headers) proper rules for the `BKE_xxx` prefixes we should use for these 'public' APIs. In the past years, me and the few other devs that had to work in that area tried to sanitize a bit old names, but looking at current code state I have the feeling this was at best a mixed success so far. -------- Current situation **** Besides old, never-yet-renamed functions, currently we seem to motsly follow those rules for new/renamed functions: | `BKE_main.h` (affecting Main structure itself) | | `BKE_main_` | | | -- | -- | -- | -- | | `BKE_library.h` (ID management) | low-level ID-only | `BKE_libblock_` | *Those are ID-generic functions* | | | data-block level | `BKE_id_` | *Those take into account the type of data-blocks* | | | Main level | `BKE_main_id_` | *Those potentially affect all data-blocks in given bmain* | | | Library data-blocks | `BKE_library_` | *Those are specific to Library data-blocks* | | `BKE_library_query.h` (queries over Main database) | | `BKE_library_` | | | `BKE_library_remap.h` (remapping of IDs) | Actual remapping | `BKE_libblock_` | *Those are ID-generic functions* | | | Callbacks | `BKE_library_callback_` | *For ID users outside of Main area* | | `BKE_library_idmap.h` (mapping from ID type/name to id) | | `BKE_main_idmap_` | *Only used in `reafile.c` for in undo code currently* | | `BKE_library_override.h` (library overrides) | On a single ID | `BKE_override_library_` | | | | On the whole Main | `BKE_main_override_library_` | | Remarks **** * `BKE_library_idmap.h` should really be name `BKE_main_idmap.h`, this is not really related to ID management (though it could be useful there in some cases), this is just an alternative 'view' of given Main content. * `library` is a confusing term, since it is used for both a specific datablock type, and as the generic ID management word. * `libblock` (when only considering the actual generic ID part of a data-block) *versus* `id` (when considering the whole data-block, including its type-specific stuff) is rather confusing and somewhat misleading. Also because we do not use `libblock` wording anywhere else in Blender codebase afaik. Not sure we’d benefit much about changing that now though, given how deep those functions go allover Blender codebase? Proposal **** First, rename `BKE_library_idmap.h` to `BKE_main_idmap.h` (and same for the `.c` implementation of course). Then rename `BKE_library` files to use `BKE_lib` prefix instead (changing `BKE_library.h` to `BKE_lib_id.h` to avoid having too common/collision-risky name). Finally split out `Library` data-blocks-specific functions into their own `BKE_library` file. Then document this convention in respective headers, based on following principles: * File naming scope: ** `BKE_main` files are for operations over the Main database itself, or generating extra temp data to help working with it. Those should typically **not** affect the data-blocks themselves. ** `BKE_library` files are for operations over data-blocks themselves, although they might alter Main as well (when creating/Renaming/deleting an ID e.g.). * Use a common small prefix referring to a same header file: ** `BKE_main_` is kind of obvious. ** `BKE_lib_` for all the `BKE_library` files, to keep it short, **and** distinguish it from actual Library data-block specific code. | `BKE_main.h` (affecting Main structure itself) | | `BKE_main_` | **->** | `BKE_main_` | | -- | -- | -- | -- | -- | | `BKE_main_idmap.h` (mapping from ID type/name to id) | | `BKE_main_idmap_` | **->** | `BKE_main_idmap_` | | `BKE_lib_id.h` (ID management) | low-level ID-only | `BKE_libblock_` | **->** | `BKE_lib_libblock_` | | | data-block level | `BKE_id_` | **->** | `BKE_lib_id_` | | | Main level | `BKE_main_id_` | **->** | `BKE_lib_main_` | | `BKE_lib_query.h` (queries over Main database) | | `BKE_library_` | **->** | `BKE_lib_query_` | | `BKE_lib_remap.h` (remapping of IDs) | Actual remapping | `BKE_libblock_` | **->** | `BKE_lib_remap_libblock_` | | | Callbacks | `BKE_library_callback_` | **->** | `BKE_lib_remap_callback_` | | `BKE_lib_override.h` (library overrides) | On a single ID | `BKE_override_library_` | **->** | `BKE_lib_override_library_` | | | On the whole Main | `BKE_main_override_library_` | **->** | `BKE_lib_override_library_main_` | | `BKE_library.h` (Library IDs) | Library data-blocks | `BKE_library_` | **->** | `BKE_library_` | This should be enforced for all new functions added there, as well as any future cleanup/renaming.
Bastien Montagne self-assigned this 2019-12-20 16:04:12 +01:00
Author
Owner

Added subscribers: @mont29, @brecht, @Sergey, @ideasman42

Added subscribers: @mont29, @brecht, @Sergey, @ideasman42
Author
Owner

Note that this is an initial draft, am not happy with all proposed new names,. E.g. the override case is a bit hairy, since we end up using library for two different meaning (lib, as 'par of ID management code, and in library override`, i.e. 'override of linked data-blocks' [opposed to 'dynamic override']), none of them being fully related to actual Library data-block itself…

Note that this is an initial draft, am not happy with all proposed new names,. E.g. the override case is a bit hairy, since we end up using `library` for two different meaning (`lib`, as 'par of ID management code`, and in `library override`, i.e. 'override of linked data-blocks' [opposed to 'dynamic override']), none of them being fully related to actual Library data-block itself…

Proposal sounds good to me.

One extra possible step is to split BKE_library perhaps. Just to add some separation between allocate new ID block and operations on Library. But that's another story :)

Proposal sounds good to me. One extra possible step is to split `BKE_library` perhaps. Just to add some separation between `allocate new ID block` and operations on `Library`. But that's another story :)

Well thought through, not much to add.

Minor preference to use the lib abbreviation for file naming too: BLI_lib.h BLI_lib_remap.h - we mostly stick to the same convention, so I think it's nice to keep this.

Well thought through, not much to add. Minor preference to use the lib abbreviation for file naming too: `BLI_lib.h` `BLI_lib_remap.h` - we mostly stick to the same convention, so I think it's nice to keep this.
Author
Owner

@Sergey @ideasman42 agree, will add.

@Sergey @ideasman42 agree, will add.
Author
Owner

Quick question: if we rename BKE_library to BKE_lib, do we want BKE_lib.h/lib.c (I guess not), or something like e.g. BKE_lib_id.h/lib_id.c ?

Quick question: if we rename `BKE_library` to `BKE_lib`, do we want `BKE_lib.h`/`lib.c` (*I guess not*), or something like e.g. `BKE_lib_id.h`/`lib_id.c` ?

Agree having lib.c - is too likely to collide w/ other names, BKE_lib_id.h/lib_id.c LGTM.

Agree having `lib.c` - is too likely to collide w/ other names, `BKE_lib_id.h`/`lib_id.c` LGTM.
Author
Owner

@ideasman42 thanks, also talked to @brecht here and he was fine with BKE_lib_id as well, so there we go.

@ideasman42 thanks, also talked to @brecht here and he was fine with `BKE_lib_id` as well, so there we go.
Author
Owner

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Author
Owner

Think we can close this now, changes at high-level have been approved and done, functions renaming will happen on case-by-case approach.

Think we can close this now, changes at high-level have been approved and done, functions renaming will happen on case-by-case approach.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#72604
No description provided.