this post was submitted on 15 Jul 2023
29 points (87.2% liked)

Open Source

31358 readers
229 users here now

All about open source! Feel free to ask questions, and share news, and interesting stuff!

Useful Links

Rules

Related Communities

Community icon from opensource.org, but we are not affiliated with them.

founded 5 years ago
MODERATORS
 

C# is a useful object oriented programming language. You can generally do the same stuff as you can in C++ but as a game modder there is 1 huge advantage C# has over C++ and that's the way it handles include path orders, or it's lack thereof.

I actually typed out and described a scenario where this starts messing things up but it was quite verbose. But the tl;dr is that it's possible to get stuck in a situation where you have circular include dependencies (kind of like how circular dependencies screw you over really hard in Linux package managers sometimes). If you planned the structure of your code really really well this shouldn't be too big of a problem but if you're extending something that is both complicated and wasn't meant to be extended upon, it starts becoming a problem.

C# doesn't really have this problem because instead of including header files, it does that "using blahblahblah;" business which doesn't run into include order problems.

C# is "open source" but it was invented by Microsoft and is hard to use without dealing with Microsoft. I don't want to contribute to the agenda of proprietary software in any capacity so I make all my projects in C++. C++ is very powerful but for certain gaming-oriented use cases, while it is the best choice most of the time it's not the best choice all the time.

How do I use C# in a responsible and open-source way? Do I just have to avoid using visual studio? I don't own a single Windows or Mac computer that actually boots up. Do I avoid dotnet framework? Do I have to avoid everything dotnet? What about Net Core?

Typing g## into a terminal window isn't a thing so what's the FOSS way to use C#?

top 9 comments
sorted by: hot top controversial new old
[–] [email protected] 19 points 1 year ago

Technically .NET Framework is now surpassed by just .NET, which is entirely FOSS. Modern C# is virtually fully FOSS. The basic dotnet CLI is open source too, and you'll always have mono.

Microsoft obviously isn't making it easier. But I honestly haven't felt the need to use Visual Studio or any of Microsoft's proprietary tools.

[–] [email protected] 17 points 1 year ago* (last edited 1 year ago) (1 children)

With the exception of some stuff used for windows desktop development, .NET ("dotnet core" is just .NET now) is released under the MIT license. I'm not following how using .NET would be contributing to the "agenda of proprietary software".

The dotnet cli tools that come with the SDK run just fine cross platforms without Visual Studio. Your Linux distribution probably packages the SDK already, just install and use it.

If you want, you can use C# without .NET by using Unity, mono, or maybe Godot now I think?

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

Your Linux distribution probably packages the SDK already, just install and use it.

The .NET SDK is still not in the Debian repositories.

[–] [email protected] 12 points 1 year ago* (last edited 1 year ago)

What's your motivation for choosing C# in particular? If you want a language that performs well, handles dependencies sensibly, is more pleasant to work in than C++, but doesn't have the Microsoftiness of C#, you might also consider Rust. I'm an experienced C#/.NET developer who just recently started experimenting with Rust, and I like it. I don't know if it suits your use cases, but it compiles to native code and handles resources cleanly without the need for garbage collection, so it's faster than C#. It's less corporate-feeling too. The only non-.NET context in which I've used C# is Unity, but that's far from your ideal of open source.

[–] [email protected] 9 points 1 year ago* (last edited 1 year ago)

I personally use C# via Visual Studio only so I don't have too much experience outside of this, but I know Visual Studio Code has a C# extension and VSCodium should also work. If you are set on really not using as much of Microsoft's products as possible, you will still have to use the dotnet sdk. From the terminal you would then call dotnet such as dotnet new, dotnet build, dotnet run, etc.

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet

dotnet sdk is open source -> https://github.com/dotnet/sdk

[–] [email protected] 8 points 1 year ago (1 children)

There used to be Mono, but Microsoft bought the developer of that (Xamarin) a few years ago. So, I don't think, there is a non-Microsoft runtime/compiler these days...

Do you need C# for games written in C# or does it not really matter what language you use precisely?

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

I normally use C++ for making new games or misc projects from scratch but I think I could save myself some work using C#. I've done a lot of Rimworld modding and I like the way C# works. I really like how versatile C++ is though. If I want to make my program work on an old Athlon, I can compile with 32 bit and sse1. I would be surprised if it were possible to do that with any C# compiler but I also haven't researched to find out.

[–] [email protected] 1 points 1 year ago

I'm not particularly familiar with the C# ecosystem, only with the rather similar JVM ecosystem, and well, in that, there is a way to compile to machine code ahead of time (called "GraalVM"; the equivalent in C# might be ".NET Native").

But as I understand, that still needs a garbage collector and still does many unoptimal things, like constantly cloning strings or doing array boundary checks on every single array access.
So, yeah, I wouldn't either bet money on being able to run on an old Athlon with that.

Someone here has already recommended Rust and I'll extend that recommendation. You get that same performance/target flexibility. It's more abstracted than C++ and in particular much harder to shoot yourself in the foot with. And it's quite popular in the open-source community.

It does not use a garbage collector, so some patterns are more difficult than in C#. But since you're doing gamedev, you'll probably be using a game engine with Entity-Component-System architecture (personally, I'm using Bevy) and that bypasses a lot of those memory management gotchas.

One more downside to Rust, is that it's still rather young. I do feel like Bevy is in the generation of game engines that will probably survive long-term, but it's still doing breaking API changes frequently and you don't get a fancy GUI editor like with Godot...

[–] [email protected] 5 points 1 year ago

C# is a superb language, it's a shame it's not used more often for open source projects.

The only argument people seem to have against it is that it's maintained by Microsoft - which apparently is the worst thing imagineable. The reality is the Microsoft of today is very different to people's pre-conceived image. They've done a fantastic job with C# and .NET.

.NET has the best documentation of any language I've worked with, it makes life so much easier.

load more comments
view more: next ›