Re: Style: Are these two blocks of code equivalent?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




> >
> > String howMany = new String(count.ToString() + " message" + ( (count >
1)
> > ? "s" : "' );
> >
> > Elegant, no? As opposed to, for example:
> >
>
> Not really, there is way too much in a single line in that example. Unless
> you are *really* paying attention it isn't hard to miss that you are using
a
> condition. The operator can be an aide to clarity when used properly, but
I
> do not think it is a good thing nested within complex expressions or when
> the expressions within it are too complex.

Well, everyone has their own tolerance for complexity.

One thing I personally dislike is code that runs off the right side of the
editing window. I tend to break up code into multi-line blocks in that
situation just so that I can see it all.

When I see one of my peeps doing a good job of using something like the
conditional operator, I take it as a sign that they're comfortable with more
than just the basics of the language. On the other hand, if I catch one of
them writing complex expressions, or even worse nesting them within a single
statement, for example, I take the opportunity to do a little education on
code readability and maintainability.

In Einstein's words: "Make things as simple as possible...but no simpler."

Tom Dacon
Dacon Software Consulting


.