-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Added infrastructure for renaming API functions #6871
Conversation
This gives us the infrastructure to rename APIs however makes sense, as discussed in #6569. How do people feel about what was proposed in #6569 (comment)? The only difference I use from Eskil is a different approach to getters and setters. Eskil uses Regular functions:
Getters (same pattern for setters):
See how the words in the identifiers stack up — the beginning fragments are consistent, which is easy to filter, while getters and setters are easy to distinguish from regular functions. Three variants of getters should also be taken into account, i.e. the prefixes |
You can rename APIs using rename.py and all the code and documentation will be updated, and entries will be added to WhatsNew.txt and docs/README-migration.md. e.g. rename.py SDL_foo.h function SDL_CreateFoo SDL_FooCreate SDL_oldnames.h is included in the SDL header, and if you define SDL_ENABLE_OLD_NAMES, will redefine the old API functions to call the new ones, and if not, will define them as a symbol letting you what the new API function is.
I don't have a strong opinion about the overall idea (reading documentation plus IDE fuzzy matching for autocomplete lists means the change isn't much of an improvement for me personally I think) - but some of the specifics are a bit weird:
|
I don't think we would want to be militant about this. I agree with all of your examples, I would for example use |
I think the next step once we agree on a general direction is to add a comment for each header with proposed name changes (or maybe a separate issue, for discussion and tracking?) |
@furious-programming, would you be willing to go through a few headers and create issues for each of them with a proposed naming change? If people generally like how it's shaping up, I can add commits here implementing those changes. |
Just as an example, this is where things get tricky, because one of these sounds like a function that does something, and the other sounds like an object you act upon. If I only saw the symbol, I'd assume the first is a function and the second one is a struct. That's just a quirk of English, not a specific flaw here, but it's definitely something to watch out for. I think the only thing that is certain is that whoever makes the first pass at this should expect to get some percentage of negative feedback and run under the assumption they might be throwing it away. We're in that awful moment of API redesign where something seems like a good idea until you do the work and find out it isn't, but it has to be done to find out. It's happened to me twice today. :) It's possible we change all these and say "this is better" or it's possible we change them and say "SDL_CreateWindow was clear and friendly and SDL_WindowCreate feels clinical and I don't know why that is or why this should matter but it does" and then we just fix the SDL_RenderSetX/SDL_SetRenderY mistakes instead and call it a day. That being said: we are going to rename some things no matter what, so the infrastructure in this PR is good no matter what. |
Yup, totally agreed on all of this. I suggested @furious-programming because I think of all of us they’ll do the best job of suggesting helpful changes. |
@slime73: the general idea was to unify the naming of library elements by establishing one universal pattern. Making identifier searches easier, whether through IDE tools or searching for text in any text editor (like Vim, Notepad++ etc.), would be an added advantage.
The plural must be preserved, so the function should be called I have several "subsystems" in my game project that distinguish singular from plural. Some units (as Pascal source files) contain the functionality of one piece of object, others are a kind of managers of a collection of a given type of objects. For example:
The same for keyboard(s), mouse(s), stick(s) and window(s), and there will be many more in the future.
And here we have a problem, because In my current project (and any other) I don't have this type of problem because Pascal has a different naming convention than C. In Pascal languages, the data type is always preceded by the letter
In the C language, there is no such thing (and I would rather not suggest using it, because C programmers probably won't love it), so it remains to add something to the end of the
Pascal also uses
You're misinterpreting it a bit. The
Not for me, because it is known what subsystem the function comes from — What I use myself and what I originally proposed is to use the following pattern:
Explanation:
Postfixes should be constructed in such a way that they share initial words. Earlier I gave some such examples:
But if you don't want to, then you can ignore it. I use this myself because it makes it easier for me to filter IDs in the completion box. If you don't use completion box, or the completion box can filter in such a way that it splits the identifier into substrings and matches them ignoring the order of the substrings in the identifier, then the above will not be necessary. Now you need to consider whether you really want to use such a pattern, and if so, you need to check all edge cases (mainly data type names) to make sure that the C naming convention does not cause conflicts and introduce ambiguity. Perhaps the best solution would be to list all the identifiers that exist in the library, group them by subsystem, and then prepare equivalents that match the pattern. In this way, you can quickly check everything and confirm or refute the reasonableness of using the pattern. |
Okay, I'll take a first pass at this. My approach will be to use |
I'm going to go ahead and commit this infrastructure, and we can continue the discussion of how we actually want to change things in #6569 |
You can rename APIs using rename.py and all the code and documentation will be updated, and entries will be added to WhatsNew.txt and docs/README-migration.md.
e.g.
rename.py SDL_foo.h function SDL_CreateFoo SDL_FooCreate
SDL_oldnames.h is included in the SDL header, and if you define SDL_ENABLE_OLD_NAMES, will redefine the old API functions to call the new ones, and if not, will define them as a symbol letting you what the new API function is.