DEV Community

Cover image for Pitch me on C#
Ben Halpern
Ben Halpern

Posted on

Pitch me on C#

Continuing the series! Feel welcome to dip in and weigh in on a past question.

Let's say I've never used C# (C Sharp) before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.

Top comments (25)

Collapse
 
webbureaucrat profile image
webbureaucrat

Today is, God willing, my last day at my last C# job.

C#'s defining feature is that it has no defining feature. It is truly whatever you want it to be.

  • Want to write purely functional code and ignore object orientation altogether? C# can do that.
  • Want to escape the static type system and use dynamic types? C# can do that.
  • Want to write neat, clean, readable, concise code? C# can do that.
  • Want to write procedures that run to thousands of lines and just divide them up with comments that collapse different code blocks? C# is happy to do that.

C#'s overarching philosophy is basically that there's no such thing as a bad feature, and if that sounds like something you'd like, enjoy! C# will absolutely not stand in your way. For my part, I work well under constraints, and I appreciate when a language nudges a user towards best practices (especially since, you know, I have coworkers...)

The other thing I'll say for C# is that for all that the NuGet package manager leaves something to be desired, the package ecosystem is enormous. That corporate money does its thing.

Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha • Edited

C#'s overarching philosophy is basically that there's no such thing as a bad feature

Nicely put.

For my part, I work well under constraints, and I appreciate when a language nudges a user towards best practices (especially since, you know, I have coworkers...)

Personally, I too find that such an overload of features is not a good thing, that is why I recommend students to learn Java before anything else. A stricter environment to learn basics can be adopted to flexible life, not the other way around.

But it is this philosophy that has made C# a truly universal language. Web, All desktop platforms, all mobile platform. Unity, Godot, Game development. Blazor for webassembly. Micro-controllers, You name it, you will get C# on it.

Collapse
 
webbureaucrat profile image
webbureaucrat

But it is this philosophy that has made C# a truly universal language. Web, All desktop platforms, all mobile platform. Unity, Godot, Game development. Blazor for webassembly. Micro-controllers, You name it, you will get C# on it.

I have to give you game engines--I'm not in that space but I'm aware C# is big in it--but for the rest I'm skeptical that C# is more per-se universal than anything else. Seems like these days pretty much everything has a native compiler, a WASM compiler, and a JVM compiler. Like, I could write pretty much the same paragraph about the universality of, say, LISP, which has the smallest list of language features I'm aware of.

Thread Thread
 
abhinav1217 profile image
Abhinav Kulshreshtha

Yes. there is a native compiler for everything. Game engines have C++, Godot have GDScript. Rust is getting popular with wasm. But there is a C# solution available, for those who want it. Mobile apps, with Xamerin, Front-end with razor and blazor, Desktop apps with multiple gui toolkit support, There is an SDK for microboards like arduino too. Microsoft is not trying to make C# be the best solution in all the field, but trying to be "An Acceptable Solution" to all field.

And reason why these fields support C# as a native solution, because this way, developers wouldn't need to learn it from scratch. C# compiler doesn't compile it to CRL/IL in all cases, It can be configured to produce native binaries, or a portable executable library file. This is why it is easier for anyone to provide first party support to C# in their field.

In the end, a C# developer can write code for any of supported field, without need to learn a new native stack. And if you are creating something new, and want to attract developers quickly, providing support for C# might be fastest way for you.

It may come with tradeoff, Mobile apps in C# are really slow, But for some, hiring and training cost may just be high enough that they would be willing to accept tradeoffs.

Thread Thread
 
webbureaucrat profile image
webbureaucrat

I'm not denying that C# is cross-platform, and I do understand the benefits of not having to learn a new language for every stack-- I just don't see that as being any thing specific to C# or C#'s philosophy.

Collapse
 
polterguy profile image
Thomas Hansen

The other thing I'll say for C# is that for all that the NuGet package manager leaves something to be desired, the package ecosystem is enormous

We've tried GoLang for 3 different projects and had to scrap it every time due to a missing eco system, and difficulties finding (stable) libraries ... :/

Collapse
 
andrewbaisden profile image
Andrew Baisden • Edited

C# is a versatile language that was created by Anders Hejlsberg who works for Microsoft. Microsoft also own popular tools like Visual Studio Code and GitHub. This is a very powerful open source combination that integrates and works well together.

Anders Hejlsberg also created TypeScript so if you are a JavaScript developer then learning C# should not be too challenging because they share some similarities. The C# programming language has many use cases you can create web, desktop, mobile and server applications much like any other programming language.

One of its biggest advantages can be seen in the area of game development. The game development engine Unity uses the language C# and it is incredibly popular because a lot of big gaming companies use it for building AAA titles for consoles and PC's. Unity can also be used for developing mobile games too. The C# programming language is fairly modern and is Microsofts competitor to Java.

With all of these features and advantages C# is a very powerful language to learn which does not have an extremely challenging learning curve when compared to other general-purpose programming languages like C++.

Collapse
 
nikfp profile image
Nik F P • Edited

