Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
philotas
Roku Guru

Remove print statements for production?

How do you handle the print statement when publishing a channel?
Do you remove them all or leave them in the code?

I was wondering if it could improve the performance on slower device, if it does not have to handle too many print statements.

What do you do?
0 Kudos
1 REPLY 1
EnTerr
Roku Guru

Re: Remove print statements for production?

Would that improve your performance? I don't know how chatty your app is but in general i don't expect much of performance hit. I just don't let the code print too much 🙂

Seriously, i have worked on projects where the console log has remained bloody mess of random prints like "1", "2", "aaaaa" etc which were put to troubleshoot something but never removed. It shouldn't be like that, console should remain mostly readable as of what's going on and not too chatty.

OTOH, do not stop any and all diagnostics - while you have no access to them in production, RokuCo collects these and in special circumstances may make parts of them available to troubleshoot a difficult problem. So log top level events and exceptions for sure.

If so inclined, you can get fancy by writing your own logging function to use instead of print - and make that more or less chatty depending if the app is side-loaded or public-ed - by checking a global variable flag (make that a field in the global Noid if doing RSG). And that flag can be auto-set on app start based on roAppInfo.isDev()

PS. e.g. (typing impromptu here)

sub log(items, must_print = false)
 if must_print or m.is_dev:
   if type(items) <> "roArray":
     print items ' single value'
   else:
     for each item in items:
       print item;
     next
     print
   end if
 end if
end sub

then use as

log("entering final stage")
log(["pi = ", 4*atn(1)])
log("FATAL: blah-de blah error", true): STOP
0 Kudos