Sign in to follow this  
Utko

Yet Another C# vs C++ thread (but please read)

Recommended Posts

Hello! I'm aware that it's akin to suicide to create these kind of threads, but I hope my is more specific, so please help me out. I used to be fond of programming a few years ago, then had to drop it because of university and now suddenly I have this urge to resurrect my old hobby. Obviously things have changed while I wasn't paying attention, specifically .NET is now at version 3.5 (am I right) and C# is 3.0 Anyway, my question is... I want to finally learn how to program in its full sense, not just a specific language. I want to get it right this time, be able to actually visualize and imagine how something is supposed to be done, code-wise. And since I'm here, it's obvious I want to dedicate some time to writing games. Sorry that it's taking so long, but I just want to provide some background info. Anyways, I guess that I'm too old now to consider having programming as my job, though I still cherish this dream, I mean, I can always try to get a degree or something, but that's not really the point. I guess it'll always be my hobby, but you know never know. So I can't really decide now whether to work with C# or C++. Eventually I want to know both, but I can't decide whether to take the C# shortcut and first learn all the algorithms and all the programming stuff (I mean, learning how to write computer programs), so basically how to THINK in terms of programming; or dive into C++ straight away because frankly, and I've done a lot of research, it's still THE language, especially in gamedev. One of the pros of C++, I think, is that there are lots and lots of books about everything: 3D graphics, AI, physics, you name it - all using C++ for its examples. Erm, so basically... Shall I start with the "easier" and "cleaner" C# to learn how to program properly (I still remember most of the basic stuff, so I'm not a complete beginner), how to think like a programmer, how to carry out all these basic ideas; or try C++ straight away? It's not that I'm afraid of pointers and memory leaks, it's just that I think when you know how to program, languages become irrelevant, they're just tools for you and you can easily switch from one to the other and still be a competent programmer. So I just want to know whether C#'s qualities and user-friendliness overweight C++'s... dominance in terms of learning how to write computer programs with gamedev in mind. Hope that makes sense... Thank you and sorry for the "tl;dr" material.

Share this post


Link to post
Share on other sites
Quote:
Original post by Utko

I want to finally learn how to program in its full sense, not just a specific language.


You have basically two choices:
- The CS approach. Learn the fundamentals (ADTs, correctness, complexity, various algebras, logic, ....)
- The Software Engineering approach. Learn the methodologies, metrics, concepts (unit testing, team and management aspects, design patterns, domain frameworks, etc.). Also a university course.

Neither of the above deals with languages in particular, but each focuses on different approach towards building software. The SE one is considerably more profitable.

The above two choices are about "proper programming". Although the term is IMHO overrated... The only programming that counts is that which gets things done, rather sooner than later. But "proper programming" matters in real world, since it establishes common vocabulary and metrics through which teams can cooperate and monitor progress.

So I'm not really sure you need "proper" programming.

Quote:
Shall I start with the "easier" and "cleaner" C# to learn how to program properly

Yes.

Quote:
they're just tools for you and you can easily switch from one to the other and still be a competent programmer.

Well, almost every language and standard library concept is still covered in any Algorithms and Data Structures 101 course, although I'm not sure they still teach that. Either way, for fundamentals, you cannot go wrong with that.

Share this post


Link to post
Share on other sites
Thanks! I really like C# and obviously have nothing against C++, it's just that since it's a hobby and there's a 99% I'll be doing all of this on my own (no college courses, just online tutorials, books and forums), my time is pretty limited and want to start off as efficiently as possible. Granted, I do not have a specific goal at the moment, besides the fact that I really do want to finally UNDERSTAND what programming is about in its purest sense, because I know all the language stuff, variables, arrays, loops, OOP, but what I don't know is how to put all these elements, whether in C#, C++ or freakin' Basic, together to form a coherent unit, to achieve a goal, especially in gamedev, with physics, AI, graphics, even at their most basic level. I don't want to put a WebBrowser control on a WinForm, add a couple of buttons and call it my own Firefox Killer. I want to actually know how all of this is done, underneath, how a browser actually go about parsing HTML and whatnot. That was just an example. Same with gamedev.

