HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMajor

Are these if-statements too fancy?

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
thesearestatementsfancytoo

Problem

I just rewrote this:

if (budgetRemaining != 0 || totalOpenInvoices != 0)
{
}


Like this:

if (new[] { budgetRemaining, totalOpenInvoices }.Any(c => c != 0))
{
}


If I had seen that before I ramped up on Linq, it would have confused me. Now that I've been learning functional programming and using Linq, it seems natural, but is it sacrificing simplicity?

Solution

Seems to be swatting a fly with a Buick to me. The first form seems pretty concise and the variable names are quite descriptive. The second form creates a new object (the array) which will eventually have to be GC'd and introduces a new lambda variable, c which doesn't seem descriptive any more.

Context

StackExchange Code Review Q#7087, answer score: 48

Revisions (0)

No revisions yet.