Why exactly is C# better than C++ (was Re: Up to date MFC Book)

D

David Ching

Tom Serface said:
I think C++ is in an awkward position. It needs to maintain the rich
unmanaged capabilities and standards compliance it has, yet it needs to
live in a managed world so the it can continue into the future MSFT sees
for application development. I think this puts a unique strain on the C++
development team. C# on the other hand doesn't have to do anything outside
of .NET so it can be a lot more restrictive and, I'd guess, easier to
develop. Thus, it doesn't need the C++ "baggage".

I keep hearing arguments like this and it is true in general, but what does
it mean to "strain" the team? What exactly can you do in C# that is harder
to do in Managed C++? Let's get some specifics here! Otherwise, I just
don't see any advantage to C#, other than it is easier to learn, and that
doesn't apply to experienced C++ programmers.

The biggest criticism I have about C# is the difficulty of deterministic
finalization, which is solved elegantly in Managed C++ using ~Class() and
!Class(). So for me, it is Managed C++ 1, C# 0.

OK, C# has the nice @ operator that lets you put literals in strings and not
worry about escaping them with '\'. Still, I can live without that. And it
lets you have switch statements with case strings, e.g.

switch (str)
{
case "value1":
...
break;
}


And it is not required to put "break" after all cases, it is assumed. But
so what? I wouldn't switch languages just for these features! Come on you
C# advocates! Sell me on C#!!!

Otherwise, I fear my current view that C# is simply another C++ wannabe like
Delphi (but with a nicer syntax) will stand.

-- David
 
T

Tom Serface

This list of blog entries is pretty interesting:

http://blogs.msdn.com/ericgu/archive/2005/01/26/360879.aspx
http://blogs.msdn.com/ericgu/archive/2005/01/27/361709.aspx

I've also heard of C++ guys who also use C# lamenting the absence of Class
Designer and some of the data visualizations and the ability to create them
for your own classes.

Like everything, there are tradeoffs. My friends who use C# swear that they
are tons more productive, but I don't feel unproductive using C++ and MFC so
that's mostly just an argument.

They only thing that would really get me to switch from C++/MFC to C# is if
I got the impression MSFT was dropping support for MFC (which I haven't).
Of course, now that I've said that they will probably drop it just to sway
me to the dark side.

Tom
 
D

David Ching

Tom Serface said:

Thanks, these were very interesting. Many of the cited disadvantages of C++
do not apply to C++/CLI because the full features of .NET are available. I
have to say, I embrace the simple philosophy of C# and couldn't care less
about getting into STL, Boost, templates, etc. religious wars. So C# is
good because you don't get into that (at least not yet).

If I were just starting out, I would learn C#. But for experienced C++
programmers, the situation is becoming clear: it is similar to how C
programmers could take their time learning C++ when it suited them, and in
the meantime, C was just fine. I think my original plan to learn .NET with
C++/CLI combined with absorption of C# along the way (as most code samples
are in C#) is the way I will go.

Thanks,
David
 
A

Ajay Kalra

If I were just starting out, I would learn C#.

Thats pretty much my view as well.
 
T

Tom Serface

David,

Me too, but I hope C++ keeps improving in the .NET paradigm so that
eventually C# goes the way of Java :blush:)

Tom
 
A

Ajay Kalra

Like everything, there are tradeoffs. My friends who use C# swear that they
are tons more productive, but I don't feel unproductive using C++ and MFC so
that's mostly just an argument.

Not really. They never claimed they were unproductive. There is huge
difference in productivity. Chris Sells mentioned this in his blog
several years ago. I never bought into it. However, I felt the same way
after using .Net/C# for around 6 months. The ease is immense regardless
of how deep your C++ knowledge is. Its like MFC vs VB from prototyping
point of view. VB wins hands down.
 
A

Ajay Kalra

Me too, but I hope C++ keeps improving in the .NET paradigm so that
eventually C# goes the way of Java :blush:)

Are you kidding? I would be willilng to bet that there are now more C#
developers than C++. I really have no idea what the numbers are but I
suspect (looking at traffic in newsgroups) the difference is huge. C++
is never going to die but it will always be a second grade language in
..Net and it should be as it was not purely designed for it. It does
what it is supposed to: cater to native code, and it does it very well.
 
B

Bruno van Dooren [MVP VC++]

If I were just starting out, I would learn C#.
Thats pretty much my view as well.

C# is very easy to learn. You pick up a book like 'programming windows
applications with C#', possibly compounded with a language reference, and
you are set. by the time you finish the books, you can do some neat stuff
AND have a pretty good idea what you are doing, and how you are doing it.

I always have to laugh when I see books called 'Learn C++ in 21 days' or
'Visual C++ in 24 hours'
They make me wonder why it took me several years before I knew what I was
talking about...
;-)

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
A

Ajay Kalra

C# is very easy to learn. You pick up a book like 'programming windows
applications with C#', possibly compounded with a language reference, and
you are set. by the time you finish the books, you can do some neat stuff
AND have a pretty good idea what you are doing, and how you are doing it.

