How to handle deprecated sdl2 functionality?
Free-Pascal-meets-SDL-Website opened this issue · 3 comments
This issue is about a problem I ran into recently and saw also in a pull request recently.
Simple example:
Lets say there are some defines which are translated.
const
SDL_DEFINE1 = 0;
SDL_DEFINE2 = 1;
SDL_DEFINE3 = 2;
In a newer version of the header file one of the defines is missing. Let's say the second define is missing. So the inc-file would be updated to:
const
SDL_DEFINE1 = 0;
SDL_DEFINE3 = 2;
However, this raises (at least) two problems.
- The define is (obviously) missing if someone is using an older version of sdl2 instead of the particualrly one to which the inc-file got updated.
- The second concern is raised particularly because we are not always updating consistently to one particular version AND not all files at the same time: Let's say some files are not updated yet (very old version), some are updated (not the most recent version), some are updated to the latest version of sdl2. If now in the newest version some defines are deleted because they are gone, this may conflict with functions or expectations which are present in very old or older versions as they need or at least expect these defines/functions to be present.
The example above can be extended to structs/records where in newer version fields are missing or change their variable type.
Solution:
Actually, I don't know a simple solution yet. except to have some conditional compilation. Something like:
const
SDL_DEFINE1 = 0;
{$IFDEF DEPRECATED_IN_NEWER_SDL2} SDL_DEFINE2 = 1; {$ENDIF}
SDL_DEFINE3 = 2;
What are better solutions or should this be adressed anyway?
Best regards
Matthias
Three solutions come to my mind:
- Keep everything as updated as possible. If SDL2 removes something, we remove it as well. Leave it to users to upgrade or downgrade the Pascal units as needed.
- Keep old stuff around and just mark it as
deprecated. - As you proposed - keep old stuff around, but guarded by some
IFDEFblock. Add a section to the README to tell users what's going on and how to enable deprecated identifiers.
What option do you prefer for our project?
I made further research on this. I think it is safe to remove the conditional.
See https://stackoverflow.com/questions/27296111/is-possible-to-mark-an-entire-const-block-as-deprecated for reference. There are variables shown to be deprecated in an identical way for Delphi.
Originally posted by @Free-Pascal-meets-SDL-Website in #52 (comment)