And there's this other issue... Does C# have any decent graphics libraries? And please, no Managed DirectX, I think it's dead now, isn't it? Something like SDL (is that what's it called?). Even for a basic 2D game, I'm not talking DOOM3 style now. Because I have GameDev.net's very own Begging OpenGL Game Programming book and of course it's in C++ but it looks nice. Is there anything like that, both in terms of technologies and books, for C#? Or does it get really ugly with multiple OpenGL wrappers just to make it work on .NET?

Thanks!

Share this post


Link to post
Share on other sites
3 words: Books, tutorials, passion (for practice).

You can start with the tutorials of this site. I've read them almost all already. Some are a little technologically outdated, but the general ones are still usefull. If you really wanna do computer programming you'll have a lot of fun.

Share this post


Link to post
Share on other sites
Even though I am a large C# proponent these days, I must say that you won't get a good grasp of how programs fit together knowing any (one) language. Knowing different languages with different approaches is a very good way to train yourself to abstract language specific implementations to general structural concepts.

Quote:

I don't want to put a WebBrowser control on a WinForm, add a couple of buttons and call it my own Firefox Killer. I want to actually know how all of this is done, underneath, how a browser actually go about parsing HTML and whatnot. That was just an example. Same with gamedev.


Though this is something you'll need to wean yourself of. One needs not know the inner workings of every thing needed to make software. Indeed, being able to work with larger more abstract boxes is a vital skill often overlooked.


But back to the question at hand. This is not anything new. Use C#. Yes, it has graphics libraries for when you learn enough about program design to take that step. Though I'd perhaps suggest not going that route, and instead learning something like Haskell after you're comfortable with console C#; something like a chat application. That should help you get towards program structure and language agnostic conceptualization a lot more than rendering.

Share this post


Link to post
Share on other sites
If you're reading a book that is C++ heavy enough that you know C# and can't understand what it's telling you, throw it away. It's junk and the author was incompetent at writing books.

Share this post


Link to post
Share on other sites
Quote:
Original post by Utko

And there's this other issue... Does C# have any decent graphics libraries? And please, no Managed DirectX, I think it's dead now, isn't it? Something like SDL (is that what's it called?). Even for a basic 2D game, I'm not talking DOOM3 style now. Because I have GameDev.net's very own Begging OpenGL Game Programming book and of course it's in C++ but it looks nice. Is there anything like that, both in terms of technologies and books, for C#? Or does it get really ugly with multiple OpenGL wrappers just to make it work on .NET?

Thanks!


C# has some good gaming options available to you. XNA being one of the more obvious options. There are also the Tao framework. with bindings for all sorts of goodies such as OpenGL and provides direct access to the real functions so you use it the same way. I've used OpenGL, DevIL, and FreeImage libraries in C#. Since most engine/libraries are contained in accessible DLL files you can still use just about any one you wish, and most of the good stuff has already been addressed as with Tao Framework. Bottom line is you can get a hell of a lot done gaming wise in C# without ever getting in to C++. If you are liking C# and aren't looking to be getting employed as a top tier game designer then it is an extremely viable option for you to explore.

Share this post


Link to post
Share on other sites
Quote:
Original post by Goober King
C# has some good gaming options available to you. XNA being one of the more obvious options. There are also the Tao framework. with bindings for all sorts of goodies such as OpenGL

Not to forget the great SlimDX library, a thin managed wrapper around DirectX and some related libraries. BTW, SlimDX is probably one of the best designed interop libraries I've seen so far.

Share this post


Link to post
Share on other sites
Quote:
Original post by VizOne
Quote:
Original post by Goober King
C# has some good gaming options available to you. XNA being one of the more obvious options. There are also the Tao framework. with bindings for all sorts of goodies such as OpenGL

Not to forget the great SlimDX library, a thin managed wrapper around DirectX and some related libraries. BTW, SlimDX is probably one of the best designed interop libraries I've seen so far.


True, but I've found the documentation very unhelpful... Maybe I'm using the wrong help file. Or maybe I'm too noob for that yet, because all I could find for SlimDX was a reference, not really a tutorial.

