10.5. Balancing Readability with Expressiveness

Some view the syntactic constructs introduced by generics as a welcome addition to the language. This crowd looks at the type arguments that accompany a generic declaration and sees them as providing a very precise, undeniably clear definition of each data type. For them, generics eliminate any confusion that might have been associated with using non-generic APIs.

Meanwhile, another population views generics as imposing on the readability of their code. They see type parameters and constraints and new keywords as muddying the image of what was an otherwise perfectly clean, uncluttered block of code. Many in this group see generics as undermining the general usability and maintainability of their code.

The challenge here is striking a balance between these two groups. If everyone can agree on the general value of generics, the only issue that remains is how to introduce them without creating code that is so confusing that it requires a decoder ring to decipher the text. The goal of this section is to offer up some guidelines that can establish some fundamental boundaries that give developers the freedom to leverage generics without leaving behind a trail of unreadable code.

10.5.1. Item 6: Use Meaningful, Consistent Type Parameter Names

During the beta cycle for Visual Studio 2005, early adopters focused a significant portion of venom and debate on naming conventions for type parameters. Because type parameters are littered throughout ...

Get Professional .NET 2.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.