June 2010 - Posts

Another distraction: I’m now a proud owner of a HTC Desire
Thu, Jun 24 2010 21:51

Yep, my old HTC Touch Pro died and I had to pick a replacement. So, I guess I did the right thing and went with Android and HTC Desire…hum…does this mean I’ll be writing Java? Who knows :)

by luisabreu | 2 comment(s)
Filed under:
Extension method madness
Wed, Jun 23 2010 11:38

Even though I haven’t been as active as I wished, I have still managed to get some time to read several interesting blog posts lately. Unfortunately, it seems like two guys that I have a lot of respect for (though I haven’t had the pleasure of meeting them in person) have gone into the “dark side”. I’m referring to Phil Haack and Oren Eini (aka Ayende). The problem: using an extension method for checking for an empty enumeration.

It all started with Phil’s post, where he presented an extension method for testing for an empty IEnumerable. Here’s the code he ended up with:

public static bool IsNullOrEmpty<T>(this IEnumerable<T> items) {
    return items == null || !items.Any();
}

Phil really explains why using the Any is a good option (especially when compared to Count) and I do agree with that part. Now, the problem here is that Ayende picked it up and improved it so that you don’t end up “loosing” items when you can’t go several times over an IEnumerable. Unfortunately, both of them missed the null check. Don’t understand what I mean? In that case, do take some time and look really carefully at Phil’s initial code. Do you see anything wrong? No? Let me ask you a question: what’s the expected result of the following code:

IEnumerable<Int32> nullCll = null;
var isEmpty = nullCll.IsNullOrEmpty();

In my opinion, it should throw a null reference exception. But that won’t happen in this case. Don’t you find that weird? I do and I think extension methods should behave the same way instance methods. And that really means null exceptions shouldn’t be “replaced” with Boolean values.

Btw, and that’s just my opinion, the helper method should really be a simple helper method (ie, not an extension method). Just because we have extension methods, it doesn’t meant they’re the solution to all the extension problems we have…

by luisabreu | 6 comment(s)
Filed under:
The “Onde está” –> “Pôr” table
Wed, Jun 16 2010 11:50

[If you’re not Portuguese, it’s safe to skip this post. If you are, please read it and watch the TV show I’ve mentioned]

It’s been a long time since I’ve written something here. In fact, it seems like I haven’t written anything useful in the last month. There’s a good reason for this: I’m working on my next PT book (Silverlight). It’s still work in progress, but things are going rather well and I expect to have it ready for reviewing in one month (or so).

Anyway, I was watching Plano Inclinado and I simply couldn’t resist showing you the “Onde está”->”Pôr” table presented by Prof Ernâni Lopes.

tabelapor

That’s what we need to do to become more competitive and improve our economy. Yes, it’s true, it really depends on how we act and face every day challenges. If you have time and didn’t see it yet, please watch the show online.

by luisabreu | with no comments
Filed under:

Search

This Blog

Tags

Community

Archives

Syndication

Email Notifications

News




  • View Luis Abreu's profile on LinkedIn


    Follow me at Twitter

    My books

    Silverlight 4.0: Curso Completo

    ASP.NET 4.0: Curso Completo

    Portuguese LINQ book cover

    Portuguese ASP.NET 3.5 book cover

    Portuguese ASP.NET AJAX book cover

    Portuguese ASP.NET AJAX book cover