Telerik blogs

In a field as dynamic as development, staying up to date on the latest best practices and trends can take effort. But keeping pace is easier than a massive overhaul later.

In my programming life, I’ve changed paradigms many times. From programming for MS-DOS apps and switching to using events in Visual Basic 6 to object-oriented programming in C# and the web and other frameworks like React and Angular.

From all this experience, I have found a common theme: It’s important to maintain and update your skills by staying current on new rules and coding techniques.

For instance, focusing on C#, the declaring variables, arrays and lists have changed significantly since 2018 after C# 7.3. And C# 7.3 is the last fully supported version in .NET Framework 4.x. I demonstrate here how to use C# 12 (or C# 13 now) with .NET Framework 4.x in Visual Studio 2022.

If your legacy code is stuck in Visual Studio 2019, upgrading to C# 9 or C# 10 is possible. The critical point is that we shouldn’t be stuck with an old version of C# while the world evolves.

Now, it’s possible to declare a List in .NET 4.8 in VS 2022 with [].

For example, the old var declaration:

1.	List<string> myStrings = new List<string>();

Or:

1.	var myStrings = List<string>();

Can be more intuitive and efficient:

1.	List<string> myStrings = [];

Or, even in C# 10 in VS 2019:

1.	List<string> myStrings = new();

As developers, we need to be updated and reskilled constantly to avoid getting outdated and to keep our code clean and modern.

Visual Studio helps us to check some improvements that can be done in the Error List (Messages)—for example, “Object initialization can be simplified.”

Object initialization can be simplified messages

If we constantly update our code to be modern, we can take advantage of new programming techniques and avoid obsolete and unexpressive ways of coding.

Coding in Pair with GitHub Copilot

Using modern coding methods in any language or framework, AI autocomplete can help you perform tasks more efficiently.

Since 2000, I have dreamed of an AI that would code together as an assistant. So, I designed a data access structure with a built-in dictionary of the data source so AI could read it and generate code contextually. The AI era has arrived, and I’m taking advantage of my previous development. I’m thinking about making this an open-source project.

If you use the latest code design in any language, AI can help you generate a better and more consistent solution for your development.

November is the month of the release of the .NET framework—in 2024, Version 9. In the last few years, I upgraded and revised my C# code to the new features. This year, C# 13 was more accessible because I already upgraded to C# 12 last year, and I realized that if I had remained in an older version of C#, it would be much harder to migrate.

If your legacy codebase is too large, you may not have time or confidence to update it—we all know the “if it ain’t broke, don’t fix it” motto. But for new implementations and upgrades, you can start coding with the new features right away. For example, from the old way to the now-preferred method:

1.	List<int> myNumbers= new List<int> { 1, 2, 3, 4 };
2.	List<int> myNumbers0 = [1, 2, 3, 4];

Also, you can declare it as an array:

1.	int[] numbers = [1, 2, 3, 4];

Check out this post to see extra samples of C# updates: https://www.c-sharpcorner.com/article/learn-how-to-use-c-sharp-12-in-net-framework-4-7-24-8-solutions/.

Obey the Rules

Observing the programming rules—the formal and informal ones, like your team’s rules—is essential to keep code consistent, clean and productive.

I’ll give two samples of rules in C# programming—automatic property and async/await for I/O operations:

1.	public class Person
2.	{
3.	    public string Name { get; set; }
4.	    public int Age { get; set; }
5.	}

You can change the getter and setter code to a new logic anytime with the automatic property.

1.	public async Task<string> GetDataAsync()
2.	{
3.	    using var client = new HttpClient();
4.	    var result = await client.GetStringAsync("https://exempla.com");
5.	    return result;
6.	}

Using async operations to avoid freezing your apps can deliver a better experience.

An application following the same rules on the entire codebase is a solution that can be managed in the long term and upgraded efficiently and reliably in the future.

In the informal rules of the team, there are infinite styles each team can have, like the maximum number of lines per method, camel case, variable declarations style, names for repetitive tasks and vars.

All this contributes to a solid and clean code in your solution: If everybody is on the same page, the result will be consistent, reliable and easy to upgrade if necessary.

Conclusion

To be updated depends on your team, tech lead, project leader and requirements. As a developer, you will likely be looking to upgrade your skills and be desired by the market. Still, the important thing is to sustain your legacy app and keep the “things” working, keeping the code clean and maintainable.


About the Author

Jefferson S. Motta

Jefferson S. Motta is a senior software developer, IT consultant and system analyst from Brazil, developing in the .NET platform since 2011. Creator of www.Advocati.NET, since 1997, a CRM for Brazilian Law Firms. He enjoys being with family and petting his cats in his free time. You can follow him on LinkedIn and GitHub.

Related Posts

Comments

Comments are disabled in preview mode.