[fpc-devel] Possible idea... "safe" subroutines/methods

Jonas Maebe jonas at freepascal.org
Sun May 5 12:02:16 CEST 2019


On 04/05/2019 18:06, J. Gareth Moreton wrote:
> I've noticed that my take on coding is somewhat different to others at 
> times.  I tend not to trust the compiler to make the most efficient code.

You generally shouldn't, and it indeed generally won't do it either. 
That's why even with the most advanced optimising compilers out there, 
some low-level and performance-critical routines like memcpy are still 
hand-coded in assembly on all platforms.

However, whenever the compiler can figure something out by itself 
without intervention from the programmer, no matter how small, there are 
several advantages:
1) It has a much lower risk of introducing bugs. The 
analysis/transformation can of course have bugs, but once it's stable, 
it should be good for a long time. Conversely, while a programmer may 
have a good idea of how a routine works when they have just written it, 
code and tends to change, and at some point the modifiers are probably 
going to get out of sync with what the code does.
2) It will be applied much wider. You don't need people to go through 
entire bodies of existing code to look which modifier could help where 
and add them. The compiler will just do everything automatically, even 
for old legacy code that no one has looked at in years (and want to keep 
it that way).
3) Programmers can focus more on function rather than performance. This 
generally leads to clearer and more maintainable code, which improves 
productivity.


Jonas



More information about the fpc-devel mailing list