Learning modern C# and modernizing your C# code turns out not to be easy. In a recent conversation that I had with Bahrudin Hrnjica, MVP for Developer Technologies, he used an interesting expression: “the inflation of C# features”. I laughed when I heard him saying that and I agreed. The expression “inflation of feature” precisely describes what happend to C# once it switched to the Roslyn compiler. The new infrastructure empowered the compiler team to ship new features quickly. The benefits of that fast paced development are obvious. C# evolves faster then ever, offering us to write code that is:
- more readable
- more robust
- less error-prone
- more performant
But this fast pace, or “feature inflation” as Bahrudin said, comes with a price. Out of my consulting and speaking experience I can say that developers have difficulties catching up with new language concepts and features. Konrad Kokosa in his recent post on Reddit expressed perfectly that difficulty with this image
A year ago in a similar Reddit thread I wrote:
C# evolves very quickly. Developers are not able to catch up with its development pace. It is hard to distinguish between genuinely useful features and syntactic sugar that can only cause headaches. And even if some feature is useful, it is not always clear in which cases not to go for it.
In the same thread I announced:
To combat this and to make sure that my future talks and workshops will not be in vain I’ve started working on a Visual Studio Extension called Sharpen. Its noble aim is to “intelligently introduce new C# features into your existing code base”. There is still a tremendous amount of work in order to fulfill its vision, but almost 8000 downloads on the VS Marketplace even in this early stage shows me that Sharpen has potential.
In the same thread I announced:
Sharpen is a result of a strong personal belief and a personal need.
I firmly believe that new C# features improve our code. They make it shorter, simpler, more expressive, more performant, and more readable. I believe developers should actively learn, understand and critically apply new C# features in their everyday work.
I ❤ C#. I love the fact that it evolves and that it evolves quickly. But I keep seeing a problem this fast-paced evolution causes. Developers have difficulties catching up with new language features and concepts.
For the past couple of years, I’ve been giving talks and workshops on new C# features. Year after year I keep noticing a disturbing fact. Developers come to a talk, hear about new features and months after report that they are still not using them in their everyday work. In my experience, the adoption of new C# features is rather slow. There are numerous reasons for that, for sure. One of them is a lack of a clear connection between a new feature and an existing code where that feature can be used. As many other C# evangelists, I tended to use simplified, artificial code samples in my workshops and talks. What I needed and wanted to have was a tool that will point out places in developers’ existing code where they can immediately start applying new C# features. I needed a tool that will help them learn C# quicker and more efficiently, by providing high-quality and easily accessible documentation.
That’s why I’ve started building Sharpen. To help developers efficiently learn and apply new C# features in their everyday coding. And to make my talks and workshops more tangible and more efficient.
In hindsight, everything I wrote back then still holds. In the meanwhile, Sharpen got more than 25 thousand downloads form the Visual Studio marketplace and a lot of encouraging feedback. It is still in an early stage, but it proves to be useful.
What Sharpen Does?
Sharpen uses static code analysis to identify places in existing code that will benefit from introducing new C# language features. It helps programmers to learn new C# features quicker and critically refactor their existing code to modern C#. This video, although being a bit outdated, demonstrates well basic usage of Sharpen:
Schritt 2: Buttom-Up Schätzung
In its latest version, Sharpen supports C# 8.0 features:
It also comes with built in C# documentation. When hoovering over the items in the Sharpen Results window, either a "Learn more..." or "What is new in C# <version>?" link will appear:
Sharpen helps you to quicker understand and grasp new C# features by meaningfully connecting them to your existing code base. It also helps you to develop a critical view on the features by distinguishing between the clear recommendations like "Replace switch statement ... with switch expression" and suggestions like "Consider replacing switch statement ... with switch expression". In the future suggestions will come with clear tips why to be cautios when applying a new language feature in that particular situation.
In the nearby future Sharpen will provide refactoring as well, allowing you to automatically refactor your code to modern C#. Refactoring is undoubtfully the most requested feature from the community as for example this discusion on GitHub shows. As a teaser, here is a mockup of that upcoming feature:
Giving Sharpen a Try
To give Sharpen a try on your own, simply install it from Visual Studio's Extensions and Updates dialog:
To learn more about Sharpen, its vision, and currently available features visit its official homepage: https://sharpen.rocks.
Last but not least, let me know what you think. Do you find Sharpen and the idea behind it useful? Are there any features that you will like to see coming soon?