New series: Refactoring C# 1.0 code to C# 3.0
I really like Scott Hanselmann’s idea to write an indefinite series of posts about reading code to be a better developer. I’m going to copy his idea, and write a series of my own.
Since its first version, C# has evolved from being a Java clone to something much more dynamic. I’ve noticed that developers often find themselves stuck long projects, and its sometimes hard to keep up with all the changes. I know a lot of developers who are still using .Net 1.1 because the project they are working on forces them too. For them, C# is still very much like Java.
So for all those who want to know what has changed since the first version, I’ve decided to make a new series of posts called “Refactoring from C# 1.0 to C# 3.0″. I will show through examples how you can make your code easier to understand and maintain by using the new features in C#. I’m not necessarily going to do it in historical order – I won’t show any preference for C# 2.0 Generics over C# 3.0 Extension Methods, for example. And C# 2.0 anonymous methods will take second place to C# 3.0 lambda expressions, which generally replaces them. I’m going to try to show how things have changed, and when you should or should not use the new features.
Some of the things I’ll cover are:
- Anonymous types
- Anonymous methods and lambda expressions
- Extension Methods
- Yield statements and iterators
- Generics
- List comprehensions (ala LINQ)
- Mixins
- Partial types
- Type and Array inference
- Property visibility
- Automatic properties
- Static classes
- The Global namespace
- Object, Collection and Dictionary initializers
I’ll try to treat each one as a refactoring opportunity, and not as a “must” or “must-not”. The idea is to write more maintainable code using the new features, not just go along with the trends.
Note: I’m not going to treat the .Net base library at all. Just the C# language.
This is my personal blog, where I express my thoughts and thinking about programming and software development.