Jump to content


c++ or c sharp?


25 replies to this topic

#1 Doyle

    New Member

  • Members
  • Pip
  • 2 posts

Posted 24 January 2011 - 03:17 AM

New to coding, which should I start using?

Is c sharp just plain out superior to c++? I'm looking into eventually making a game engine after lots of learning so which would be better suited for such a task?

Thanks in advance.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 24 January 2011 - 03:45 AM

If you're brand new to coding, I would suggest starting with either Python or C#, then picking up C++ later.

C++ is more widely used in game development, is available on more platforms, and can be faster for performance-critical code. But it's not a good language to start with. It is powerful, but also complicated, low-level (you have to handle more details like memory management on your own) and has a lot of little quirks and gotchas.

C# is a cleaner, more modern, higher-level language, and is easier to learn. There are several game engines that let you script in C#, and it is also the most natural language to use with Silverlight or XNA. I'm not sure whether a full-featured 3D game engine has been written entirely in C#.

Python would be my recommendation for a first language because the syntax is exceedingly simple, which lets you spend more time focusing on learning how to conceptualize a program, organize code and data, and design algorithms rather than learning syntax rules. Those are the most important skills in programming, as they are the ones that cross language boundaries. There are a few game engines that let you script in Python, and some lower-level frameworks like PyGame, as well.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 24 January 2011 - 09:49 AM

Totally agree with everything Reedbeta says.

c++ is a complete mess, its full of redundant parts, c# is the way to go for a new guy, learn decent habits straight away.

Me? im still writing hybrid c, c++ cause its how I learnt spanning 10 years ago... if it ever gets to the point where it becomes obsolete completely im sure id be able to learn c# in a couple of days, so theres no big issue. c# is easy to pick up for an old c guru.

Go hell for leather with objects/classes, I suggest, build nice object structures and benefit from all the extra instancing youd get out of it, even though I still write procedural code most of the time. but I know what im doing, you can still use pascal these days if you really want to, its just as powerful as an objective language if you use the functions right.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

#4 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 24 January 2011 - 01:37 PM

No language is superior to another.

Allow me an analogy: is a nailgun superior to a hammer? Well, when you've got umpteen linear feet of crown molding to put up, you reach for the nailgun. Speed is it's forte... until the damn thing jams. But, if you are putting together a jewel box, well, the nailgun will blow the delicate work out. A hammer, with more control, is the call.

Reedbeta is right, though, some languages are more approchable than others. C# or Python are great because of not only the higher-level nature manages more for you automagically than C++, but there's more material available on the net for inbound devs.

But, in the end, it doesn't matter because a dev that only knows one language is just as versatile and useful as a carpenter that only uses a hammer.
Hyperbole is, like, the absolute best, most wonderful thing ever! However, you'd be an idiot to not think dogmatism is always bad.

#5 Steven

    New Member

  • Members
  • Pip
  • 2 posts

Posted 19 May 2011 - 06:44 AM

c# is easier to learn and use, but has overheads..
C++ is more efficient, but harder to learn and use as less of the more difficult programming aspects such as resource management are abstracted from you.
Birthday Party Treasure Hunt

#6 Mattias Gustavsson

    Senior Member

  • Members
  • PipPipPipPip
  • 413 posts

Posted 19 May 2011 - 08:39 AM

Start with C++. I think it gives you a better understanding of what goes on. It might take a bit more effort to get going with, but imo, it's effort well spent.
  • www.mattiasgustavsson.com - My blog and current projects
  • www.rivtind.com - My Fantasy world and isometric RPG engine
  • www.pixieuniversity.com - My Software 2D Game Engine

#7 Grandmaster B

    Member

  • Members
  • PipPip
  • 30 posts

Posted 19 May 2011 - 10:28 AM

Go with C/C++, its not easy but its the real thing. C# is nice but i believe you may waste your time if you get serious with an engine someday, only with C/C++ you can make everything you dream of (that should be motivation enough). In either language, you do not have to have learned everything to make cool stuff.

#8 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 19 May 2011 - 12:37 PM

Mattias Gustavsson said:

I think it gives you a better understanding of what goes on.

Depends on what you mean by "what goes on".

If you want to see the memory management guts, the pointers, the bit pushing and all the low-level stuff, then yes, C++ shows more of what's under the skirt than C#. However, if you want to be able to see the "higher-level flow", the algorithm, taking all that clutter away gives C# the edge. That's why it's an easier starter language for a noob...
Hyperbole is, like, the absolute best, most wonderful thing ever! However, you'd be an idiot to not think dogmatism is always bad.

