Editor: Blend out debug statements

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PeWa
User
User
Posts: 23
Joined: Fri Sep 06, 2019 8:25 pm

Editor: Blend out debug statements

Post by PeWa »

The Purebasic Debugger toggle is a very nice feature: we can easily control the use of debug-statements in the sourcecode and can switch them on an off, so that the compiler ignores debug if we wish it.
However, if i found with debug all failures and errors, I start deleting all or most of the debug statements, the sourcecode is more readable and more structured.
That is in most cases no problem - but sometimes we need the debugs again.
Make it not sense to implement a debug blend out function in the editor, so we can switch on and off debugs in the sourcecode ?
Then we could leave debugs in the sourcecode and must not delete them and can use them again.
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: Editor: Blend out debug statements

Post by BarryG »

Debug commands are not compiled into the final exe for distribution to users, so leaving them in is of no concern (they're like comments in that sense). But if having them annoys your readability, that's a different issue.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Editor: Blend out debug statements

Post by spikey »

There are a few things you might be able to take advantage of:
1) The IDE supports custom folding. If you surround sections of debug code with ;{ and ;} they will get fold up marks in the margin the same way that 'Procedure…EndProcedure' do:

Code: Select all

;{
Debug "Something here..."
;}
If you define this as a template, you don't even have to type the extra text.
If you're already using ;{ for your own purposes you can define an extra folder via Menu → Preferences → Editor → Folding.

2) Use DebugLevel. The Debug command has an optional 'DebugLevel' parameter. The specified message content will only be displayed if the current DebugLevel is equal or greater than this parameter value:

Code: Select all

DebugLevel 1
Debug "DebugLevel 1"
Debug "----------------"
;{
Debug "This is a level 1 message.", 1
Debug "This is a level 2 message.", 2
Debug "This is a level 3 message.", 3
Debug "This is a level 4 message.", 4
;}

DebugLevel 2
Debug #Empty$
Debug "DebugLevel 2"
Debug "----------------"
;{
Debug "This is a level 1 message.", 1
Debug "This is a level 2 message.", 2
Debug "This is a level 3 message.", 3
Debug "This is a level 4 message.", 4
;}

DebugLevel 3
Debug #Empty$
Debug "DebugLevel 3"
Debug "----------------"
;{
Debug "This is a level 1 message.", 1
Debug "This is a level 2 message.", 2
Debug "This is a level 3 message.", 3
Debug "This is a level 4 message.", 4
;}
3) If this still doesn't provide a suitable level of granularity you can use custom constants for different build configurations with 'CompilerIf…CompilerEndIf' etc:

Code: Select all

CompilerIf #CustomConstant = 5
  Debug "Something detailed you only need when something really odd is happening."
CompilerEndIf
You can define custom constants via the Compiler Options dialog, and importantly, each Build Target in a Project file can define its own custom constants so you can have multiple predetermined configurations set up to make the task quicker when recompiling.

4) Use 'Macro…EndMacro' for bigger debug output sections. These can be tucked away out of sight in a different source file too. For example I've this one in my toolkit:

Code: Select all

Macro APIDebug(Message)
  CompilerIf #PB_Compiler_Debugger
    Debug Message
  CompilerElse
    OutputDebugString_(Message)
  CompilerEndIf
EndMacro
It sends messages to the Debug output when running under the IDE or to the OS debug output instead when running on a deployed machine.
Post Reply