But thanks, I think I'll go with C# then.

Share this post


Link to post
Share on other sites
Quote:
Original post by Utko
True, but I've found the documentation very unhelpful... Maybe I'm using the wrong help file. Or maybe I'm too noob for that yet, because all I could find for SlimDX was a reference, not really a tutorial.

Because it is such a thin wrapper I normally only have the C++ DirectX documentation open, works like a charm. There are of course some totally non-DirectX related thinks (e.g. how to write to a VertexBuffer), but you can pick those up from the samples, I guess. Otherwise, feel free to ask here!

Share this post


Link to post
Share on other sites
If for you, Microsoft Windows environment is what only matters, go straight forward with C# and .NET!!

Sadly for me, I'm still searching a platform with the features of C# but truly cross-platform. Well, perhaps there is Mono, but Mono doesn't have a descent IDE for non-windows systems. That's why Java is most used.

Also D language looks interesting.

However, c++ is necessary when you want the highest performance. The bad thing is that making cross platform code in c++ is too hard, and you must care about memory management and other low level issues.

Share this post


Link to post
Share on other sites
Quote:
Original post by superoptimo
If for you, Microsoft Windows environment is what only matters, go straight forward with C# and .NET!!

Sadly for me, I'm still searching a platform with the features of C# but truly cross-platform. Well, perhaps there is Mono, but Mono doesn't have a descent IDE for non-windows systems. That's why Java is most used.


MonoDevelop 2.0 is pretty good and works on Linux and Mac OS X. MonoDevelop 2.2 will be even better when released and can be used for Windows, Linux, Mac OS X *and* iPhone development. So yeah.

As for Java... Many Linux distros ship with Mono/C# applications out of the box. No Linux distro I know of ships with Java applications out of the box.

Share this post


Link to post
Share on other sites
Quote:
Original post by superoptimo
The bad thing is that making cross platform code in c++ is too hard, and you must care about memory management and other low level issues.


Why is cross platform C++ hard?

Share this post


Link to post
Share on other sites
Quote:
Original post by superoptimo
However, c++ is necessary when you want the highest performance.
Let me rephrase that for you: C++ allows you to achieve very good performance if you have a very good understanding of C++, the standard library implementation you are using, and the platforms/hardware you will be deploying on.
Quote:
The bad thing is that making cross platform code in c++ is too hard, and you must care about memory management and other low level issues
These are the areas that will hurt you. A naively written Java or C# implementation will often beat a naive C++ implementation in performance, because the higher-level languages are pretty smart about memory management, etc.

Sure, a good C++ programmer can implement optimise using custom memory management with allocation pools, etc. and in the end outperform the Java/C# implementation - but it isn't always worth the effort of dealing with all of C++'s shortcomings.

