dhylands wrote: ↑
Thu Nov 29, 2018 9:39 pm
The general tendency is to make things STATIC unless they need to be shared. From a maintenance standpoint a function that is declared STATIC can be changed arbitrarily and you only need to look within the same source file to find all of the "users" of that function.
If a function is made public, then if you want to change the API of the function you need to find all of its uses in the rest of the codebase and fix those as well.
I think there is absolutely no disagreement between us; I fully understand and appreciate your points. All I wanted to say is that I have already run into difficulties with this restriction. For now, I solved the problem by copying small chunks of code, but I believe, this can't work in the long run.
For one thing, this is also a maintenance issue: if the original code (meaning the one that is part of the micropython code base) changes/improves, you have to copy that chunk, or at least, think about, whether it is worth copying. I would even argue that this case might even be worse, because the maintainer of mymodule.c would always have to check for changes in the code base, if they don't want to miss out on the improvements. On the other hand, if the API of the original is made public, and it changes, then this fact will be immediately obvious to everyone, because mymodule.c won't compile anymore.
Second, every time you copy code, you are probably going to make the firmware larger. I don't think that the compiler/linker is smart enough to notice that a static function in objarray.c is the very same as a static function in mymodule.c. I believe, this argument is especially important in the case of a microcontroller, where resources are sparse.
The question really is, whether the benefits of making at least a subset of the functions public outweigh the drawbacks. I wrote a module that renders fonts in 16-bit colours as described in https://github.com/peterhinch/micropyth ... /writer.py
. @peterhinch reported render times in the order of 5 ms for 12-pixel high fonts. I can manage it under 100 us with a font height of 20 pixels. That is a gain of at least 50. This sounds convincing to me. I will try to release the code over the weekend, so you can see it for yourself.