[fpc-pascal] SetLength warnings - request
listbox at martoks-place.de
Tue Jan 1 04:17:36 CET 2019
First, I agree clearing dynarrays with :=nil is somewhat cleaner than
Setlength(0). (Small issue: I only learned that this is even a thing from the
compiler implementation of it when I was debugging #0031215! From the reactions
of other Delphi developers I showed it to, it is _very_ uncommon.) Initializing
to any number other than 0 can only be done with Setlength, and I'm going to be
honest, this bit from compiler/symtable.pas looks just ridiculous.
> I'm 100% serious about the above. Code should be explicit, not implicit.
> It's up to the compiler to remove unnecessary code based on what it
> knows is implicitly guaranteed. The programmer should only have to focus
> on the algorithms and on making their code as explicit/clear as
The question then is: what is explicit? How does one tell apart "filler" code
the compiler is supposed to remove and "relevant" code the compiler is not
supposed to remove? Why even write code we hope will not be in the final binary?
Incidentally, this was the topic of a talk at this (well, last!) year's CCC .
Compilers doing overly clever optimisation are sometimes a real-world *problem*,
not a solution. The compiler should at least tell the programmer about security
relevant optimizations and offer ways to fix it if necessary.
> In that sense, the optimisation capabilities of a compiler are quite
> important for the quality of the code that people write, because a
> better optimiser means that (some) people are less inclined to mangle
> their code and "tune" it to implementation details in order to coax the
> compiler into generating the code they want to see.
Before I had to bury the project because of the whole enum portability fiasco, I
rewrote large parts of the DEC routines in pure pascal, and it turned out that
while being more readable and more portable, it was also *faster*, because FPC
generates better instructions these days.
More information about the fpc-pascal