For me there are a few things that stand out in C#.

  • LINQ - Language integrated query. some other languages have tried to incorporate parts of this, but what you can do with LINQ in either a fluent syntax or the SQL-esque LINQ syntax is pretty incredible. Complex data operations on multiple data sources are the easiest to write that I've seen in any language.

  • Task Parallel Library (TPL) - This makes building multithreaded apps much easier to write and works with async / await patterns OR using task continuations. Both of these patterns will look similar to what Javascript does.

  • Generics and Delegates - the starting points for more functional styles of programming in an OOP language.

  • C# is mature and feature rich. There is a way to do anything you can think of.

  • NuGet - LARGE ecosystem of libraries to speed development.

  • Events - built upon Delegates and allows for simple Pub/Sub patterns to be built up between code modules. Code is easier to decouple as a result.

  • Extensive documentation - everything from the basics of variable assignment to the extensive tutorials on building certain kinds of apps is centralized on the Microsoft language documentation. One place to look.

  • Direct interop with F# - write some libraries in a functional language, consume them in an OOP language, no big deal. Do it the other way, no big deal. It all compiles down to "Intermediate language" and runs on the same runtime. (This also works with VB.NET, but just don't. VB is on sunset status)

AND some drawbacks:

  • C# is mature and feature rich. This is slated as a good thing also, but when there are 9 different ways to do anything, you see a lot of different patterns in the wild that accomplish the same thing. Thus, no "idiomatic" C# like we're currently seeing in Go.

  • NuGet is huge and there is a package for everything, but you have to be really careful about licenses when using anything. Some of the biggest players in the ecosystem and strictly for-profit are write libraries that they expect you to pay for. Fine for enterprise, but not for someone starting out.

  • Extensive documentation - sometimes it's just too much. Like sipping from a fire hose.

Collapse
 
jessekphillips profile image
Jesse Phillips

I would go further and claim that a language with restrictions does not mean it provides the ability to write good code or best practices.

However there is definitely value in having standards in how things are approached. To me this is less about the language and more about the collaboration. How is code shared, what can be done in code refactors to provide upgrade paths. Does the team work to stay up-to-date or put things on life support.

Collapse
 
ivis1 profile image
Collapse
 
awright18 profile image
Adam Wright

Do you want to build an app? You can build your app using any OS, or just a web browser. Your app can run anywhere that apps, or code runs. You have the option to use best-in-class tooling (even from your web browser) and choose from millions of libraries inlcuding one of the FASTEST web frameworks on the planet. The question isn't why would you choose C#, but why wouldn't you?

Collapse
 
isaacdlyman profile image
Isaac Lyman

Some may disagree, but I believe C# is the easiest strongly-typed compiled language to learn if you already know JavaScript. Most of the time it even feels like JavaScript. It lends itself well to a paradigm of imperative code with functional features, chained operators, and plenty of generics. It's also really concise but manages to tell a story most developers can read, even without prior C# experience.

It's fast, has an endless lineup of features, and enjoys extremely high-quality support from Microsoft.

And LINQ is the best functional list extension library on the planet. It makes me happy every time I use it.

Collapse
 
codewander profile image
codewander • Edited

Most packages implemented by Microsoft. Centralized technical leadership leads to a mixed bag of nice and mediocre ideas for frameworks, rather than typical decentralized oss in python, ruby, node where the best frameworks and libraries end up winning.

Moves slower, less churn than node, which can be a pro or con.

Collapse
 
swimburger profile image
Niels Swimburger.NET πŸ”

I believe C# has led the way and inspired many other languages by showing what worked and didn't work. I'm thinking of attributes, generic types, and especially async/await.
The language is awesome and they are still innovating a lot, although this also means some older features have become irrelevant because new features do the same much better.

Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

C# is similar to Java from a point that if you learn C#, skills related to code structure that you will learn will form the basis of your entire developer life.
Sometimes I feel that there are just an overload of language features creating a confusion on what technique to use. Where one thing can be done with many techniques, All techniques are valid and have different tradeoffs. Microsoft is known for that. Typescript is also an overload of features.

At present, Biggest benefit of learning C# is that it is a truly universal language. Dotnet Core is available for mac, windows, linux. You can create mobile apps with C# using xamrin libraries. Blazor webassembly has a good DX if your stack is already dotnet based. For game development, Unity, Unreal, Godot, And many more, allows you to use C#. Some home-automation system are also programmable with C#. If I remember correctly, Arduino board was also planning to implement C# sdk.

Collapse
 
polterguy profile image
Thomas Hansen

I'd like to add to this that C# is more about what to avoid than what to use. This is especially true in the library space, where 90% of everything is garbage, but every domain has (at least) one unique perl ... ^_^

Collapse
 
webbureaucrat profile image
webbureaucrat

Dynamics are never needed--lots of languages do fine without them, just like code #regions or default implementations on interfaces or "smart" properties.

But if you're too good of a developer to need, as you put it, "hand-holding" from your compiler then just use JavaScript for everything.

Collapse
 
superxcode profile image
SuperXCode

C# It's the strongest, and it's got a lot of advantages.
It's an extension of Microsoft's methodology from the '90s.
It is flaws in society aren't great because its already closed, unlike now.
Also Microsoft updates are changing very quickly

Collapse
 
frikishaan profile image
Ishaan Sheikh

It is an object-oriented, statically as well as dynamically types language.
You can create anything in C# whether it is a web app, cross-platform mobile application, desktop app, game, machine learning, etc. You can also create SPA using Blazor (C#).
It has a pretty big community, documentation and also other learning resources.

Collapse
 
noseratio profile image
Andrew Nosenko • Edited

AFAIK, C# was the first language that introduced and popularized versatile syntax sugar concepts like async/await, iterators, async iterators (JavaScript calls these generators), as well as Linq and ReactiveX paradigms.

Besides C#, .NET runtime APIs are available also from F# and PowerShell, cross-platform and open-source under MIT License.