-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unifying naming conventions across libnds #169
Comments
I feel like i have to explain the reasons why i named my code the way it is.
Code style is always a matter of preference you will probably get as many opinions as there are devs. |
Code style is a matter of preference, and I'm not criticizing any particular naming convention here; the goal is to get away from a situation where we have eight naming conventions for structure types, and unify them for the present and future. (Besides, it should have been my responsibility as the committer in such a situation to unify code styles, not yours.) |
https://en.cppreference.com/w/c/keyword
Regarding situations like |
The idea is that an user should never call |
Yes, but I mean that instead of using C extensions we can just have the functions as regular non-nested functions and mark them as In any case, this is a minor thing, I agree with the rest. |
Moving away from |
No, that's incorrect. Let me explain based on int bgInit_call(int layer, BgType type, BgSize size, int mapBase, int tileBase);
static inline int bgInit(int layer, BgType type, BgSize size, int mapBase, int tileBase)
{
return bgInit_call(layer, type, size, mapBase, tileBase);
}
// the `bgInit_call` definition still pollutes the user's namespace versus static inline int bgInit(int layer, BgType type, BgSize size, int mapBase, int tileBase)
{
int bgInit_call(int layer, BgType type, BgSize size, int mapBase, int tileBase);
return bgInit_call(layer, type, size, mapBase, tileBase);
}
// no pollution You can't use |
Ah, okay, I see what you mean. But, to be fair, in that case we should just move the wrapper function to the We did something similar in blocksds/libnds@2456564 when it become a problem to have the implementation of a function in a header. |
I'm not so sure about that. Remember the compiler won't optimize function calls across translation units unless we get LTO working. |
Depends on #168 - no point in starting this without first tackling that.
One of the many criticisms of libnds over the years has been the rather slapdash nature of its naming scheme. For example, functions currently may use any of the following cases:
dmaSetParams
(camel case, most common)BoxTest
(Pascal case)cothread_create
(snake case)TMIO_powerupSequence
(camel case with a snake prefix)setSDcallback
(a case)Some functions (like
soundPlayPSG
orcardPolledTransfer
) are prefixed with a category/namespace; others (likeenableSlot1
orwritePowerManagement
) are not.Structure types currently may use any of the following cases and styles:
rtcTimeAndDate
(camel case)TmioPort
(Pascal case)TUnpackStruct
(Pascal case with a Pascal-style prefix)tNDSHeader
(Pascal case with a lowercase Pascal-style prefix)PERSONAL_DATA
(upper-case snake case)cothread_info_t
(snake case with a_t
suffix)bg_attribute
(snake case)s_vramBlock
(camel case with as_
prefix)Enum types:
NWRAM_C_SLOT_MASTER
(upper-case snake case, most common)ObjShape
(Pascal case)GL_TEXTURE_TYPE_ENUM
(Pascal case with an_ENUM
suffix)PM_Bits
(a case)Private variables and functions exported publicly but used by libnds only internally are also often not prefixed; I think they should be, either with
libnds_
or__
, and they should not be exposed to the end user. For example, something likeint bgInit_call(int layer, BgType type, BgSize size, int mapBase, int tileBase);
should be defined inside thebgInit
function, so that an user cannot rely on this symbol accidentally in their production code.The correct naming scheme should be decided and documented as part of the code style, with all functions, types and variables adjusted to match.
Naturally, of course, renaming everything will break the world. Is there something we can do about this? For a previous transition, libnds provided a
registers_alt.h
file, with legacy register names (slightly different, most notably - not prefixed withREG_
).There is currently a large open source project undergoing a mass rename/refactor - SDL 3. They solved this by:
SDL_oldnames.h
file which contains#define
s for all previous names to all new names,WINDOW
),I believe the best options here for our uses are 1 and 3; option 1 can be realized by creating an
nds/oldnames.h
file that's only included, for example, for values ofBLOCKSDS_STRICT < 20000
(see #167 ), and option 3 can probably be generated from such a file.Note that most other libraries are ineligible -
dswifi
is maintenance-only,maxmod
is already fairly well prefixed, and many other libraries are provided by third parties - they could follow the same roadmap, but we obviously can't force them to.The text was updated successfully, but these errors were encountered: