Craving For Language Expressiveness

Posted on November 07, 2007  |  

Posted in Development

2 comments

What I’ve been missing in C# for years is expressiveness. For example, which construct is more natural?

if (collection.Count == 0) ...
if (collection.IsEmpty) ...

Some steps were already taken in 2.0, which is the case with string:

if (s != null && s != "") ... // the 1.x way
if (!string.IsNullOrEmpty (s)) ... // the 2.0 way

In both cases the latter construct is much more readable and natural. It’s closer to the human language.

What I’m really looking forward to are extension methods in 3.5. Can’t wait to have a way to augment some of the blandness. I’m also wondering when we’ll start seeing commercial or open source “extension packages”. It’s enough to look at Python or Ruby, for example, to really start craving for expressiveness.

To me, it’s not even about verbosity. I don’t mind it because I hate guessing what’s behind cryptic names (again, as in Python or Ruby). A Fluent Control Container, for example, may look a bit verbose at first sight, but it’s way better than the rut of instantiating controls one by one and stuffing them with properties.

This just in

Whoa! I may have my wish granted sooner. End of this month? ScottGu for, uuummm, president!

2 comments

Kent Boogaart
on November 8, 2007

I kid you not, this is from an email I wrote earlier today to colleagues:

=========================
NOTE #6

if (str.Length == 0)

is better than

if (str == string.Empty)

And similarly:

if (string.IsNullOrEmpty(str))

is better than

if (str == null || str == string.Empty)

WHY?: string.Equals() executes significantly more instructions than accessing the Count property, even when the string is empty. A string.IsEmpty property would be nice, but that hasn't been added yet (but you could add one yourself in .NET 3.5 using extension methods).
=========================

Freaky!

I, too, am looking forward to extension methods. Hopefully the community will standardize on sets of extension methods for common stuff. Otherwise, one project will use str.IsEmpty, another str.IsBlank, another str.ThereAintNothingToSeeHere etcetera.

Alright, gotta go practice my ESP . . .


Milan Negovan
on November 8, 2007

LOL! Oh man, it's almost as if I was reading your mind.