Phillip Trelford's Array

POKE 36879,255

5 Common C# Misconceptions

I’ve had the pleasure of working with and interviewing C# developers for over a decade now. However here’s 5 common misconceptions I continue to encounter.

1) Lists are implemented as linked lists

List<T> is actually implemented using an underlying array. The name is a little misleading with the earlier non-generic version having the less ambiguous name of ArrayList and in F# they are aliased to ResizeArray to avoid confusion. Needless to say the performance characteristics of operations on an array are somewhat different to those of a linked list.

2) var is dynamic

The var keyword is used to implicitly define a local variable that is strongly typed using type inference.There is actually no runtime difference from explicitly defining the type.

3) Dependency injection requires interfaces

Dependency injection has become common practice in C# code bases. Many seem to believe that you can only inject interfaces, often leading to interface proliferation, to the point that it can feel like you’re back in C++ land with header files. In fact most dependency injection environments support injection of abstract and even concrete classes.

4) Built-in serialization is efficient

The truth is the opposite, it is slow and verbose. If you’re looking for something efficient consider using Google Protocol Buffers with a library like protobuf-net or JSON from a third party like Service Stack.

5) C# is at the cutting edge of programming language design

C# is heavily based on the Java programming language, and has since made some incremental improvements like LINQ and more recently the async/await keywords. The reality is that all of the “new” features in C# are actually rather old, and progress has been pretty slow when compared to more recent curly brace languages like Scala and Nemerle.

Iterators introduced in C# in 2005 are merely coroutines, defined in 1963, they were first seen in the 1970s in Modula-2.

LINQ provides a library of higher order functions available as extension methods. Similar libraries have been available in functional programming languages like ML since the 70s, for example Select is equivalent to and Where is equivalent to List.filter.

Finally C#’s innovative new async feature actually first appeared in F# back in 2007.

Maybe the pace will pick up when Roslyn is finally delivered, but if you want to experience a wider range of features you might want to look at Clojure, F#, Nemerle, Scala or TypeScript.

Comments (4) -

  • Yan Cui

    8/29/2013 6:41:44 PM |

    Hey, great to hear you mention Nemerle, been wondering what's going on with the language. Haven't heard much about it for qutie some time, do you know if development on the language and IDE support is still ongoing?

    I spent some time with Go recently and found some interesting language features there too, such as how it deals with the expression problem using implicit interface implementation, and that it's compiled straight to machine code (which has its obvious drawbacks but in most cases you know the target platform you're deploying to).

  • Phil

    9/2/2013 11:12:46 PM |

    @Yan the Nermele team seems to have been acquired by JetBrains just over a year ago: and they've been relatively quiet since then. In the comments of the post they're promising an announcement at the JetBrains Day in Sweden on September 7th:

  • bad russian

    9/4/2013 10:22:47 PM |

    A common misconception is that you need to use some sort of a special environment (IoC framework) in order to be able to use dependency injection whereas in fact you dont need it and better stay away from them

  • Phil

    9/5/2013 1:41:42 AM |

    @bad russian I'd agree you don't *always* need an IoC framework for dependency injection. Lightweight approaches are discussed in Mark Seemann's Dependency Injection in .Net book
    That said I think there are contexts in where using an IoC framework is helpful.

Comments are closed