Berkeley wrote: ↑Sep 28, 2024 11:36
Suggestion: "debug.bi" should become part of FreeBASIC, and a bit more "hardcoded": so you shouldn't need to write explicitely #include "debug.bi" to use e.g. DEBUGOUT. And further, its functions will only work in a debug build, automatically stripped off in a release build. The exact behaviour should be not defined - DEBUGOUT might also write in a "debug.log" file or put out over STD_ERR, so you could better integrate it in an IDE. For error logs and handling there should be an own library, although it will be almost identically in a debug build.
The debug functions are only ment for debugging resp. testing by the programmer. In principle they are removed anyway before making a code release. But it would be handy if you don't have to add/remove the "#include ONCE "debug.bi"" line again and again...
All but one thing you just said can already be emulated without much effort. It does not need to "become a part of FreeBASIC". The language is plenty powerful to allow you to basically do this on any library you write. Allow me to explain:
1) The user decides whether to build a debug version or release version by using the -g compiler flag
2) The library can know, at compile time, whether or not the program was compiled with that -g flag by checking for the __FB_DEBUG__ intrinsic. See:
https://www.freebasic.net/wiki/KeyPgDdfbdebug
3) The library (your code) conditionally compiles actual results based on the intrinsic at the sub/function level. Functions need to return some default so pick something (0 is probably best). Do something like this for all of your functions in your library:
Code: Select all
FUNCTION DEBUGSTOPTIME() AS DOUBLE
#if __FB_DEBUG__ <> 0
DIM retval AS DOUBLE
retval=TIMER-debugstoptimetimer
debugstoptimetimer=TIMER
RETURN retval
#else
RETURN 0.0d 'Default return value is necessary only if it's a function.
#endif
END FUNCTION
4) You also wrap any module level code in the same #if guard. Your code doesn't have any of that (yet), but something to keep in mind.
5) The compiler (probably) does "dead code elimination", therefore eliminating overhead on your functions when compiling a release version.
6) You simply toggle your debugging on/off exactly the way you described: Works in a debug build, automatically stripped off in a release build by compiling with -g or not.
The only thing that I would take issue with is the idea that you shouldn't need #include "debug.bi". Adding it directly to the language is bloat. Bloat needs to earn its keep. This level of tooling would not earn its keep. Surely one line per module isn't that much to have a more structured, readable source code?