Backstory
For me, becoming a C# developer was not a choice: when I graduated as a Software Engineer in 2014, I was accepted in only one junior C# software engineer position for a Front Office Solution (the other job offer I got was for a microcontroller programmer with C). I had no other choice other than to go down the Microsoft route. However, for a long time, I kept asking myself: did I miss out on something better? Is C# still a good programming language to learn in 2022?
What does ChatGPT think?
It depends on your goals and interests. C# is a popular programming language that is widely used for building a variety of applications, including web, mobile, desktop, and games. If you are interested in developing applications for the Microsoft ecosystem, C# is a good choice. It is a relatively easy language to learn and has a large developer community, which means there is a lot of support and resources available online. However, if you are interested in a different area of programming, there may be other languages that would be more suitable for your needs.
It did a pretty good job but I think the answer is outdated... Let me explain!
C#/.Net Then - a brief history
C# then
Microsoft is known to have an approach of "let's find out what is the best tech in the IT world, study it and push our better version". C# is not the exception, it is the Microsoft "better version" of... Java! And here are the big similarities:
Managed: you don't need to worry about allocating and cleaning memory for the objects you create in your code, the Garbage Collector will do it for you!
Ease of use: Writing, reading and understanding C# code is a breeze thanks to the object-oriented programming (OOP) model.
Feature-rich: a wide variety of libraries are available, for instance, you don't have to write code to stream file contents, fetch data from databases or consume HTTP APIs, the .Net framework got you covered.
Strong community: you will find an answer for every situation just by googling.
Since Java is older, one question comes to mind: why should a developer or a development team consider C#? Well, at the time, C# was attractive, and here are some of the things C# did better than Java:
Getters & Setters: While Java getters and setters were just methods in a class, C# came up with "Properties":
Java
public class Person { private String name; public String getName() { return this.name; } public void setName(String name) { this.name = name; } } // calling code Person person = new Person(); person.setName("John"); String name = person.getName(); System.out.println(name); // prints "John"
C#
public class Person { private string name; public string Name { get { return this.name; } set { this.name = value; } } } // calling code Person person = new Person(); person.Name = "John"; string name = person.Name; Console.WriteLine(name); // prints "John"
C# with auto-implemented property
public class Person { public string Name { get; set; } } // calling code Person person = new Person(); person.Name = "John"; string name = person.Name; Console.WriteLine(name); // prints "John"
It's a lot cleaner in C# (auto-implemented property), at least in my opinion. Let's also note that the getters and setters support access modifiers (private and protected)
Multithreading: I am not diving into the details but to summarize, the way you create Threads, Tasks and Async methods in C# is unbeatable. The types you use in Java to start parallel executions (Consumer, Callable...) are a little bit misleading to me.
LINQ: This was one of the GOAT features that Microsoft brought to developers. LINQ makes the use of collections in C# a lot like querying SQL tables with a big performance advantage thanks to lazy evaluation. Java lately introduced Streams to have a similar feature such as C# LINQ.
Here is an example of a C# query that fetches names starting with the letter "A" in an array of names:
Query syntax:
string[] names = {"Alice", "Bob", "Charlie", "David", "Eve", "Frank"}; var query = from name in names where name[0] == 'A' select name;
Method syntax:
string[] names = {"Alice", "Bob", "Charlie", "David", "Eve", "Frank"}; var query = names.Where(name => name[0] == 'A') .Select(name => name);
The .Net framework then
By definition, a framework provides a set of rules and guidelines alongside the needed libraries and tools to build and maintain an application. Opting for the Microsoft ecosystem (.Net Framework and Windows) was a one-way trip, the application only works on Windows machines.
Besides, .Net was not Open-Source. That change came afterward, with the first version of .Net Core: the lightweight, cross-platform, open-source variant of the .Net Framework.
C#/.Net then - summary
Well, for me, C# even before the Microsoft "Open Source" Transformation was a great choice for developers: easily mastered, you can focus more on producing clean code, and adopting the SOLID principles was natural with C#.
Moreover, C# was the "Enterprise" choice, even though hosting was more expensive on Windows, it was the obvious choice for many Financial and Investment institutions and, for some reason, it was considered the preferred successor of C++, at least in the companies I worked for.
C# today
Well, if I were to answer the same question in present times, I would say "definitely" and here is why...
.Net Core
C# wouldn't exist nowadays without .Net Core as .Net Framework always relies on Windows OS for hosting. .Net Core can run on Windows. Linux or even inside Containers and this is a huge deal: it opens a lot of options for Cloud migration!
Most importantly, if you have an entrepreneurial mindset, developing apps with C# and .Net Core doesn't have limitations especially when it comes to Time-To-Market, you can host your app at a low (or sometimes free) cost and scale as the consumer base grows with a lot of flexibility.
Craftsmanship
You might have heard this trendy term a lot lately but before your skip, hear me out! The main reason you should value Clean Code, respect the SOLID principles or care about Design Patterns is not to be fancy; it is about having an application that's unit-testable and future-proof: doing all the above promotes lose coupling which means switching modules in an app for newer better ones will be easier.
Writing SOLID C# code is not a hard task to do because you don't need "Hacks" to do it like how inheritance is established between objects in Javascript for instance.
Blazor
Blazor is a fairly new offering by Microsoft, it uses WebAssembly and it allows the same built C# packages to be shared between client and server. Besides, Blazor (in combination with Razor) gives the possibility to define "Components", the same as Angular and React.
Blazor itself might not be attractive for React or Angular front-end developers, but what's promising for me is the fact that Microsoft is always trying to compete and innovate.
Alternatives
Java
People always compare C# to Java, I heard "C# is easier than Java" or "If you used Java before, C# should be a piece of cake" many times!
Java is still a good language to learn, it competes well with C# and it has a huge user base and strong community. Moreover, Kotlin is another Java-based language that has great features and seamlessly interoperates with Java, so it can be a good candidate to learn especially if you are interested in Android development.
Typescript
Typescript with Angular or React and Node.js is a powerful combo for full-stack developers that used to work with Javascript. Simply put Typescript is an OOP layer on top of Javascript. Typescript uses a Structural type system that is less strict than the C# Nominal type system.
Final word
If you are interested in learning a robust and capable programming language, C# sits at the top of the list: learning it goes without frustration. For me, it is the first candidate (using .Net Core) when it comes to back-end work for professional or personal projects.
I hope this wasn't too much of a rant. If you are interested in a particular subject from this article please let me know in the comments.