~ OBSERVATIONS ~
One common convention is the use of a debug flag. The workflow is more or less what you described as your personal workflow, but with an extra detail added.
The addition is that there will be some sort of global variable (I use the term loosely here to mean some value that can be set or changed at runtime) the value of which controls their activation.
The implementation conventions differ from one language and / or environment to the next, but the concepts are usually the same. One value, which represents debug mode, will enable (whether by way of a script of some sort or by any other means) not only assert statements, but also various other custom tools they have created to facilitate efficient debugging.
Some implementation details that Ive seen which stuck out to me include:
in C, an old convention was to set a DEBUG
macro that was included in the compile options for debug builds. I am not sure if this is still a convention, though, as C++ developers generally consider Macros bad.
Linux developers of command line tools usually include a --debug
option that serves the same purpose.
Various frameworks and standalone solutions now exist with the sole purpose of providing an interface to build flags at runtime.
~ SOLUTION ~
As for possible solutions, I believe that my workflow for debugging java may circumvent your issue.
My stance is that everyone working on a project will most likely have their own brand of debugging that works well for them. For example, you like to use assert
statements, and I never do. (I assume that you are talking about the keyword defined in the Java API and not the various testing frameworks' versions.)
What I am guessing you use assert
for, I do mostly using breakpoints and watchers pointed at any properties.
If everyone were to include their preferred helpers, this difference in debugging styles would yield some messy source code. One section would follow convention A , while the next section would be filled with B. C may or may not overlap both sections.
To avoid this without having to rewrite my reusable debug code, I will usually write it into a separate file. This may be a java class that extends a target class, or it may not be java at all. It depends on the situation.
The best way to describe this method would be to say:
Externalize your own debug code in the most efficient and convenient means for the situation at your disposal.
I usually keep my own debug script, but you could just as well share it with others. If the file is destined to stay small and will not be in the persisted source, neatness and style consistency do not matter as much.
One more solution would be to use a git workflow that allows you to "keep them without keeping them."
~ AFTERTHOUGHT ~
git rebase
allows you to add only certain commits from your branch to another. If you are careful with commits, ensuring that all of your debug logic is contained within their own commit(s), you would be able to merge only the "good" code into the team's working branch. However, this would be hard to maintain across merges, so it would be a no-go without something else added to automate synchronization.That said, I am sure that a GitHub search would provide many such options, so it may be worth looking into for some users.