C++ Compared to C#

  • Thread starter Thread starter phil cunningham
  • Start date Start date
P

phil cunningham

Ok, I guess this is a common question but I need reassurance here.

I've used VC++ MFC for many years and have a love hate relationship with it.

I've been playing with C# for a couple of weeks and think it could be the way forward.
1.. We don't want to use legacy code.
2.. We have no reason to use Unmanged code
3.. We need pretty fast execution speed but robustness and ease of code maintenance is preferable
4.. All our users can be moved up to Windows XP

So my question is... when starting from scratch would there be any reason to choose C++ over C#

Look forward to hearing any comments on this.

Many thanks

Phil Cunningham
 
Not really Phil, I used C++ for years and I'm now almost exclusively
programming in C#.

I've deployed the .NET framework in several production applications and
generally found it to be very robust indeed. For code maintenance, I've
found C# is generally easier to manage than C++. Of course in terms of raw
speed C++ will sometimes have the edge over C# as you're no doubt aware, but
most of the time the differences are negligible (depending on your specific
application requirements). Also, some .NET 'innovations' such as the use of
the managed heap to allocate memory can speed up the code execution quite a
bit. The one area where you may find issues is that starting up programs
written using the .NET framework can take slightly longer than traditional
win32 API apps largely due to the fact that the code is JIT compiled on
startup. You can help to alleviate this to some extent by pre-jitting the
code, although for most apps this slight delay is not a problem - unless the
app will be started very often, run for short periods and then closed down,
the startup time is generally not an issue (and they normally only take a
second or two to start anyway...). Overall, I've found the execution speed
of managed .NET code to be very good.

Even if you do find that you need to use unmanaged code (either COM or
traditional dll functions) you'll find the .NET framework (and C#) has very
good support to enable you to do this, so you shouldn't have many issues
there.

There may be occasions when you find you don't have the same low level
control in your programs as you did with C++, although generally there are
ways around this by using API calls etc. This depends somewhat on the type
of programs you are writing - I've never found this to be a major issue not
sure about other peoples experiences here?

I've found that running .NET apps on XP or 2000 is preferable to running
them on NT 4 - the same apps ran somewhat slower when installed on NT 4
machines than on 2000 and XP machines although whether this was down to the
OS or the specific build I couldn't be certain.

One thing you didn't mention in your list is developer productivity - while
you will obviously have a learning curve to go through, after a few weeks /
months you 'should' find your productivity increasing quite significantly as
you find your way around the BCL and the winforms framework.

Anyway, good luck whatever you decide to do!


--
Steve Willcock, MCSD
http://www.willcockconsulting.com/

Ok, I guess this is a common question but I need reassurance here.

I've used VC++ MFC for many years and have a love hate relationship with it.

I've been playing with C# for a couple of weeks and think it could be the
way forward.
We don't want to use legacy code.
We have no reason to use Unmanged code
We need pretty fast execution speed but robustness and ease of code
maintenance is preferable
All our users can be moved up to Windows XP

So my question is... when starting from scratch would there be any reason to
choose C++ over C#

Look forward to hearing any comments on this.

Many thanks

Phil Cunningham
 
Dear Steve

thanks very much for the reply

Back in 1989 C++ was a fantastic stepup from C, but many of the features
that I originally found so exciting about C++ do suffer from it being on top
of 'C' - it was a great tool but although you can do just about anything
with C++ many of them I'd rather not be able to do :)

I am extremely impressed by the way C# seems to know what to do without
header files - one C++ feature I wont miss.

So far my main reaction to C# is "surely it cant be so easy to do..." fill
in the blanks.

In fact the more I look at our exisiting product the more I see that at
least 50% of it is simply support code that we will no longer need, just
from that our program should be twice as stable.

Once again thanks for letting me know your experience, it is very reassuring
to hear

All the best
Phil
 
phil cunningham said:
Dear Steve

thanks very much for the reply

Back in 1989 C++ was a fantastic stepup from C, but many of the features
that I originally found so exciting about C++ do suffer from it being on top
of 'C' - it was a great tool but although you can do just about anything
with C++ many of them I'd rather not be able to do :)

I am extremely impressed by the way C# seems to know what to do without
header files - one C++ feature I wont miss.

So far my main reaction to C# is "surely it cant be so easy to do..." fill
in the blanks.

In fact the more I look at our exisiting product the more I see that at
least 50% of it is simply support code that we will no longer need, just
from that our program should be twice as stable.

Once again thanks for letting me know your experience, it is very reassuring
to hear

All the best
Phil
Just wanted to add my second to Steve's eloquent reply. You sound like the
ideal candidate for C#.
Your comments on C++ ("... it was a great tool but although you can do just
about anything
with C++ many of them I'd rather not be able to do :)") speaks volumes!
 
Stroustrup himself called C++ a superset of C. In evolution new bits are added
on when the old cannot be revised to deal with new situations. As soon as you
do that (add bits on), you create interface problems. Also new bits were added
on to C++ again like STL. So C++ is a bit of a ragbag.

It is like an application that you keep on chopping and changing to meet new
demands. A day will arrive when you chuck the whole lot overboard an rewrite
the application. C# is a rewrite of what preceded.

(C# wasn't written with speed as a prime objective. Re C# language spec ECMA 334)

Ok, I guess this is a common question but I need reassurance here.

I've used VC++ MFC for many years and have a love hate relationship with it.

I've been playing with C# for a couple of weeks and think it could be the way forward.
1.. We don't want to use legacy code.
2.. We have no reason to use Unmanged code
3.. We need pretty fast execution speed but robustness and ease of code maintenance is preferable
4.. All our users can be moved up to Windows XP

So my question is... when starting from scratch would there be any reason to choose C++ over C#

Look forward to hearing any comments on this.

Many thanks

Phil Cunningham
 
-----
It is like an application that you keep on chopping and changing to meet new
demands. A day will arrive when you chuck the whole lot overboard an rewrite
the application. C# is a rewrite of what preceded.
--------

this is exactly where I am at.

Thanks for reply
Phil

Stroustrup himself called C++ a superset of C. In evolution new bits are added
on when the old cannot be revised to deal with new situations. As soon as you
do that (add bits on), you create interface problems. Also new bits were added
on to C++ again like STL. So C++ is a bit of a ragbag.

It is like an application that you keep on chopping and changing to meet new
demands. A day will arrive when you chuck the whole lot overboard an rewrite
the application. C# is a rewrite of what preceded.

(C# wasn't written with speed as a prime objective. Re C# language spec ECMA 334)

Ok, I guess this is a common question but I need reassurance here.

I've used VC++ MFC for many years and have a love hate relationship with it.

I've been playing with C# for a couple of weeks and think it could be the way forward.
1.. We don't want to use legacy code.
2.. We have no reason to use Unmanged code
3.. We need pretty fast execution speed but robustness and ease of code maintenance is preferable
4.. All our users can be moved up to Windows XP

So my question is... when starting from scratch would there be any reason to choose C++ over C#

Look forward to hearing any comments on this.

Many thanks

Phil Cunningham
 
Adrian said:
(C# wasn't written with speed as a prime objective. Re C# language spec
ECMA 334)

I think c# is the final admission of c programmers that what IT and most
programming projects really need is Visual Basic 6.0 in a form that can do
threads and can run reasonably fast.

Because they still cannot give up their precious idea that 'c' is so
superior, they took what is basically Visual Basic with an improved memory
model and mega-COM objects ( now called assemblies ) and made it look like
c.

Then of course they stole all every idea java ever had and threw that in.

That's ok. Java was just a rip off of visual basic.

If Visual Basic could write applications that didn't look like crap when
they repainted the screen -- it would have dominated all programming in the
last 10 years.

Instead, here's the hapless m$ trying to catch up to java.

Well, at least one good thing came out of it: mono.

www.go-mono.com
 
Everyone is free to use the language of their choice.
Choice is a good thing, because variation happens
to guarantee that the most fittest will survive. No
variation (say nothing but VB) would therefore
be a bad thing. M$ is a bit of a blessing really
because you need lots of money to plough back
into improved quality. As to pinching good ideas,
would you prefer to scrap all good ideas, rather
than build on them? Most developments are what
Schumpeter called "neue Kombinationen" that is,
recombinations of what was already there and
available.
 
Maybe I'm a bit of a sucker but I really like Microsoft Products. The amount
of tools now available is really incredible compared to a few years back and
it I dont see how something like .Net could be done except by a company with
enough muscle and money to impose a standard and supply an enormose
potential user base. As long as the tools get better, allow me to do what I
need to do and help me be more productive I'm a happy chap.

Mind you, I'm programming exclusive for Windows so I dont really care about
portability issues.

I suppose if you are a VB programmer you may object to the curly brackets
and ; but for everyone coming from C,C++ it makes it very easy to get going.

maybe some people take all this progress for granted but as a C++ programmer
I can only sit and wonder at how good C# is

Phil


Adrian said:
Everyone is free to use the language of their choice.
Choice is a good thing, because variation happens
to guarantee that the most fittest will survive. No
variation (say nothing but VB) would therefore
be a bad thing. M$ is a bit of a blessing really
because you need lots of money to plough back
into improved quality. As to pinching good ideas,
would you prefer to scrap all good ideas, rather
than build on them? Most developments are what
Schumpeter called "neue Kombinationen" that is,
recombinations of what was already there and
available.
 
Ok, I guess this is a common question but I need reassurance here.

I've used VC++ MFC for many years and have a love hate relationship with it.

I've been playing with C# for a couple of weeks and think it could be the way forward.
1.. We don't want to use legacy code.
2.. We have no reason to use Unmanged code
3.. We need pretty fast execution speed but robustness and ease of code maintenance is preferable
4.. All our users can be moved up to Windows XP

So my question is... when starting from scratch would there be any reason to choose C++ over C#

Look forward to hearing any comments on this.

Many thanks

Phil Cunningham

Depends what and how you code

If it is a GUI app not really (although you can use WinForms in C++ as
a replacment for MFC if you don't want to completely rewrite your
code)

I see C# as more of a replacement for VB

On point 2 above, I thought the same but found that the there are too
many WinAPI calls not in the .Net framework yet and in certain cases
they are awkward (not impossible I'm sure but a pain) to wrap

The lack of templates is annoying

The difference in speed is substantial in almost every case where I
have compared them. In most cases it didn't matter (on a simple GUI
you may notice it but not enough to make the program unusable)
but in cases where there was heavy use of COM components the cost of
using the Interop layer was too high

Vin
 
The decision should really be about which "framework" you want to build your
applications on...
Do you want to stick with MFC, STL, ATL etc. all with their own definition
of a string?
Or do you want to base your apps on the .NET framework, which is the basis
on which all forthcoming Microsoft OS and server products are being built
(at least for the next few years).

Sure you can get at the .NET framework from C++, and you can use managed
extensions, but it is still not a first class .NET language like C#.
The next release of VS.NET (2005) does make C++ a first class language (I'm
not quite sure how) but you will still need to get to grips with the .NET
framework.

The syntactical differences between the C++ language and C# (and VB.NET) are
minimal. I do agree with Vin - the lack of templates are annoying - but
these are on the way in VS.NET 2005 (called 'generics').

In my experience the only situation where I see C++ winning over C# is where
processor cycles are critical to your application performance (or where .NET
framework is not available).
In most application scenarios this is simply not the case (unless your
running on legacy hardware or mobile devices).
If some parts of your application do need this, code those in managed C++
and write the other 95% of your application in C#.

C# (and any other fully-managed language) is a considerably more productive
environment both in terms of initial development and subsequent maintenance.
Solutions are robust almost by default - something which in my experience
could take considerable effort with C++.
 
Back
Top