C#,C++ Some insight (Not about performance)

Started by
13 comments, last by EduardoMoura 11 years, 4 months ago
Well, let me start by saying this is not asking about which language is better/faster.

I have been programming in the .Net platform for about 6/7 years, so I quite like to think of myself as a "decent" programmer, and no matter what C# is one, if not, my preferred language.


I have been thinking in writing a (another) game this days, the thing is I am feeling divided by what approach to take.
I am not sure if I should go for c++ or c#, I am proficient in both, but I am not sure which one to pick.

My doubts are mostly because I don't want to reinvent the wheel, and I feel that C# lacks a lot of good libraries that are available in C++. I talking mostly about physics and other components that are needed for game. I don't want to roll my own on everything, why should I since there are many great ones available already out there that simplifies the job.

So my question, I think, is more on what language would be "easier" and more future prof to write the game. I am not worried about portability, since c++ would probably win hands down, even with mono laying by C# side.

I was thinking in using OPENGL / DirectX with C#, no XNA since I have grown a dislike on the lacking features of DirectX and how hard it is to implement some of features.

I want to hear your insight on this subject, how viable is C# to make a decent game, or if I should scracth it an go with the market choice of C++. Once more I am not asking how performant they are, and lets be realistic I am not going to make a AAA game, so my question is not really which is the best language, but which one would make development easier/faster.

Check out my new blog: Morphexe

Advertisement
I think it is entirely project-dependent. When you are evaluating project design issues, you have to make some choices - for example, what 3rd party components you will be reusing. If existing C# libraries satisfy your needs, then you should choose C#, because it's obviously easier to develop with this language. If there are no C# libraries you can reuse, you should choose C++ in that project.

And, personally, I think that if C# is so great, then good libraries will show up sooner or later. But perhaps it is not that great...
I am not saying C# is better that c++, actually I think they both have their Pro/Con.

But I find myself beliving that C++ is the way to go in this case, I just feel sad leaving my beloved C# behind. One of the aspects I love in C# is the fast prototyping we have and great compile times in huge projects mostly. I guess, in this case, I will just take the dust of my c++ skills and go with the industry standard.

Check out my new blog: Morphexe

I've found great C# wrappers for many C++ libraries, what in particular do you need? There are native c# physics libraries, and c# wrappers for things like Bullet. SlimDX and SharpDX both wrap DirectX, OpenTK and Tao wrap OpenGL...the list goes on. Aside from mission-cricital performance differences, mitigated by programmer error in many cases, there's no real reason you HAVE to go with C++ unless a specific library you want doesn't have a port or wrapper for it.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

I don't really have specific library in mind, I was just thinking in future I don't want to be mid game development, and then snap I am lacking something.
Also on another subject, OpenTK,ShapDX etc, how close are they to their native counterparts?

Check out my new blog: Morphexe

@Morphex

For sharpDX: http://code4k.blogspot.com.au/2011/03/benchmarking-cnet-direct3d-11-apis-vs.html
Above all, you should do what you're most comfortable with. C# has a nicer environment in my opinion, but you really can't go wrong with C++. If you want to be 100% sure you won't run into issues related to your language choice, I'd roll with C++. With the reinventing the wheel thing, I'd say C# and C++ both have a good amount of libraries so you won't have to. From switching from C# to C++ recently though, I've found that C++ has more overall support, and more libraries support it natively, whereas some C# libraries are just C++ libraries with wrappers.

If I had to recommend one or the other flat out, I'd say C++. Like I said, you really can't go wrong with it. It also feels pretty good not being shackled by the .NET framework. Muh freedoms.
@Xanather, wow that was suprisingly informative, I never expected that the diference would be so small. I guess I was lacking a bit of research on the subject :\. Thanks for the heads up.

Check out my new blog: Morphexe

I think the sweet spot in writing a game in C# and C++ would be to have your core engine coded in C++ and then exposed to C# (or any other language that can bind to C) via a C interface (good for portability) or CLI/C++ interface. This way you keep all the game code using the elegance and simplicity of C#/F# while using C++ to interface all the 3rd party libs as it was meant to be.
Also, this way, you are not paying the price of constant context switching that you get when using things like OpenTK and SharpDX happening at every single function call, and you can keep this cost under control by grouping more calls into a single "engine" call.

This for the software.. then there is the programmer's brain context switching cost.. I find this remarkably annoying, especially when you are forced to go "down" into C++ code because you need something not available in C# land... I did this for my last project project and I didn't really like it, so for my current project I am back to C++ only approach. Somehow, working with C++ only makes you forget how much it sucks to deal with forward declarations, includes, stupid compiler error description and so on... having part of your code in a decent language like C#/F# is a constant reminder of how much suckage there is in C++.

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

It's very viable to write games with C# (I've enjoyed several indie games that were all XNA based and really didn't do a lot of in the "game engine" department).

And as the other posters have said, perhaps one of my favorite things about C# is how easy it is to pluck useful libraries from the native world. This was one of the main selling points for .NET/C# way back when I was still doing things in Java.

This topic is closed to new replies.

Advertisement