Provide an upgrade tool
Another approach is to not preserve backwards compatibility and instead provide tools to upgrade to the new version.
In the case of adding a couple of new keywords all the upgade tool would have to do is rename variables using the string that is now a reserved word.
Make it possible to identify the language dialect in use
This procedure is facilitated if you have something in the source code that can identify the version in use. Otherwise your tool may incorrectly treat the new keywords as variables.
Example
For example running foo1to2
on:
dialect(foolang,1)
var IamAKeyword : integer = 2;
It becomes:
dialect(foolang,2)
var IamNotAKeyword : integer = 2;
Upgrade tools can be a pain to write if the nature of the change is complex or the syntax is complex. You can make your life easier if you consider this issue upfront.
Consider context
As others have said you can somewhat avoid the issue if your new syntax is illegal in the previous language version/dialect.
Beware though that you are trading convenience of upgrade for clarity in the language.
An interesting example of this is C++.
Relatively early on for pure methods the = 0
syntax was introduced rather than a pure
keyword
class Foo
{
virtual void someMethod() = 0;
};
assignment of methods was not a legal syntax.
Much later when override and final were introduced they appear in the same place. So instead of:
class Foo
{
override void someMethod();
};
Where override
could seem to be the name of the return type say
You write:
class Foo
{
void someMethod() override;
};
There was a good link about this which I cannot find but https://stackoverflow.com/questions/32757571/why-do-the-c-language-designers-keep-re-using-keywords is very relevant.
Don't bother - just document
A final option is to not to anything other than document carefully the changes.
You leave the community deal with the issue.
They may well come up with upgrade tool on your behalf.
This risks alienating your user base, particularly if you do it too often.
But if your language is good and your community loyal you can get away with it.
This is really trading user friendliness for development resources.
There are quite a few languages that are guilty of this (despite having ample developement budget) and remain popular.
Deprecate
When evolving a language you could consider formally deprecating interfaces in one version before removing or changing them in a subsequent version. This slows down changes to your langauge but makes it easier for users to manage the transition.
This is particularly useful in 'enterprise' environments.
You can also consider having a syntactic or semantic way to mark something as deprecated in the language itself.
For example an attribute like [[deprecated]] in C++ can be used to indicate a function is to be retired.
This may or may not be harder to do for a keyword. In some languages keywords are a lot like functions or even exactly the same (e.g. TCL.
My personal preference is both:
- a clear way to the dialect/version used.
- an upgrade tool
static
in C. $\endgroup$