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.
begin newbuiltdefderefs:=nil; builtdefderefs:=nil; builtsymderefs:=nil; setlength(builtdefderefs,deflist.count); setlength(newbuiltdefderefs,deflist.count); setlength(builtsymderefs,symlist.count); > 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 > possible. 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 [1]. 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. [1] https://media.ccc.de/v/35c3-9788-memsad > 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. Strongly agree. 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. -- Regards, Martok _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal