Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14

Thread: C++ vs C#

  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts

    C++ vs C#

    Which is better? From what I've seen, C# is simpler. But does simpler mean less powerful?
    If you're reading this, it may already be too late!

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    No...it does not mean that in this case.

    C# is based on C++ and Java...and is as powerful as C++ or Java.

    In actual fact, a lot of people see C# as the natural replacement to C++...as it lends itself to powerful constructs that are available in C++, but not implemented in Java...such as operator overloading...among other features.

    This does mean that we are going to see the end of C++. A lot of applications available today are still being built on C++...and I don't think that we will see the end of C++ programming any time soon.

    The only thing you should note about C# is that is built targeting the .NET Framework...which only runs on Windows OS systems.

    Yes there is Mono which runs on Linux, Mac Os...and Windows...but, it is still under development...and not 100% compatible with .NET Framework....specially when building ASP.NET applications.

    In any case, C# is still a very powerful programming language....and it is much easier to learn than C++.

    Also, if you learn C#, you can easily switch to Java...as it is very similar in many ways to Java

    Cheers,
    Ess

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts
    When it comes to compiled languages like C++, I'm one step below newbie. Now, when you say "only runs on Windows OS systems", do you mean C# applications can only be built in windows, or they can only be run on Windows. (Or both?)
    If you're reading this, it may already be too late!

  • #4
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    If your application was built on .NET Framework...(.NET Framework only works on Windows)...then your application can only be run on Windows operating systems that have .NET Framework installed on them.

    There are many people who would argue that Mono run time...should still be able to run those applications...but...as I have stated previously...Mono is not 100% compatible with .NET Framework...specially, when one's application hard codes paths specific to Windows Platforms..or uses COM modules, or VB Code.

    By the way...if you haven't come across Mono before...here is a link to their main website.
    http://www.mono-project.com/Main_Page

    Of course, you can develop C# Applications on Mono...and you should be able to run your applications on Linux, Mac OS...so long as the machine has Mono runtime installed.
    Last edited by ess; 05-20-2007 at 12:23 AM.

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by Digger3000 View Post
    When it comes to compiled languages like C++, I'm one step below newbie. Now, when you say "only runs on Windows OS systems", do you mean C# applications can only be built in windows, or they can only be run on Windows. (Or both?)
    C# Applications require the .NET framework to run, which is only available under Windows. However as ess pointed out there is the Mono project which has a ported version for Linux (and other OSes I believe) however you'd still need to compile your C# program under Linux with Mono if you wanted it to run on Linux, I think; I've never tried it myself.
    OracleGuy

  • #6
    Regular Coder
    Join Date
    Oct 2004
    Location
    England
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You should choose a language dependant on your needs. Never compare two languages directly, only compare them with a project in mind. That's like saying "Shall I get a four-door car, or a two-door car?" without saying the reason why. If you've got kids, you'll probably want a four-door car. There are reasons for and against.

    Some people might want platform independence and not what to work with C#. Some people might want speed, thus working with C++. There's loads of reasons for and against, but it's entirely dependent on the context. Direct language comparisons aren't logical, only when there's context in mind.

    EDIT: I made a blog post especially for you: http://blog.kieransenior.co.uk/?p=50

    Ta.
    Last edited by KeZZeR; 05-21-2007 at 02:53 PM.

  • #7
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts
    I looked at some c# tuts, it looks harder than c++ to me xD

  • #8
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    Wow, I'd like to see those tuts I can't think of a situation where C# is "harder" than C++. (But I come from a Java background. I can do pretty much all I want in C# but I don't have or want much to do with delegates etc in C#)

    As Kezzer said, it depends on your needs. C++ takes longer to write, is usually harder for most people to write as a first language and if you aren't careful is platform specific anyway (you can write ANSI/ISO standard C++ and compile it with MinGW on windows or gcc on linux, and it should work on both, but as soon as you do something like use MS Visual C++, Winsock, MFC etc you are essentially limiting it to being run only on Windows)

    C# works with the .net framework on windows and mostly works with mono on other operating systems. In both cases the end user must have .net framework or mono installed. The good news is that XP SP2 and Vista both come with the .net framework, so this is not so much of an issue any more. Linux users can easily install mono.

    C# is used quite a lot in the industry, but I doubt it would cause people to stop using C++. Probably every major current game is written in C++ for example.

    Popular C# IDEs come with nice GUI designers too.

    However, C++ is native and can use C libraries (without any marshalling) such as SDL. This makes it easier to run by the end user and gives it a performance benefit.

    The argument is really whether you want a relatively high level language, or a relatively low level language. High level languages are faster to write and usually less buggy but suffer when it comes to performance and the end user being able to run them easily. Do you want to spend 3 months writing a piece of software to make it 30% (that was just a random number) faster than the same piece of software which took you only 1 month to write. Is it going to be written once and then used heavily for a long time, or written once and used rarely or for non-critical tasks?

    If you really need performance, use C++. If you don't, try C# and if you don't like it try C++. (and if you don't like that try Java or Python?)

  • #9
    Regular Coder
    Join Date
    Oct 2004
    Location
    England
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I chatted to some people who code real industry standard stuff and apparently they work in Java for systems powering massive databases. Java can achieve just as much as C can in some cases apparently.

  • #10
    New Coder
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    72
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by oracleguy View Post
    C# Applications require the .NET framework to run, which is only available under Windows. However as ess pointed out there is the Mono project which has a ported version for Linux (and other OSes I believe) however you'd still need to compile your C# program under Linux with Mono if you wanted it to run on Linux, I think; I've never tried it myself.
    That's not quite true, in the (limited) tests I've performed you can run a .NET compiled .exe file using `mono foo.exe' just fine under Linux, however it doesn't support Windows Forms (no, really?), and obviously if people are going to do half-arsed things like hard-coding in @"C:\mydir\foo.tmp" then applications aren't going to just run... but that's not really mono's fault.

    As for which is better out of C# and C++, I don't know really, I'm just learning some C++ to use SDL to be honest (good call ghell). C# is a lot "safer" in my opinion merely because you don't have as much access to pointers or multiple inheritance, so as a modern OO language for a novice I think C# fulfills "better".

    And this is my first post, so "hi codingforums!"

  • #11
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    Hi Ahri!

    I have definately used the same code to do forms under mono as .net, I don't remember if I needed to recompile for mono or just plain needed an extension library though.

    C# can be "unsafe" too, but of course you need to use the unsafe keyword Most of the time pointers are just not needed anyway. Java uses something like primitives by value, objects by reference, which seems to work quite well. In my oppinion, the only problem with Java (the actual language) is the lack of unsigned types, for example if you want to write a tcp port number it has to be an int (actually I think you can use a char which is like an unsigned short, but that can get a bit confusing)

    When people ask me what language to learn first I usually point them in the Java direction because the standard API is generally very good and the syntax is more meaningful (and neater in my oppinion) in most places than in some other languages. (for example use of "extends" and "implements" rather than : ) However, a lot of people seem to think it is hard as their first language (I dont know about this because I come from a background in BASIC ) and have told me in hindsight that they would have prefered me to have pointed them towards python first.

  • #12
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    I actually just started writing my first C# application in at least several months the other day. I've pretty much been doing C++. Why did I pick C#? I needed to make a simple application with a GUI quickly. And C# was the right tool for the job.

    I think it just depends on what you are doing. C# might be a better for a beginner since it won't let you do anything too naughty that will crash the computer or anything.
    OracleGuy

  • #13
    New Coder
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    72
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by ghell View Post
    I have definately used the same code to do forms under mono as .net, I don't remember if I needed to recompile for mono or just plain needed an extension library though.
    Sorry, should've done my research there; what I said was true when I did some testing of cross-platform functionality! I found the mono WinForms page after a very quick look on google

    To address the suggestion of Python as a first language; it occurred to me too but it's not a pure OO language so it might have a negative impact on the learning curve (I learnt a lot of OO through PHP and that's one mistake I don't wish on anyone - the abuses of the language and concepts perpetrated by me were really horrible!)

    I understand the reasoning behind suggesting Java, after all it was selected by my university as being an industry standard OO language to learn (we also did a 1 semester module in C# which I enjoyed a lot more). I just don't like java so much, interestingly the things I like most about it compared with C# are "implements"/"extends" and the natural ability to override methods without explicitly being allowed and specifying that you are doing so - those are things I dislike about C#.

    Since we're talking OO, how about Ruby? I have "the Pickaxe" and it's a really nice language to learn, the only complaint I have about Ruby is the performance of the interpreter. Oh, does Java have proper closures yet? Or do you still have to use the nasty anonymous inner classes hack? In Ruby closures are nice.

    http://poignantguide.net/ruby/ -- a crazy (but fun!) way to learn Ruby

    Addendum:
    Holy crap! Mono's WinForms support really does work, at least on basic GUI apps (like a work-for-10-break-for-2 application I made) - merely running `mono Workaholic.exe' (which was coded and compiled in VS2005) works fine!

    It doesn't work for everything though; my 3rd year project was on chord-input for the PC keyboard, and running that app fails with:
    Code:
    ** (ChordInput.exe:1866): WARNING **: Missing method System.Windows.Forms.Button::set_AutoSizeMode(AutoSizeMode) in assembly /usr/lib64/mono/gac/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll, referenced in assembly /home/adam/Sync/Coding/c#/ChordInput/ChordInput/bin/Release/ChordInput.exe
    But support for Forms 2.0 is on the way (with mono 2.0, targeted for Q3/2007).
    Last edited by Ahri; 05-23-2007 at 09:52 PM. Reason: Addendum

  • #14
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts
    http://csharpcomputing.com/Tutorials/TOC.htm
    http://www.csharp-station.com/Tutorial.aspx
    http://www.softsteel.co.uk/tutorials.../contents.html

    The last one is the best one, and also has comparisons of c# to c++ and java. So read those and make up your own mind

    C# vs C++

    Although it has some elements derived from Visual Basic and Java, C++ is C#'s closest relative.

    In an important change from C++, C# code does not require header files. All code is written inline.

    As touched on above, the .NET runtime in which C# runs performs memory management, taking care of tasks like garbage collection. Because of this, the use of pointers in C# is much less important than in C++. Pointers can be used in C#, where the code is marked as 'unsafe' (lesson 5), but they are only really useful in situations where performance gains are at an absolute premium.

    Speaking generally, the 'plumbing' of C# types is different from that of C++ types, with all C# types being ultimately derived from the 'object' type (lesson 4). There are also specific differences in the way that certain common types can be used. For instance, C# arrays are bounds checked unlike in C++, and it is therefore not possible to write past the end of a C# array.

    C# statements are quite similar to C++ statements. To note just one example of a difference: the 'switch' statements has been changed so that 'fall-through' behaviour is disallowed (lesson 10).

    As mentioned above, C# gives up on the idea of multiple class inheritance. Other differences relating to the use of classes are: there is support for class 'properties' of the kind found in Visual Basic, and class methods are called using the . operator rather than the :: operator.

    For more comparison of C# and C++ see:


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •