Wish Debug - ignore code option.

RandomCoder

Well-Known Member
Licensed User
Longtime User
It's been a while since I last looked at the beginners guide and so I'm currently rereading it to catch up on some of the new features that have been added, that's when I came across this...
Ignoring warnings
You, as the developer, can choose to ignore any warning. Adding an "ignore" comment will remove
all the warnings for that specific line:
B4X:
Sub UnusedSub(a As Int) 'ignore
That's when I thought wouldn't it be nice to have a similar option of debug code.

I regularly add lots of lines such as...
B4X:
Log("Some useful information") 'DEBUG
Then when I'm done I search for the word DEBUG and delete all those lines. This means that all the once useful debug comments are gone for good in the finished app. It would be nice to leave them in but have the final released code ignore lines commented as DEBUG, this is my wish :)
I've seen code where the programmer sets debug code within conditional statements and then uses a flag to enable the debug statements as required, which is another way of doing it without needing to actually delete any debug lines of code. I suppose its all down to personal preference.

Kind regards,
RandomCoder
 

sorex

Expert
Licensed User
Longtime User
I'd rather go for conditional compilation.

in process globals use

dim debug as int=1 ' or 0 for release build
dim versiontype as string="pro"

then you can use

.if debug=1 then log ("your stuff")

notice the . before the if, this means it's conditional compilation

which should allow you to create a pro and limited version in 1 file too
so no messing up due to forgetting to update code parts in 2 different projects

.if versiontype<>"pro" then
showprolink()
showAds()
.endif


not sure if it already supports something simular tho
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Actually, here is what i do now.

This code is in a bass module:
debugModeSet is called one time when the program starts

'--- and then I use this
debugLog("Prints only if debugger is attatched")

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
     Public debugMode As Boolean
End Sub

Public Sub debugModeSet() As Boolean
  Dim r As Reflector
  debugMode = r.GetStaticField("anywheresoftware.b4a.BA", "debugMode")
  Return debugMode
End Sub

Public Sub debugLog(s As String)
    If debugMode Then Log(s)
End Sub
 

sorex

Expert
Licensed User
Longtime User
yes, that's an option just for debug output.

with the conditional compile you can output to the logfile or onto the screen,
sd card, smb share whatever.
if you disable it all that code is not being inserted at all.

same goes for pro features etc, if it's not needed it's not included either.
so you work in 1 app for both versions (free & pro/paid) and just compile with 1 variable that has a different value
 
Top