#9 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 698 posts

Posted 19 May 2011 - 04:45 PM

C#, it will save you time, tears and pain. You don't need max time performance of the cpu-side code, that would otherwise be the only reason to use C++.

#10 Kekke88

    New Member

  • Members
  • PipPip
  • 29 posts

Posted 19 May 2011 - 05:10 PM

I'd say it depends on what you want to do.

Do you want to build game engines? go C++.
Do you want to build easy smart cool games? go C#.

Do you want to work at a game company (you will probably need lots of education as well though)? go C++.
Do you want to program for fun and as a hobby? go C#.

Do you want to spend much time, more code but eventually (maybe) get a cooler and more powerful game? go C++.

I don't think the statements above are 100% accurate but maybe they will help you decide.

#11 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 20 May 2011 - 08:45 AM

Doyle said:

I'm looking into eventually making a game engine...
If you're serious about your goal, then concentrate on C/C++. It's a steep and long learning curve, but once you master it you'll be able to take on any programming task.

If your goal is to become such a skilled programmer, I don't think learning a more domain-specific programming language first is worthwhile. They'll teach you a certain paradigm (rules you're supposed to follow), but when you transition to C/C++ you'll find that there are no strict rules and there are many successful paradigms to reach specific goals, and you'll get very confused/scared and try to avoid C++ and never become good at it. So in my opinion you should learn to stay afloat in the deep end as soon as possible. Once you understand how a complex C++ application works down to the most fundamental level, you'll have no trouble learning any domain-specific language should you need it, without getting distracted by the paradigms it enforces.

Opinions vary wildly on this subject though. So perhaps there is no right answer and you have to figure out for yourself which learning approach works best for you. Personally I've started with C and assembly, and then learned C++. I've never regretted starting at a very low level, because it taught me the skills to deal with complicated issues. I know lots of people who are very comfortable writing C# code, but totally panic when something unexpected happens because they are clueless how to handle it.

The thing is, you will encounter unexpected issues during the development of something like a game engine. Lots of them. The time spent actually writing code is only a very small part of the total development cycle. So while for instance a language with a garbage collector like C# allows you to write code a little faster by not having to worry about memory management all the time, it doesn't actually save you from all memory related issues. You might end up having to learn how the garbage collector works to get the behavior you expected.

I'm not saying this means you should write everything in C++ instead. On the contrary. You should learn C++, and then you'll be able to determine which language is best for the job (could be C++ itself). By understanding memory management you'll be able to fully appreciate the benefits of garbage collection, while also understanding the limitations. Knowing C++ gives you the insight necessary to make the right design choices.

It's like manual versus automatic transmissions in a car. If you plan to become a rally pilot, you're better off learning to drive a stick shift in your very first driver's lesson. It's a little harder at first, but will give you a much better insight into how things work at the mechanical level so it will be easier to become an advanced driver. If you learn to drive in a car with an automatic transmission, manual transmission will seem very awkward (since you learned there's an 'easier' way first) and to become a rally pilot you won't only have to learn normal driving with a stick, but also advanced driving. I hope you can see in this analogy that C# is more advanced in the sense that it takes work out of your hands, but if you actually want to do advanced things, you're better off with C++ which allows more manual control of all aspects.

Just my two cents.

#12 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 20 May 2011 - 08:57 AM

roel said:

C#, it will save you time, tears and pain. You don't need max time performance of the cpu-side code, that would otherwise be the only reason to use C++.
That might be a major reason (certainly not the only reason) to use C++, but there are plenty of other reasons to learn C++.

#13 Grandmaster B

    Member

  • Members
  • PipPip
  • 30 posts

Posted 20 May 2011 - 09:10 AM

Kekke88 said:

I'd say it depends on what you want to do.

Do you want to build game engines? go C++.
Do you want to build easy smart cool games? go C#.

Do you want to work at a game company (you will probably need lots of education as well though)? go C++.
Do you want to program for fun and as a hobby? go C#.

Do you want to spend much time, more code but eventually (maybe) get a cooler and more powerful game? go C++.

I don't think the statements above are 100% accurate but maybe they will help you decide.

That's a very good simplification, hits the nail. I second that.

#14 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 20 May 2011 - 09:11 AM

I dont know what you guys are talking about, c# does everything c does better, you can make a game engine in c# no skin off your nose.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

#15 Mattias Gustavsson

    Senior Member

  • Members
  • PipPipPipPip
  • 413 posts

Posted 20 May 2011 - 02:42 PM

Nick sums up my thought on this perfectly. +1
  • www.mattiasgustavsson.com - My blog and current projects
  • www.rivtind.com - My Fantasy world and isometric RPG engine
  • www.pixieuniversity.com - My Software 2D Game Engine

#16 v71

    Valued Member

  • Members
  • PipPipPipPip
  • 353 posts

Posted 20 May 2011 - 09:30 PM

What is becoming a common attitude is to switch from c/c++ to java also c# at university courses, professors loves java.I remember that my theses professor adviced me to forget about pointer becasue evertyhing is java now.
I felt really sick that day and it took several days to recover from that horrible feeling of 'now is everything java'.
I agree with the car analogy.
So i'd go for c++ since the start

#17 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 20 May 2011 - 10:21 PM

Nick said:

in my opinion you should learn to stay afloat in the deep end as soon as possible

If it's good enough for swimming lesson... wait, funny how nobody really teaches swimming itself that way, huh? :dry:
Hyperbole is, like, the absolute best, most wonderful thing ever! However, you'd be an idiot to not think dogmatism is always bad.

#18 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 23 May 2011 - 12:27 AM

alphadog said:

If it's good enough for swimming lesson... wait, funny how nobody really teaches swimming itself that way, huh? :dry:
I didn't say swimming. I said staying afloat.

I'm not suggesting that people should learn the hard stuff before they learn the easier stuff. That's just plain impossible. My point is that if one wants to become an expert at something, he/she should aim high and not skip any steps.

For instance learning manual memory management is actually not hard at all. It only becomes complicated once projects reach a certain size, at which point garbage collection becomes quite valuable. But knowing the basics of memory management gives you valuable insights into how software works and how to fix nasty bugs.

Likewise, object-oriented development is supposed to make programming simpler, but for newbies it's actually very confusing because in small projects it has little use. So in my opinion people should first learn C, so that once they move to C++ they fully realize the benefits of object-oriented programming. I also find it incredibly useful to know how inheritance works at the vtable level. It's hard to understand those kind of things if you haven't learned basic C function pointers first.

I'm even convinced that starting your first programming lesson in assembly makes sense. It's no harder than using a pocket calculator. But it helps tremendously in understanding how complex expressions and statements get executed by the actual processor, and makes you appreciate high-level languages even more. It's also invaluable for advanced debugging.

So really, starting with the bare basics doesn't have to be harder per se. It allows to learn things incrementally, instead of having to go back and forth between high-level and low-level to make sense of it all. But that's just my opinion...

#19 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 23 May 2011 - 01:59 PM

An alternative is to start very high. A scripting language that allows you to start procedurally just to get a ten-liner going, and then layer in algorithms like sorts, tress and other well-known algos to get a handle on computation, then on to "code modularity management" paradigms like OO and such.

And, voila: Python! ;)

Once you master that space, if you want to or need to know how the innards work, then try assembler. The race car analogy is apt. To race a car, you don't also have to be a mechanic.

As always, you can take a bottom-up approach or top-down, or a mix of both. At my school way, way back, they kinda did both, with an emphasis on bottom-up. Myself, from experience, find a top-down approach much easier, peeling the layers of a complex onion one layer at a time. IMO, the bare basics of assembler/C is too bare. It's like walking through a flat desert. Sure, there are no visible obstacles, but man is it hot and you gotta carry all that water, food and other basic necessities... :) IOW, to me, exposing a noob to C first, thinking that bit-pushing and other close-to-metal stuff is hard therefore good for them, is a case of "premature optimization".

Of course, ultimately, it really comes down to the source: the teachers that you get in life.
Hyperbole is, like, the absolute best, most wonderful thing ever! However, you'd be an idiot to not think dogmatism is always bad.

#20 Mattias Gustavsson

    Senior Member

  • Members
  • PipPipPipPip
  • 413 posts

Posted 23 May 2011 - 02:15 PM

I've found that more often than not, people who started out high level will struggle when trying to get to grips with low level concepts. While people who started low level, will often be fine with high level concepts. At least, that's my experience based on people I've worked with.

I fully agree with Nick on this one - it's way, way better to *learn* low level first - even if you end up *using* high level when working.
  • www.mattiasgustavsson.com - My blog and current projects
  • www.rivtind.com - My Fantasy world and isometric RPG engine
  • www.pixieuniversity.com - My Software 2D Game Engine





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users