[fpc-pascal] Checking the validity of Format and friends at compile-time

Santiago A. svaa at ciberpiula.net
Thu Oct 6 09:43:40 CEST 2016

El 05/10/2016 a las 19:47, Michalis Kamburelis escribió:
> 2016-10-05 9:00 GMT+02:00 Maciej Izak <hnb.code at gmail.com>:
>> 2016-10-05 4:32 GMT+02:00 Michalis Kamburelis <michalis.kambi at gmail.com>:
>>> For example, the call
>>>   Format('%s', [123])
>> I have a small hint (instead of answer). We have in mORMot / NewPascal in
>> SynCommons module nice function which works perfect in most of cases:
>> FormatUTF8('%', [123], []); // same string '%' works for both: integer and
>> string values
>> FormatUTF8('%', ['123'], []);
> That's a cool improvement. No need to write the type, so one less
> thing that can go wrong:) I seldom use non-standard formats anyway
> (like %g instead of %f for floats).

I don't agree. You are asking for a compile time check, but now you
accept skipping run time type check doing a automatic type conversion.
Things can go as wrong as with classic format but, without runtime error
or exception, hunting bugs is more difficult.  I support your first
idea: Compile time check.

I haven't understand very well whether Sven Barth's reluctance is a
matter of taste or whether there are serious technical reasons. If there
are not severe design drawbacks, I would go for it. I love compile time
checks. The more, the better.


Santiago A.

More information about the fpc-pascal mailing list