Re: Lazy construction of parameters
- From: Torsten Kirschner <torsten.kirschner@xxxxxxxxxx>
- Date: Tue, 14 Mar 2006 14:59:46 +0100
On Tue, 14 Mar 2006 01:16:05 -0800, anders.johanse wrote:
Hi,
I would like to convert code such at this:
if (entry == null) {
log.warning("No entry found in storeEntries for
arcfilename: "
+ arcfileName);
}
...to this:
LogWarning.ifNull(entry, "No entry found in storeEntries for
arcfilename: " + arcFileName);
In effect consolidating common logging situations to one line of code.
Unfortunately, this means that the cost of constructing the message must
be paid always, and not just when the test fails. This has been raised
as a potential concern by some of my collaborators. In particular, some
like to construct lengthy messages in case of fails, involving DB
lookups etc.
Is there any easy way to deal with this, that retains the simple syntax
for the programmer?
Simpler than if() {} else {} which already solves your problem?
Your case seems to be rather special. Apparently, your test result does
not change the control flow of your program other than the need for
logging it.
Such cases are rarely the focal point of development in my experience.
I wouldn't invest too much time into creating an obscure logging
"framework" which side effect is testing.
You could look into the ternary operator. It appears to use short circuit
evaluation.
.
- References:
- Lazy construction of parameters
- From: anders . johansen
- Lazy construction of parameters
- Prev by Date: Re: Lazy construction of parameters
- Next by Date: Re: Lazy construction of parameters
- Previous by thread: Re: Lazy construction of parameters
- Next by thread: Re: Lazy construction of parameters
- Index(es):
Relevant Pages
|