473,839 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

learn C++ or C#

If I haven't made substantial investment in either C++ or C#, which language
would the experts recommend I become well acquainted with?

Daniel
Jul 17 '08
151 4545
Multi-threading, GUI development is much easier in most of the other
languages compared to the efforts you have to take in C++, because they
support it out of the box. Fortunately C++ has Boost.
To be fair, this has nothing to do with C++ as a language (which has no
support for multi-threading or GUI whatsoever). You have to separate the
tools from the language itself.
The only programming paradigm I miss in the other languages is RAII.
That's IMHO still a big plus of C++.
RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
..NET advocates will point out that the GC takes care of cleaning most
resources so the programmer has to do nothing at all. IMO the C++ paradigm
is still a better design but the reasons run too deep to get into here.
A simple example:

How do I ensure in C++ that I have successfully overridden a base class
virtual function and that the compiler throws an error if the base class
implementation has changed ?
C++ has many warts, many a legacy of C itself. From cast issues (very
dangerous) to forgetting to handle newly added class members in your
existing copy constructors and copy assignment operators. Templates are also
an incredible source of difficulty and potential errors (very difficult to
understand, read, and get right beyond the basics - some things will be
improving in C++0x but it's really too late). The use of #includes and
headers in general (from C) is also a hornets nest of serious problems. Not
to mention the usual issues of pointer handling, the cryptic nature of the
syntax itself (from C style arrays to function pointers to many types of
arcane C++ constructs like binders, adapters, etc. - did I mention
templates?). The dizzying array of rules and trap doors in general is very
difficult to master.

I also have some serious pet peeves. Why didn't they permit local classes to
be passed as template arguments. I once asked Stroustrup about this at a
conference but I wasn't satisfied with his terse response. The fact is that
many templates are useful for small local tasks. Why should I use the
"for_each" template for instance (among many others) if the tiny function
object I want to pass has to be declared outside the function itself (where
I'm using "for_each") . It would be so much cleaner to just declare the
function object locally. C# allows me to use anonymous methods which is so
much cleaner. The issues surrounding C++ go on and on.

Don't get me wrong, C++ is still a very powerful and flexible language with
incredible versatility (and very elegant design constructs in spite of all
the problems). The trade-off is that it's very difficult to master and
therefore prone to many serious problems. Even very experienced developers
have to continuously bend their minds out of shape and remain on guard years
after learning the language. This is not the hallmark of a successful
language in spite of C++'s "stellar" reputation and the millions who
continue struggling with it.
Jul 24 '08 #91

[Larry Smith]
>The only programming paradigm I miss in the other languages is RAII.
That's IMHO still a big plus of C++.

RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
.NET advocates will point out that the GC takes care of cleaning most
resources so the programmer has to do nothing at all.
The GC is fine for memory resources - it runs a garbage collection process
when under memory pressure.
But, what about non-memory resources (like sockets, textures, files, etc.) ?
I think that GC is designed for memory resources only, and has very little
clue about non-memory resources.

Instead, if you use RAII and a smart pointer (like shared_ptr, or some
intrusive reference count smart pointer) to manage non-memory resources,
they will be released as soon as the ref count becomes 0, making a very
efficient use of precious resources.

Yes, C# is a very well designed language, which incorporates lots of lessons
learned from C++, Java and Visual Basic.
But C# has not discovered destructors yet :)

Giovanni

Jul 24 '08 #92
The GC is fine for memory resources - it runs a garbage collection process
when under memory pressure.
But, what about non-memory resources (like sockets, textures, files, etc.)
?
I think that GC is designed for memory resources only, and has very little
clue about non-memory resources.
Yes, that's what "IDisposabl e" is for as previously mentioned. The "using"
statement is just a compiler-generated wrapper around it, putting your code
in a "try/finally block behind the scenes and calling
"IDisposable.Di spose()" for you. RAII is clearly much better than this.
Instead, if you use RAII and a smart pointer (like shared_ptr, or some
intrusive reference count smart pointer) to manage non-memory resources,
they will be released as soon as the ref count becomes 0, making a very
efficient use of precious resources.

Yes, C# is a very well designed language, which incorporates lots of
lessons learned from C++, Java and Visual Basic.
But C# has not discovered destructors yet :)
Actually it has destructors but they're not the same as C++ destructors
(they're just compiler-generated wrappers for "Object.Finaliz e()"). I
already agree that object creation/destruction in C++ is cleaner and more
natural IMO. This hardly makes up for the many problems in C++ however. Like
many others, I have a love/hate relationship with it but objectively
speaking (IMO anyway), it's still a failure for the reasons I mentioned
previously.
Jul 24 '08 #93
Larry Smith wrote:
>Multi-threading, GUI development is much easier in most of the other
languages compared to the efforts you have to take in C++, because they
support it out of the box. Fortunately C++ has Boost.

To be fair, this has nothing to do with C++ as a language (which has no
support for multi-threading or GUI whatsoever). You have to separate the
tools from the language itself.
I don't think so. What would C++ be without the standard library ?

And that GUI development is easier in other languages has IMHO something
to do with the language. C++ isn't IMHO fast enough in compilation to be
a good RAD language - at least you don't have the same developing
experience in C++ as in other languages.
[...]
RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
Yes. Using is fine if I hold a resource in a control block, but if the
resource is held by let's say multiple lists, I have to use some kind of
smart pointers to handle the resources efficiently. In C# I can rely on
the GC to free the memory - so far that's fine. But resources should be
freed immediately, if they aren't used anymore.
.NET advocates will point out that the GC takes care of cleaning most
resources so the programmer has to do nothing at all. IMO the C++ paradigm
is still a better design but the reasons run too deep to get into here.
[...]
understand, read, and get right beyond the basics - some things will be
improving in C++0x but it's really too late). The use of #includes and
headers in general (from C) is also a hornets nest of serious problems. Not
I don't think that it's too late, C++ modules could fix many problems.
But since they aren't in the upcoming standard I perhaps have to agree -
it will be too late.
[...]
Andre

Jul 24 '08 #94
On Thu, 24 Jul 2008 06:43:30 -0700, Giovanni Dicanio
<gdicanio@_nosp am_email_dot_it wrote:
[Larry Smith]
>>The only programming paradigm I miss in the other languages is RAII.
That's IMHO still a big plus of C++.

RAII is also vastly superior to "IDispose" and "using" statements. OTOH,
.NET advocates will point out that the GC takes care of cleaning most
resources so the programmer has to do nothing at all.

The GC is fine for memory resources - it runs a garbage collection
process
when under memory pressure.
But, what about non-memory resources (like sockets, textures, files,
etc.) ?
I think that GC is designed for memory resources only, and has very
little
clue about non-memory resources.
This distinction has nothing to do with the _language_. If the OS was
entirely garbage collected, then these "non-memory resources" wouldn't be
an issue. They would be managed the same way memory is in .NET and you'd
never have to worry about disposing them.

Now, with certain types of objects you'd still have to deal with closing,
flushing, etc. But that's not something that RAII inherently solves; it
just happens that C++ classes can take advantage of that to handle those
operations. The OS API itself isn't based on C++ and requires the program
to deal with managing those operations.

In C++, RAII provides a convenient way to deal with that, and in C#, the
"using" statement does the same. You may prefer one syntax over the
other, but I personally don't see a difference between the two that would
justify an argument of superiority one way or the other. Larry's claim of
"vastly superior" seems particularly baseless. Vastly? Pure hyperbole.

Pete
Jul 24 '08 #95
>>Multi-threading, GUI development is much easier in most of the other
>>languages compared to the efforts you have to take in C++, because they
support it out of the box. Fortunately C++ has Boost.

To be fair, this has nothing to do with C++ as a language (which has no
support for multi-threading or GUI whatsoever). You have to separate the
tools from the language itself.

I don't think so. What would C++ be without the standard library ?
It would be another language since it must include the library by
definition. Contrast this to C# whose basic support is primitive (see the
standard for yourself). In any case, the claim that GUI development is
"easier" in C# compared to C++ has nothing to do with the languages
themselves. It's the rich set of classes in MSFT's framework combined with
better development tools that make C# easier (noting that C# is a natural
fit for the framework unlike C++). Provide an equivalent C++ library and
better tools and it will be just as easy (not taking into account the actual
language differences).
And that GUI development is easier in other languages has IMHO something
to do with the language. C++ isn't IMHO fast enough in compilation to be a
good RAD language - at least you don't have the same developing experience
in C++ as in other languages.
>[...]
RAII is also vastly superior to "IDispose" and "using" statements. OTOH,

Yes. Using is fine if I hold a resource in a control block, but if the
resource is held by let's say multiple lists, I have to use some kind of
smart pointers to handle the resources efficiently. In C# I can rely on
the GC to free the memory - so far that's fine. But resources should be
freed immediately, if they aren't used anymore.
The "using" statement is ugly compared to RAII. Moreover, in theory your
unmanaged resources may never be released if you neglect to call
"IDisposable.Di spose()". Other problems also exist with this pattern.
>
>.NET advocates will point out that the GC takes care of cleaning most
resources so the programmer has to do nothing at all. IMO the C++
paradigm
is still a better design but the reasons run too deep to get into here.

[...]
understand, read, and get right beyond the basics - some things will be
improving in C++0x but it's really too late). The use of #includes and
headers in general (from C) is also a hornets nest of serious problems.
Not

I don't think that it's too late, C++ modules could fix many problems. But
since they aren't in the upcoming standard I perhaps have to agree - it
will be too late.
The core language is in place. Enhancements won't change that. The problems
inherent in C++ will remain forever unless it morphs into a different
language (but then it won't be C++ anymore).
Jul 24 '08 #96

"Peter Duniho"
In C++, RAII provides a convenient way to deal with that, and in C#, the
"using" statement does the same. You may prefer one syntax over the
other, but I personally don't see a difference between the two that would
justify an argument of superiority one way or the other.
Destructor and "scope" syntax in C++ is cleaner, simpler and more elegant
than C# bloated 'using'.

Moreover, there is big difference between C++ RAII and C# "using".

In Andre's words:

<quote>
Using is fine if I hold a resource in a control block, but if the
resource is held by let's say multiple lists, I have to use some kind of
smart pointers to handle the resources efficiently.
</quote>

For example: I think that there is nothing like shared_ptr in C#.
With shared_ptr you can have a *deterministic* resource manager, and you can
wrap also non-memory resources in classes and store shared_ptr to these
class instances into STL containers, and that works fine and is very elegant
and simple.

And there are also intrusive smart pointers, you may consider Eugene
Gershink's implementation here:
http://www.gershnik.com/articles/refcnt_ptr.asp

BTW: I'd like to make it clear that I'm saying neither that C++ is better
than C#, nor that C# is better than C++. Simply, both languages have pros
and cons.

Giovanni
Jul 24 '08 #97
In C++, RAII provides a convenient way to deal with that, and in C#, the
"using" statement does the same. You may prefer one syntax over the
other, but I personally don't see a difference between the two that would
justify an argument of superiority one way or the other
That's hardly a valid argument, considering that RAII requires no "using"
statement whatsoever. This alone justifies an argument that there is a
difference in favour of C++ (in contrast to your assertion).
Larry's claim of "vastly superior" seems particularly baseless. Vastly?
Pure hyperbole.
Point conceded. Scratch the word "vastly".
Jul 24 '08 #98
On Thu, 24 Jul 2008 10:25:47 -0700, Giovanni Dicanio
<gdicanio@_nosp am_email_dot_it wrote:
"Peter Duniho"
>In C++, RAII provides a convenient way to deal with that, and in C#, the
"using" statement does the same. You may prefer one syntax over the
other, but I personally don't see a difference between the two that
would
justify an argument of superiority one way or the other.

Destructor and "scope" syntax in C++ is cleaner, simpler and more elegant
than C# bloated 'using'.
Purely subjective. That sort of claim has no place in a technical
discussion.
Moreover, there is big difference between C++ RAII and C# "using".

In Andre's words:

<quote>
Using is fine if I hold a resource in a control block, but if the
resource is held by let's say multiple lists, I have to use some kind of
smart pointers to handle the resources efficiently.
</quote>
RAII doesn't _inherently_ support "smart pointers", nor does a garbage
collecting system prevent one from implementing "smart pointers".

As I pointed out before, in a 100% GC-ed system, "smart pointers" become
unnecessary anyway. But in a mixed system (i.e. pretty much any current
platform), it's entirely possible to implement "smart pointers", and they
can work in a very similar way to that implemented with RAII.

Which only brings us back to your purely subjective complaints about
"using".

Pete
Jul 24 '08 #99
On Thu, 24 Jul 2008 10:35:59 -0700, Larry Smith <no_spam@_nospa m.com>
wrote:
>In C++, RAII provides a convenient way to deal with that, and in C#, the
"using" statement does the same. You may prefer one syntax over the
other, but I personally don't see a difference between the two that
would
justify an argument of superiority one way or the other

That's hardly a valid argument, considering that RAII requires no "using"
statement whatsoever. This alone justifies an argument that there is a
difference in favour of C++ (in contrast to your assertion).
You save a whole line of code. Wow! Yup...that definitely outweighs any
advantage that garbage collection has with respect to simplifying and
improving the robustness of memory management. After all, that's what
programmers really care about. I'd much rather save a line of code than
make it more likely that my code is correct.
>Larry's claim of "vastly superior" seems particularly baseless.
Vastly?
Pure hyperbole.

Point conceded. Scratch the word "vastly".
Replace it with "insignificantl y", and then _maybe_ you've got a point.

Personally, I think a discussion comparing/constrasting languages should
be limited to things that actually matter.

But hey, if you guys want to keep wasting time arguing about pointless
differences, be my guest.

Pete
Jul 24 '08 #100

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
3437
by: Rob | last post by:
i know javascript, vbscript, asp css and alot more and im only 14 i was wondering which is easier to learn php or cgi. any help?
42
3733
by: Bicho Verde | last post by:
I have now free time and money to do what I want :-) I have some basic skills in programming (C, Pascal, Macromedia Actionscript) but don't know exactly what to do in the world of programming. And also I don't know exactly why would I learn Python rather than C#, C++ or Perl. Basicaly I don't know where to start, if there is much to do or if it is has it seems and there is software to everything nowadays and so doesn't make sense to spend...
55
46028
by: Elijah | last post by:
I have read many of the topics on learning C++ or Java first. It seems like everyone says something different. I would like to know if I should learn C++ or Java. First a little about myself. I know PHP, BASIC, and of course HTML. I'll be 15 years old in September. I am interested in programming GUI applications. I am also interested in programming games. I know that I should learn C++ to program games, but would learning Java make the...
30
9443
by: Rhino | last post by:
I am giving some thought to applying for some jobs that want people with Java and C++ experience. I have been writing Java for several years and am fluent enough that I don't have to get help with Java very often. I have no real C++ experience and not much C experience for that matter. However, the core Java statements are "borrowed" from C and C++ has often been called "C with classes". It seems to me that it shouldn't take very long to...
8
4053
by: Hermawih | last post by:
Hello , I want your opinion about this . In order to say it clearly , I think I have to describe it in long sentences . I could consider myself as Intermediate/Advance Access Developer ; Intermediate/Advanced Database designer . Because of the requirements , I must create Web Application . Access Pages is not suitable for that so I think about learning VB Net / ASP Net . I am
21
2870
by: TAM | last post by:
Hi, I read that ASP.NET uses VB.NET instead of VBScript. I also read that ASP.NET is a subset of VB.NET. So if I learn VB.NET first then do I have the knowledge for programming ASP.NET applications or do I need to learn both VB.NET and ASP.NET. Thank you. TAM
85
4175
by: abhi | last post by:
hi everybody am new to this group and help me to learn C
31
2640
by: anand devarajan | last post by:
hi friends, im anand im just a beginner in c learning for the past two weeksnow i can write simple prgs can anyone help me to get well known to c lang so that i should able to write even tough prgs in c
34
3168
by: pandit | last post by:
hai all, i want to become a good programmer. one of my friends ( named "arnuld", he posts here infrequently), taught me Lisp. so i am not a programming beginner. i have heard these 2 points. i want to know how : 1. C gives you a strong base of Procedural style of programming which forms the basis of learning other paradigms e.g OOP
65
5314
by: Chris Carlen | last post by:
Hi: From what I've read of OOP, I don't get it. I have also found some articles profoundly critical of OOP. I tend to relate to these articles. However, those articles were no more objective than the descriptions of OOP I've read in making a case. Ie., what objective data/studies/research indicates that a particular problem can be solved more quickly by the programmer, or that the solution is more efficient in execution time/memory...
0
9697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7828
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4482
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3132
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.