This is probably answered somewhere, but I haven’t found it. I’m sure it is good practice to remove or comment out print statements in production code uploaded to the app stores, but is it necessary? In other words, what harm does it cause?
-Jerry
This is probably answered somewhere, but I haven’t found it. I’m sure it is good practice to remove or comment out print statements in production code uploaded to the app stores, but is it necessary? In other words, what harm does it cause?
-Jerry
I would say yes remove them when possible, as most string functions are generally quite slow.
To make it easier (and someone may correct me here if this is actually a bad thing to do) I simply override the print function before I create my release build.
--main.lua --before any print statements are called function print(str) end
I’d still advise removing print statements when you no longer need them, but doing this means that if you miss any, print() will basically be a function that does nothing.
If you put it in now, and comment it out, then you just need to uncomment it when you build the release version.
AlanPlantPot is right, you can simply over-ride print if you want to keep you debug code in place.
I usually put something like this towards the top of main.lua:
\_G.print = function() end
This will let you keep you print code in place, but kill it all in one fell swoop.
This still costs the function call, but it doesn’t do any work so you should be fine.
Note: The other benefit to this is that it reduces the chance that you might accidentally break your code while deleting/commenting multiple lines. All it takes is a little fumble-fingered coding or a mistake with global replace tools and whamo, broken game/app.
That sounds great! I recently had the same thought and ran Search / Replace on “print” replacing all occurrences with “–print”. Thats another way to achieve the same goal if one chooses to go that way.
Thanks for the great tip re using an overridden print() I’ll definitely use that!
But it sounds like the only real harm in just leaving them in is possible speed problems. Right? I was concerned that the actual output would be logged somewhere on the device and cause problems.
I would say yes remove them when possible, as most string functions are generally quite slow.
To make it easier (and someone may correct me here if this is actually a bad thing to do) I simply override the print function before I create my release build.
--main.lua --before any print statements are called function print(str) end
I’d still advise removing print statements when you no longer need them, but doing this means that if you miss any, print() will basically be a function that does nothing.
If you put it in now, and comment it out, then you just need to uncomment it when you build the release version.
AlanPlantPot is right, you can simply over-ride print if you want to keep you debug code in place.
I usually put something like this towards the top of main.lua:
\_G.print = function() end
This will let you keep you print code in place, but kill it all in one fell swoop.
This still costs the function call, but it doesn’t do any work so you should be fine.
Note: The other benefit to this is that it reduces the chance that you might accidentally break your code while deleting/commenting multiple lines. All it takes is a little fumble-fingered coding or a mistake with global replace tools and whamo, broken game/app.
That sounds great! I recently had the same thought and ran Search / Replace on “print” replacing all occurrences with “–print”. Thats another way to achieve the same goal if one chooses to go that way.
Thanks for the great tip re using an overridden print() I’ll definitely use that!
But it sounds like the only real harm in just leaving them in is possible speed problems. Right? I was concerned that the actual output would be logged somewhere on the device and cause problems.