The bottom line is that the more-modern languages (in particular C# and Java) are plenty fast enough for 90% of applications written - so unless you have the requisite knowledge to say *beforehand* where your performance problem with Java/C# will be, don't make your decision based on performance.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fiddler
MonoDevelop 2.0 is pretty good and works on Linux and Mac OS X. MonoDevelop 2.2 will be even better when released and can be used for Windows, Linux, Mac OS X *and* iPhone development. So yeah.


May you're right. I haven't worked with MonoDevelop recently, but in that time I've had problems with debugging and I didn't found a class browser in MonoDevelop for navigating between symbols. So then I had to fallback to a plain editor like Geany and use command line commands for Mono.

I would like something more like Netbeans or Visual Studio.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
Quote:
Original post by Dolf

Why is cross platform C++ hard?


Look at Boost,
If my eyes don't fool me, then most of boost-hacks are about being portable among compilers*, not about being cross platform (across e.g. operating systems).

* including those with many bugs (e.g. Borland) or older ones that don't conform to standards (e.g. MSVC 6.0)


Quote:
QT
That's true, but for all programming languages (slightly related thread). The most essential sourcecode of C# API libraries don't look any better, if they are cross platform. Probably they are not even C#.

Anyways, like with most libraries, programmers typically use Qt to write cross platform code. They don't have tweak Qt's sourcecode.

Summary: Thanks to such libraries, it is nearly trivial to write cross platform applications in C++, if done right (i.e. if you've chosen the right libraries). Writing libraries is a completely other story.

Quote:
or ACE source code.

At the danger of attributing myself ignorant: Which one of those?
Quote:
wikipedia
* ACE (editor), a multi-platform collaborative editor
* ACE (file format), a data compression and archiving format
* ACE (software), virtualisation software from VMware
* Adaptive Communication Environment, a cross-platform C++ framework for concurrent software
o The ACE ORB (TAO), a free CORBA implementation based on the Adaptive Communication Environment
* Advanced Computerized Execution System, an electronic order-routing system
* Advanced Computing Environment, a defunct computer initiative to define a "new PC" based on MIPS CPUs instead of Intel x86
* Agent-Based Computational Economics, the computational study of economic processes modeled as dynamic systems of interacting agents
* Automatic Computing Engine, a 1952 British computer
* Jupiter Ace, a FORTH-based home computer
* ASCII Compatible Encoding, in the context of internationalized domain names
* Access Control Entry, a Microsoft Windows NTFS security element
* ACE Workbench Foundation, a web portal framework in use at UBS AG

Share this post


Link to post
Share on other sites
Quote:
Original post by phresnel
Summary: Thanks to such libraries, it is nearly trivial to write cross platform applications in C++, if done right (i.e. if you've chosen the right libraries).


Exactly my point.

Quote:
Original post by swiftcoder
A naively written Java or C# implementation will often beat a naive C++ implementation in performance, because the higher-level languages are pretty smart about memory management, etc.


In C# and Java it's easier not to make mistakes that might take some performance. But before you claim that Java or C# "often beats" C++ in performance I'd like to see some benchmarks and situations, because I find that quite hard to believe.

Anyway, if you're starting with game programming performance is not an issue. The target PC you'll be working for is your own and I don't think your first game is going to push hardware to the limits. Pick the easiest to work with language.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dolf
But before you claim that Java or C# "often beats" C++ in performance I'd like to see some benchmarks and situations, because I find that quite hard to believe.


swiftcoder didn't say that C# "often beats" C++ in performance, he said that naive C# will "often beat" naive C++. I'll give you an example: if you're dynamically allocating large blocks of memory on an inner loop in your code then the native C++ implementation will be much slower than the .net implementation. This is because dynamic allocation on the .net managed heap is, in general, almost as fast as allocating on the stack.

This doesn't mean you'll always be running faster code on the .net platform. When you think you actually have performance to be gained, then you should realize that C# and C++ are not mutually exclusive as you always have access to C++/CLI.

Regardless, programming in C# takes care of a lot of the annoying and senseless bullshit that you'd have to be dealing with when using C++. Anyone that says otherwise, or says that the supposed performance losses aren't worth the productivity gains, is either full of shit and lying out their ass or is an ignorant moron.

Share this post


Link to post
Share on other sites
Quote:
Original post by phresnel
Quote:
Original post by Antheus
Quote:
Original post by Dolf

Why is cross platform C++ hard?


Look at Boost,
If my eyes don't fool me, then most of boost-hacks are about being portable among compilers*, not about being cross platform (across e.g. operating systems).

* including those with many bugs (e.g. Borland) or older ones that don't conform to standards (e.g. MSVC 6.0)


Crappy/old compilers are commonly all that's available for some platforms.

Quote:
Summary: Thanks to such libraries, it is nearly trivial to write cross platform applications in C++, if done right (i.e. if you've chosen the right libraries). Writing libraries is a completely other story.

The hole in your argument is that few nontrivial programs will have all their needs met by existing libraries.

Share this post


Link to post
Share on other sites
Quote:
Original post by CrimsonSun
Quote:
Original post by Dolf
But before you claim that Java or C# "often beats" C++ in performance I'd like to see some benchmarks and situations, because I find that quite hard to believe.


swiftcoder didn't say that C# "often beats" C++ in performance, he said that naive C# will "often beat" naive C++.


Indeed. The curious thing is that they both are saying the same thing. I dont know what it is on the internet that makes people instantly disagreeable. From over here it looks like Dolf was telling swiftcoder the way he was doing it was wrong and that to do it properly he had to do it the way he (swiftcoder) was already doing it.

Share this post


Link to post
Share on other sites
Quote:
Original post by MaulingMonkey
Quote:
Original post by phresnel
Quote:
Original post by Antheus
Quote:
Original post by Dolf

Why is cross platform C++ hard?


Look at Boost,
If my eyes don't fool me, then most of boost-hacks are about being portable among compilers*, not about being cross platform (across e.g. operating systems).

* including those with many bugs (e.g. Borland) or older ones that don't conform to standards (e.g. MSVC 6.0)


Crappy/old compilers are commonly all that's available for some platforms.

Though most platforms are not commonly used, and conforming compilers are available for all relevant desktop operating systems, some mobile phones, and all relevant unix-, linux- and windows-based servers (+ some more).

If you conserve dead horses in your stable, it's clear that you have to live with some maggots.

That said, portable + cross platform C++ programs might be more portable + cross platform than C# applications.

As for the console market: Can't tell, but I bet it's only relevant for a minority of sparetime gd.net users. Does C# exist for consoles?


Quote:
Quote:
Summary: Thanks to such libraries, it is nearly trivial to write cross platform applications in C++, if done right (i.e. if you've chosen the right libraries). Writing libraries is a completely other story.

The hole in your argument is that few nontrivial programs will have all their needs met by existing libraries.

0) That's not specific to the programming language in question.
1) Care for examples?

Share this post


Link to post
Share on other sites
*dashing past all the C# vs. C++ fankids*

As an answer to the original post: IMHO, I think you should start off with C# and then move on to C++ if required (for example to write cross-platform apps, or due to library dependencies, and what-not).

What you should also do is to buy a *good book*! I can't stress this enough. Especially when it comes to C++ which has been around for a while, there's a lot of crappy OO-code and crappy solutions out on the internet. You're much better off investing your time in a book or two.

Share this post


Link to post
Share on other sites
Again - learning proper programming has nothing to do with languages, speed or portability. Proper programming is about learning the methods which allow one to:
- Choose the most suitable language for the job, and be instantly productive with it
- Evaluate problem complexity, then choose the most suitable algorithm
- Understand the problem domain and choose the platform/toolchain that will cover all the requirements

Last option falls under software engineering, and can, for most part, be omitted while learning, since it deals with business aspects, not programming as such.

C++ is not a magic bullet that will make one understand algorithms better, it is several times slower to debug, build and deploy, and lacks some huge productivity boost that one gets out-of-box in C#, Java, Python, ....

- Memory management:
It is a complex topic, but memory management can be studied without a single problem in a managed language. The difference is simply in that C++ allows some syntactic overloads to make it transparent, but that's C++ coding technique.
- Portability:
Libraries do exist which make it somewhat painless. But let's stay realistic here. Writing a simple application on top of SDL will be quite portable. But what happens when you need to use SIMD (ya'know, speed), atomic operations (happen to know of a good library equivalent of AtomicInteger<T>, or NonBlockingXXX, which are part of standard library these days), unicode (what is sizeof(wchar_t)?), and so on, just to mention the most basic stumbling blocks. Here is an insteresting article on portability as well. A quote from article:
Quote:
it takes around six engineers a couple of months to test the game on various possible PC configurations, and that's assuming that this is the only work they're doing. Not only that, but the testing has to be done continually throughout the development process.


Finally - all of the above is craft, is covered by third-party libraries, in tutorials and in platform documentation and SDKs. "LookItUp(tm)".

It all comes down to the question of what one wants. To learn "proper programming", which is the process of factoring down the problem, or just learning to churn out code, without ability to understand why.

For hobbyst, the second option is frequently quite viable, and in that case it makes sense to choose a language that comes with a safety net, airbags and good insurance policy. Then again, OP specifically asked about:
Quote:
I want to finally learn how to program in its full sense, not just a specific language
which makes choice of language mostly irrelevant (for reference, at university, we were taught those concepts in Oberon).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this