Q&A

Q&A with Jim Wooley: C# Past, Present, and Beyond

The Microsoft MVP and LINQ expert discusses the best current C# features, how developers can stay on top of changes, and what they often get wrong about Microsoft's flagship coding language.

November is shaping up to be a busy month for developers. Along with Visual Studio 2022 and .NET 6, another landmark release of a major Microsoft product is expected to debut next month: version 10 of C#.

When it comes to what's included in the new C# release and how we got here, Microsoft MVP and LINQ expert Jim Wooley has the answers. At the upcoming Live! 360 conference taking place on Nov. 15-19 in Orlando, Fla., Wooley will host a session called "C# Past, Present, and Beyond" that will cover a lot of the most important C# features, especially those in more recent versions (think C# 6 and later), how you can start using them today, and what to expect when C# 10 comes around.

Ahead of his session next month, Wooley answered a couple of questions about the best current C# features, how developers can stay on top of changes, and what they often get wrong about Microsoft's flagship coding language.

VisualStudioMagazine: There've been a lot of changes to C# in recent years. What's been the most exciting new development/change/feature?
Wooley: In its first decade, we saw several language enhancements in areas such as LINQ, Lambdas, Generics and Async which fundamentally changed the way we write C#. In the next decade, since the compiler was re-written via Roslyn, we've seen a ballooning of language features, including ones we use every day like String concatenation, null-terminating operators, ref locals and returns, and pattern matching. Some features improve performance of the framework APIs, like Span<T>, range operators and native ints. And then there are features to make getting started with simple projects easier, including top-level statements, static and global usings, and file-scoped namespace declarations. There are even some features that some might consider controversial, including tuples, nullable reference types and default interface implementations.

While most of these changes won't fundamentally change how we think about how we approach code like the functional changes from LINQ and Lambdas, many can reduce and simplify the code you have to write as a C# developer.

"People think [C# is] just a different syntax from JavaScript, Java, C, etc. and don't take the time to understand differences in memory models, object pointers. Oftentimes, they produce systems which have performance issues, or flat-out don't work right because they didn't understand what their code was doing."

Jim Wooley, Solution Architect, Slalom Consulting

Perhaps the most exciting feature isn't specifically a language feature, but related to changes enabled with the Roslyn compiler, and that is syntax generators that came with C# 9. These generators enable enhanced metaprogramming capabilities to automate repetitive coding operations that typically required IL rewriting, aspect-oriented strategies, reflection, etc. With the generators, you can create code that writes code once and greatly reduce the amount of plumbing code you have to manually type over and over, while still retaining the performance benefits of not having to use things like runtime reflection, for example.

Is there an underrated, often-overlooked C# feature that you wish more people knew about?
As newer versions of C# have come out, the patterns that we use to code have subtlely changed. To make it easier to discover these newer patterns, the compiler team has also created a number of Roslyn-based analyzers and code fixes to provide recommendations on how to discover the new features. Paying attention to the squiggles and suggestions (ellipsis dots) under older code patterns, developers can learn about some of these newer language features like string interpolation, pattern matching and out variables, just to name a few.

Many developers ignore these suggestions, but they can often not only reduce the code that developers have to write, but in some cases even highlight potential bugs in the code base that the compiler may otherwise overlook. In many cases, just learning a simple keyboard shortcut in Visual Studio (Ctrl-.) when focus is placed on a line that can be optimized can start teaching developers how to improve their code.

In the face of constant updates, what's the best way to keep up your C# skills and stay on top of changes?
Gone are the days where we just go out to a bookstore to pick up a book teaching us the latest features. Technology changes too frequently and by the time a new book is produced, a new version of the technology often has already shipped and made parts of that book obsolete. For example, with C# over the last five years, we've seen C# 7.0, 7.1, 7.2, 7.3, 8.0, 9.0 and -- this fall -- 10.0. If you want to stay up-to-date on the status of the various language features, the best bet is to monitor the GitHub repository for the language features along with the language features pages of the Microsoft docs site.

Of course, the best way to learn about new features is to attend conferences like Live! 360 and other community events that discuss things that you aren't familiar with to get an overview of what's available and why you should consider using it. Don't expect to learn everything there is to know about the topic in an hour, but just knowing that it exists will help you out when the time comes that you need to use a new technology. Then you can learn the best way I know -- by trying to use the technology and working through the challenges you encounter.

Also, if you're using a modern IDE, pay attention to the recommendations that it gives you on ways to improve your code. You can often learn a lot of the new ways of doing things just by trying out some of the suggestions that it gives.

How has the C# community evolved, especially in relation to other programming languages? Where do you see it progressing?
When C# and .NET were open-sourced, C# developers no longer needed to rely on reflection and decompiling tools to understand how things work and we can see the implementation and details for ourselves. This means that we no longer have to rely on support desk calls or Microsoft forums to figure out how to use framework elements. Now we can look at the actual source of not only the libraries that we use, but also the compiler itself.

Inside the Session

What: C# Past, Present, and Beyond

When: Nov. 17, 2 p.m. - 3:15 p.m.

Who: Jim Wooley, Solution Architect, Slalom Consulting

Why: "With the modern open source C# Compiler, we've seen so many new language features, it's hard to keep up."

Find out more about Live! 360, taking place Nov. 15-19 in Orlando, Fla.

As a result, the language developers are no longer working in a vacuum, but are actively monitoring and discussing potential new language features directly with you the customer on GitHub for anyone that wants to participate (and potentially contribute back code). The docs for .NET and C# are open-sourced, as well, so if you find a gap or bug, you're welcome to create an issue and possibly contribute your own pull request to help others.

In addition to the official C# team channels, there are also other online resources like blogs, Twitter and Stack Overflow. While this enables the community to have greater access to information, it also poses a challenge of keeping up-to-date, or qualifying the version of C#/.NET that the item applies to. Sometimes finding the answers to your problems is more challenging because the underlying technology stack may have changed (.NET Framework to .NET Core to .NET 5/6, for example). Naturally, this challenge is not isolated to C#, but can be seen in many other languages and platforms. Consider, for example, the challenges of trying to find resources specific to Angular when that framework completely changed between the 1.x and 2+ versions.

As time goes on, don't expect the number and quality of online resources to decline, but be aware to check the date of the original post and factor that into your decision as to whether it solves your problem or not.

What's the biggest mistake or misconception developers have about C#?
People think it's just a different syntax from JavaScript, Java, C, etc. and don't take the time to understand differences in memory models, object pointers. Oftentimes, they produce systems which have performance issues, or flat-out don't work right because they didn't understand what their code was doing. While you don't have to know the internals of everything you use, you shouldn't just find a Stack Overflow answer for your question and pick the first answer assuming it will solve your problems without understanding the solution and why it is better than other alternatives.

About the Author

Gladys Rama (@GladysRama3) is the editorial director of Converge360.

comments powered by Disqus

Featured

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

  • TypeScript Tops New JetBrains 'Language Promise Index'

    In its latest annual developer ecosystem report, JetBrains introduced a new "Language Promise Index" topped by Microsoft's TypeScript programming language.

Subscribe on YouTube