The Perils of Format
Format is good. Format is bad.
The good is that you can create very nice translatable strings which can deal with reordered parameters, and that perform fairly well.
if Language = Yoda
then fmt := ‘%1:s apples, %0:d you took.’
else fmt := ‘you took %0:d %1:s apples.’; // English
Writeln(Format(fmt, [5, ‘green’]));
So, what is the pain? All the checks are done at run time.
Let me repeat that: … at run time.
Once again, during a hotfix, I blew it on the parameter type, mistakenly passing a Double into the position where an Integer was expected.
I really wish that there was compiler magic that could validate the type and position of the Format parameters at compile time. Until there is, I will be careful to send all parameters as strings, and convert to string in the Format argument list – at least for the quick fixes.
You must be logged in to post a comment.