I think its relatively much easier to get going as compared to C++.
I always have to laugh when I see books called 'Learn C++ in 21 days' or
'Visual C++ in 24 hours'
They make me wonder why it took me several years before I knew what I was
talking about...
;-)

The book I read seems to indicate that it will take a life time to
learn all features. Once I know it all, C++ will be obsolete.
 
A

Ajay Kalra

Actually even though I didnt really use VB too much, our Product Dev
dept(non programmers) used it a lot. They will give us real dialogs,
all done in VB in no time.

Also, VB is an excellent tool to develop and test COM servers. Nothing
can beat it, not even .Net. ATL/MFC/C++ was such a pain to write
programs to test the object model and with VB its a piece of cake.

---
Ajay
Yikes!

Tom

VB wins hands down.
 
R

Roman

Tom said:
Like everything, there are tradeoffs. My friends who use C# swear that they
are tons more productive, but I don't feel unproductive using C++ and MFC so
that's mostly just an argument.

How can they swear they are more productive if they only use C# ? Only
person using both can provide an objective comparison.

We use both. We are by no means experts, but we get around. C# is clean
language with lot of "syntactic sugar". When it comes to platform invoke
or subclassing a Windows form, it gets annoying.

Managed C++ can do everything C# can and more. When there is a need to
use or produce unmanaged code, compiler makes it completely transparent.
I do not need to define const int WM_KEYUP, only #include <windows.h>.
We have a lot of live unmanaged libraries and C++ makes it easy to use them.

All that said, now get this: Normally we deliver projects on time or
slightly late. For whatever reason, when we did our first C# project
(and we were learning), we delivered early.
 
O

Ole Nielsby

David Ching said:
If I were just starting out, I would learn C#. But for experienced
C++ programmers, the situation is becoming clear: it is similar
to how C programmers could take their time learning C++ when
it suited them, and in the meantime, C was just fine. I think
my original plan to learn .NET with C++/CLI combined with
absorption of C# along the way (as most code samples are in C#)
is the way I will go.

I think you might be better off using C# for your .NET learning
- it will give you a clearer sense of how things are done in managed
code, and the learning effort from a C++ background is really a
matter of hours. If you learn .NET with C++/CLI, you might
inadvertently mix up managed and unmanaged coding style.

BTW I am trying to switch from C# to C++ and I must say, I found
the C# generics surprisingly easy to learn (though covariance would
have been nice at times) but C++ templates is a misty land I hesitate
to enter - I simply don't understand the implications of using them.

I recently had to do a binary search on an array, first in C# and
later in (unmanaged) C++.

In C#, this was easy. I examined the instance methods of the array
object, nothing relevant there so I tried the static methods of the
array class, and right there was a generic method that did what I
wanted. I had to ensure the comparison was done the right way,
but this wasn't too hard to find out from the docs.

With C++, things seemed more complicated. I soon figured out
STL had a binary_search template function and this was what
I needed. But it wasn't clear from the online help description
of the template how to make it work on an array. The template
required two iterators. It took me a good deal of browsing and
guessing, and a few questions to a colleague who is more
knowledgeable with C++ than I, to find a way out: I declared
two pointer variables, had them point to the first array element
and after the last, respectively, then passed them, and somehow
it seems the compiler "understands" that these variables can
be used as iterators. The resulting code looks nice but I don't
understand how the compiler casts my pointer variables as
iterators, and I'll probably step through the code in a disassembly
window before I dare trust that it does the right thing.

This seems to be the general picture: there seem to be nice
and elegant C++ solutions to the tasks I face, but it can take
much time and confusion to get there. Whereas C# helped
me on the track incredibly fast but there were things that
simply wouldn't get right - for this particular project I need
better control of the memory management etc. than I can get
with managed code, and that's my reason for learning C++.

I still think the clr is a big mistake but that's another matter...
 
A

Ajay Kalra

Roman said:
How can they swear they are more productive if they only use C# ? Only
person using both can provide an objective comparison.

I thought it was evident from it that they were using C++ prior to using C#.

Managed C++ can do everything C# can and more.

MC++ is a thing of the past. It was a short term fix and apparently not good
enough for MSFT. Take a look at CLI.
 
T

Tom Serface

They used to use C++, but I'm glad to read your comments. Obvioulsy, I'm
still a C++ guy. Maybe your C# project was less complex.

Tom
 
A

Ajay Kalra

Tom Serface said:
If you say so :blush:)

I guess you have not gone thru the pains of doing COM programming in C++.
Its by far one of the most difficult environments for that purpose.
 
T

Tom Serface

I can't argue that. I haven't done that much, but the few times I have it
has been difficult to be sure.

Tom
 
A

Ajay Kalra

Tom Serface said:
I can't argue that. I haven't done that much, but the few times I have it
has been difficult to be sure.

..Net essentially has killed COM and for good reason.
 
B

Bruno van Dooren [MVP VC++]

I can't argue that. I haven't done that much, but the few times I have
.Net essentially has killed COM and for good reason.

A client of mine wanted to run COM in a client server model between 2
computers..
It took me 2 full days of fiddling with dcomcnfg, firewall settings and
security settings before I had it working.

DCOM is powerful, not question about it, but getting it to work can be a
horrible experience in a security controlled environment.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top