CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: C# or C++?

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    C# or C++?

    Do many of you C++ coders also code with C#? I am completely brand new and am wasting a lot of time trying to decide which route to take, sighs.

    I am interested in all sorts of applications for programming skills from simple handy tools to have around the desktop to reverse engineering to device drivers.

    As I understand, C++ uses native code and is entirely portable, C# uses the .net framework which makes it hard to code programs that are easily deployable on host machines without the appropriate .net framework installed. Thats not really a worry to me since I will be coding purely for me anway.

    I was close to settling on C++ until I read an interesting article comparing the two which suggested that for every 1 line of code in C# you would need to write between 3-5 in C++ to achieve the same task (later learning that this is because of the class modules that C# can make use of).

    Whilst my motivation for learning programming is for my desire to learn about computing and everything in it, I know myself think I could get demotivated by not being able to figure out the myriad of problems that unmanaged code presents.

    Sorry this is turning into an essay so I will stop clearing my throat.

    These are some of my coding goals whichever route I take:

    1. automating the web like a web scraper/filler
    2. a team-viewer like application
    3. being able to extend functionality of existing programs by hooking and creating ad-ons without source code
    4. automating the windows invironment like predicting what I am going to do based on my historic behaviour (eg. I go to documents and it learns that I normally next go to downloads so just opens downloads folder, stuff like that).
    6. manipulating memory/graphics
    7. controling packets and network activity.

    And thats about it so far.

  2. #2
    Join Date
    Aug 2011
    Posts
    8

    Re: C# or C++?

    If keeping motivation is an issue, start with C#. The learning curve is a bit easier and once you mastered C# jumping up to C++ is not all that bad.

  3. #3
    Join Date
    Aug 2005
    Posts
    198

    Re: C# or C++?

    Learn at least a little of both - it's easier to understand some concepts if you have experience with more than one language.
    e.g., it's easier to understand C# struct vs class when you understand C++ value vs reference semantics (in C++ this is accomplished only in the way variables are declared while in C# the actual type is different).
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  4. #4
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    Re: C# or C++?

    I would have to go with learning C# first, then "graduation" to C++ if, after developing applications in C#, you find yourself longing for more fine-grain control, portability, and performance tweaks...

  5. #5
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: C# or C++?

    I echo the sentiments of the other authors: learn C# first and transition to C++. I thought your portability comment was a bit odd since one of the major goals of a virtual machine-based langauge (.NET runtime, Java runtime, etc) is theoretical "compile once; run anywhere" portability. In my experience, installation of the .NET runtime on Windows boxes is not a severe limitation to portability. Additionally, I have had good experiences running .NET applications in linux under mono (link). Usually I re-compile using the mono compiler, but I'm not sure if this is just superstition on my part. Often the binaries I have compiled under Windows work just fine if you copy them to a linux box and run them under mono.

    Specific replies to your goals:

    1. automating the web like a web scraper/filler
    C# is fine

    2. a team-viewer like application
    C# is fine

    3. being able to extend functionality of existing programs by hooking and creating ad-ons without source code
    Probably C++ is better is my gut instinct

    4. automating the windows invironment like predicting what I am going to do based on my historic behaviour (eg. I go to documents and it learns that I normally next go to downloads so just opens downloads folder, stuff like that).
    This is going to be hard in any programming language. I recommend a solution like AutoHotKey (link).

    6. manipulating memory/graphics
    Kind of vague; either is fine. Depends on your application.

    7. controling packets and network activity.
    C# has a number of libraries for this purpose. C++ should be fine too.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Join Date
    May 2007
    Posts
    1,546

    Re: C# or C++?

    As I understand, C++ uses native code and is entirely portable, C# uses the .net framework which makes it hard to code programs that are easily deployable on host machines without the appropriate .net framework installed
    You just quoted the exact reason why C++ isn't portable and then said that's what makes it portable :P

    There are many ways to define portability. The two common ones are write-once run everywhere and compile-once and run everywhere. C++ and C# both allow write-once run everywhere however C++ requires that you must recompile for every platform you want to run on. C# allows *compile-once* and use the exact same binary on all platforms on all systems on all operating systems. This is what makes C# more portable than C or C++.

    3. being able to extend functionality of existing programs by hooking and creating ad-ons without source code
    Probably C++ is better is my gut instinct
    Definitely easier in C# Dynamic assembly loading combined with reflection makes it trivial to write and use plugins. Take a look at Mono.Addins as an example framework for writing plugins or perhaps Managed Extensibility Framework (MEF) written by Microsoft.

    To be honest, everything you want to do is more than suitable for C#. Some of the more complicated things (point 4) are definitely *more* suited to C# than C++ as all you care about is expressing your high level logic. You don't want to have to care about when exactly you should free a certain block of memory.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  7. #7
    Join Date
    Jan 2010
    Posts
    1,133

    Re: C# or C++?

    Yeah. About portability: the .NET framework is likely to be available everywhere in the future.
    There is another important aspect of .NET: every .NET language compiles to IL (Intermediate Language), which is then rather efficiently just-in-time complied (JIT-complied) to the appropriate form for the underlying platform. This enables all .NET languages to pretty much effortlessly cooperate - your C# code can call an API from a dll written in VB.NET, and vice versa.

    Also, IIRC, some (or most) of the people who replayed to your question have experience with both C++ and C#, so they know what they are talking about. I believe that not many C++ coders also work with C# - if you asked this question at the C++ forums section, you would probably get a different answer, but a more C++ - biased one, I believe.

    Now, don't get me wrong - C++ is a great and powerful, multiparadigm language. It is also often a bit messy, and more low-level than C#. It's great when you need power and performance, but this doesn't come without significant knowledge and experience (both C++ - specific and language independent). C#, at it's core, is elegant, intuitive, more OO, really good at what it does and well thought out. It is designed with the age of the internet in mind (which doesn't mean it's not suitable for desktop applications - it most certainly is), and the .NET framework comes with an extensive library with APIs for all kinds of things. C++ devs will tell you that C# code runs slower than C++, and it is, but not all that much.
    And, C# is a managed language - which means that the resources are (again very efficiently) managed by the runtime, which in-turn means that a whole set of memory-leak-related problems is removed from the language, and that memory leaks are far less likely.
    C# also has pointers, in a more limited form than in C++, but C# developers almost never have to use them.

    As for what's possible to write in each language: most or almost all things you can do in one, you pretty much can do in the other. The key differences are conceptual, as pointed out in this thread. You should also try both to see what feels better to you.

    I'll echo Mutant_Fruit's remark about 3 (extending functionality): C# is definitively more suited for that than C++ - if we are talking about plugins. Also, C# assemblies are self-documenting, as they include metadata about the code they contain. To use a C# (or generally a .NET) dll, you essentially need nothing else but the dll itself.

    As for "6. manipulating memory/graphics", generally speaking C++ is more suitable for intensive graphics processing, however, there are games, even commercial (a Sims series entry, I think) written in C# and with Managed DirectX, and with the XNA Framework you can write C# games for XBox.

    Finally, C# has interop capabilities, which enables you to work with native code in your C# application, at the expense of portability, but you can design around that.
    Last edited by TheGreatCthulhu; August 9th, 2011 at 10:15 AM.

  8. #8
    Join Date
    Jan 2010
    Posts
    1,133

    Re: C# or C++?

    I'm glad to say that the the OP got generally the same answers from the C++ guys.

    For those interested: >>> the twin thread at the Visual C++ section >>>

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured