Sunday, November 27, 2005

What Are the Benefits of Generics?

Generics offer significant benefits, including productivity, type safety and performance.

What is special about generic types is that you code them once, yet you can use them with different parameters. Doing so has significant benefits—you reuse your development and testing efforts, without compromising type safety and performance, and without bloating your code.

With the object-based solutions, mismatch in type will still get complied, but yield an error at runtime. With generics, such code would never get compiled.

Various benchmarks have shown that in intense calling patterns, generics yield on average 200 percent performance improvement when using value types, and some 100 percent performance improvement when using reference types. However, performance is not the main benefit of generics. In most real-life applications, bottle necks such as I/O will mask out any performance benefit from generics. The most significant benefit of generics is type-safety.

Adopted from Generics FAQ: Fundamentals by Juval Lowy.

0 Comments:

Post a Comment

<< Home