So... what's so great about C#?

Discussion about everything. New games, 3d math, development tips...
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

So... what's so great about C#?

Post by Anteater »

Everyone always seems to talk bout how great C# is, so I thought I'd try it out. I downloaded MSVC# Express today, looked at some examples, and I have to say... it's like a slightly dumbed-down C++. Nothing more. I'm probably wrong, it may very well be great, but would someone explain to me just what makes it so good?
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

Seems's to be a decent list of pro cons

C# vs C++ by Eric Gunnerson
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

ya mee too i just see it is like c++ but c++ has many advantage than c#!? :roll:
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

It's kind of like C++, but you get your code written in 1/10 the time. There are so many good things in C# it's hard to know where to begin. The biggest drawback is that it's really Microsofts, even if it is an open standard.
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

jam wrote:Seems's to be a decent list of pro cons

C# vs C++ by Eric Gunnerson
Seems like a fair analysis (although I may be biased as the author is another Source Insight user).

I like C#, but one thing I'd really hammer home is that you should be very wary about using it for any serious server applications, for much the same reasons explained in this this evisceration of Java servers. C# goes hog wild on spawning threads for all socket operations; this will not scale, no matter how much iron you throw at it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post by Anteater »

I like C#, but one thing I'd really hammer home is that you should be very wary about using it for any serious server applications, for much the same reasons explained in this this evisceration of Java servers. C# goes hog wild on spawning threads for all socket operations; this will not scale, no matter how much iron you throw at it.
I program to create rather lame single player games, so I don't think that would be an issue. :D
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

I don't know much about C# but I know I tried to help someone get setup with it using irrlicht.

problem is the irrlicht compatability part.. meaning you'll be writing some extra code to use it. I think certain things still do not work. not sure.
3ddev
Posts: 169
Joined: Tue Sep 19, 2006 6:51 am
Contact:

Post by 3ddev »

First of all, my primary language is C++. I started "testing" C# out around a year ago. My impressions were mixed. Like Java, I somewhat liked the entire class library that comes with .NET and thus also C#. I also found event handling and delegates quite nice. Also, the Windows Form Designer makes it a snap to create nice gui applications, and custom controls is a nifty idea. Of course, having a "managed" language is nice. Good memory management without having to create a memory manager and delete variables and pointers. Last of all, I like how threading is integrated directly into the C# language. True, the threading is very inefficient, but for regular applications it suffices for the job.

But... What I didn't like: First of all, cross-platform support is currently pretty much limited. Mono is still far from complete and I question the community involvement. I also know that many users wouldn't be happy downloading the .NET framework(22mb) to run a simple app(<1mb). I did some tests comparing C++ and C#, and not surprisingly C# was much slower. The only place where it was faster was in establishing a network connection(Stream). Last of all, I don't like how few libraries are available for C#. Take a look at 3d graphic engines, for example. I know of only one pure C# 3d graphics engine, Axiom Engine. Most C# 3d games use C++ engines like Irrlicht through a wrapper. Not only does this make it slower than direct C++, you don't get the "managed" code. Last of all, how committed is Microsoft in updating and supporting a language like C#? In ten years, where will this language be at? It is not uncommon for large corporations to drop an old product and introduce a new within less than a decade. C++ in comparison has been around 30+ years and is as popular as ever...

Just my two cents! :wink:
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

IMHO, garbage collected memory is over-rated. If you forget to null a reference, then you leak just as hard as you do in a free()/delete based manager, with the added complication of not having to track down which component is causing a possible chain of references to persist.

This obfuscates the issue of who is responsible for freeing memory; in a free() based model, the component that allocates memory is usually responsible for freeing it. In a managed memory system, it's a collective responsibility; every user is responsible for nulling their reference, but none of them are solely responsible for verifying that the memory has been freed. IME, that actually tends to increase the chance of memory being leaked.

The big advantage (IMHO) is that if you have a reference to an object and don't null it, then you can be pretty confident that it's still valid, unlike in a free() model where another component can stitch you up a treat.

Horses for courses, but on balance I prefer the determinism of a free() based system.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
not_a_commie
Posts: 19
Joined: Wed Mar 21, 2007 6:22 pm

Post by not_a_commie »

Here's some things I like about C#:

1. The Reflection, Type, and Assembly classes are very useful. It makes dynamic loading a snap.
2. In addition, I like References rather than header files. For the most part, they are resolved at design time.
3. WPF is a cool API. I really like where they're going with it.
4. I like having easy access to most standard functionality such as regular expressions. I usually don't have to worry about which threading library I'm going to use today, etc.
5. I like the differentiation in C# between structs and classes.

Sometimes I wish it had the "throws" keyword that Java has. C++ has slightly more powerful templates. C++ also allows multiple inheritance and inheritance of structs, both of which I like.

The Boost library is cool. Unfortunately, most of the Irrlicht code doesn't use a lot of the coolness that the Boost library promotes.
not_a_commie
Posts: 19
Joined: Wed Mar 21, 2007 6:22 pm

Post by not_a_commie »

rogerborg wrote:If you forget to null a reference, then you leak just as hard as you do in a free()/delete based manager, with the added complication of not having to track down which component is causing a possible chain of references to persist.
Uh, going out of scope is as good as setting null, fortunately. Once you understand IDisposable interface and the "using" keyword in C# you can do everything you need with memory management. It's not very difficult. In theory, garbage collection is faster at runtime than freeing memory frequently. Most C++ coders have to write their own memory management routines for speed reasons. Many also use auto_ptr from STL or shared_ptr from the Boost library, so they don't have to worry about an exception kicking them out of a function before the free statement -- something you wouldn't have to worry about in C# assuming you use the using statement for objects that implement IDisposable.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

main c# disadvantage - reverse engineering. its quite easy to obtain code from compiled exe.
CuteAlien
Admin
Posts: 9926
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

not_a_commie wrote:In theory, garbage collection is faster at runtime than freeing memory frequently.
Well, you have that under your control in c++. The important thing when programming games is rarely the average time something takes, but in most games the peak time is important (losing 1-2 FPS is not so bad than say having the game drop 10 Frames once every minute). But i guess there might be some tricks to control the garbage collection for c# also, otherwise programming serious games with it would be hard. I know you could get that stuff mostly under control with Java - but it did usualy cause some additional work!

I suppose one advantage of c# will be faster compile times. C++ is really, really bad there. And that is sucking up a lot of development time.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

memmory allocation in c# is faster than in c++. btw myth that c# is slow as hell is totaly busted. tests prooved that there was obly 3-6% difference in performance, just dont know which was faster, c# or c++. If you dont bealive me look here, online counter shows 1500-1600 ppl online, server is written in c#. Now check [ur=http://altar.vnet.ee/mangos/l]here[/url]. This server limit is 175 players. Server is written in c++. Significant difference huh?
CuteAlien
Admin
Posts: 9926
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

@roxaz: a way better comparison of programming language speeds than a single example (which tells absolutely nothing, because implementations could be completely different):
http://shootout.alioth.debian.org/gp4/b ... ng2=csharp
(unfortunately only mono and gcc available).

And why should memory allocation in c# be faster? I can nearly bet there are simply some cases where c# has advantages and some where c++ has advantages, but in c++ you can implement every optimization which c# has while it's not possible to do so the other way round. The advantage of c# is not execution speed - it's development speed.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply