473,839 Members | 1,611 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 4543
Peter Duniho wrote:
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.
It's quite objective. In C++, the burden is on the library developer, the
user needs no extra syntax to benefit from automatic cleanup.
>
>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
Nothing could be further from the truth. Lazy (or deferred, if you prefer)
cleanup breaks access to shared resources, and does so
non-deterministical ly.
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.
No, in C# it's not possible to create an object that automatically performs
cleanup when it becomes unreachable. You can only do so (1) manually, or
(2) when its memory is reclaimed.
>
Which only brings us back to your purely subjective complaints about
"using".

Pete

Jul 24 '08 #111
Peter Duniho wrote:
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.
The C# way is brittle. If C# let you use a using statement with types that
don't support IDisposable, then it would be better. But right now, adding
IDisposable support to an existing class is always an impermissible breaking
change.

In C++, you can add a destructor without any changes to the code which
references the class.

That's a much bigger issue than saving a single line of code.
Jul 24 '08 #112
Peter Duniho wrote:
On Thu, 24 Jul 2008 11:23:49 -0700, David Wilkinson
<no******@effis ols.comwrote:
>Not only is the "using" mechanism less convenient/elegant for the
client of the class than RAII (not to mention the possibility of
forgetting to do it), but a C# Dispose'd object can still be used
(unlike a C++ object that goes out of scope or is delete'd).

I was comprehending your post until "or is delete'd". There's
nothing in C++ to stop someone from trying to use an object that's
been deleted, and depending on how the memory was allocated and what
the class does in its destructor, doing so might even work for awhile.
C++ delete calls the implementation of 'operator delete' after running the
destructor, which can mark the memory with a pattern (or on some CPUs, even
set up data breakpoints to trap any future access to that memory) which in
debug builds would detect use after free. You can use something like
electric fence which will deallocate the segment, generating a segfault on
any future access to that object. All of which can be done without any
changes to the class being protected.

So no, these aren't "in C++", because one of the prime ideals of C++ is "you
don't pay for what you don't use". You turn on these features during
debugging, and perhaps in extremely critical environments where failure
detection is more important than efficiency you might leave them on in the
release build. In all other circumstances, you convince yourself through
thorough testing that these sorts of bugs have been eliminated, and disable
the checks.
Jul 24 '08 #113
On Thu, 24 Jul 2008 15:14:38 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nos pamwrote:
>>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.

It's quite objective. In C++, the burden is on the library developer,
the
user needs no extra syntax to benefit from automatic cleanup.
You don't seem to have read the statements you quoted.

I'm talking about the question of the syntax itself, not the semantics.
The need to include a "using" statement is not a "burden". It's just a
different way to write the same thing.
[...]
>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

Nothing could be further from the truth.
Ah, more hyperbole. Yup...that really makes your point compelling.
Lazy (or deferred, if you prefer)
cleanup breaks access to shared resources, and does so
non-deterministical ly.
In a 100% GC-ed system, a resource that's eligible for "cleanup" is not
"shared" by any code anywhere, by definition. Your statement makes no
sense.
>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.

No, in C# it's not possible to create an object that automatically
performs
cleanup when it becomes unreachable.
I never said it was. But nice straw man.

Pete
Jul 24 '08 #114
On Thu, 24 Jul 2008 15:17:05 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nos pamwrote:
The C# way is brittle. If C# let you use a using statement with types
that
don't support IDisposable, then it would be better. But right now,
adding
IDisposable support to an existing class is always an impermissible
breaking
change.

In C++, you can add a destructor without any changes to the code which
references the class.
If C++ didn't have its own brittle behaviors (including limitations on the
use of stack-allocated classes), I might think your point has some merit
here.

But it does, so I don't.

Pete
Jul 24 '08 #115
On Thu, 24 Jul 2008 15:22:47 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nos pamwrote:
[...essay on C++ built-in testing aids...]
In all other circumstances, you convince yourself through
thorough testing that these sorts of bugs have been eliminated, and
disable
the checks.
Yes, I'm aware of all of the debugging aids C++ includes so that you can
hopefully detect coding errors that simply aren't possible in C#.

As far as I'm concerned, you're just making my point for me.
Jul 24 '08 #116
Peter Duniho wrote:
On Thu, 24 Jul 2008 12:30:34 -0700, Andre Kaufmann
<an************ *********@t-online.dewrote:

[...]
But you can include reference counting in the C# object if you want.
You can even implement a "smart pointer" class that uses Dispose() to
decrement the counter and call Dispose() on the wrapped object if it
reaches 0.
I can include reference counting, but I can't use smart pointers. I
prefer GC memory handling, but for resources GC can't be used
effectively, because often resources have to be released directly.
I do a lot of multi threaded programming, there I permanently have the
need of some kind of reference counted resource handling.

[...]
But there's nothing about C# that precludes using that
technique if you find yourself i
If you could add methods to value structures in C# I would agree. But
currently in C# you have to either use a temporary object in combination
with using or call the AddRef / Release functions by hand.

Perhaps it wouldn't be a good idea to add the complexity of C++ which
allows RAII to C#, but some kind of simple automatism would IMHO help too.

E.g. the temporary objects could be replaced by some kind of using which
calls specified methods of an object.

Pseudo code:

MyObject o; // member variable
....
autocall(o) --calls enter / leave methods automatically
{ // call o.enter()
} // call o.leave()

Pete
Andre
Jul 25 '08 #117
On Thu, 24 Jul 2008 22:43:52 -0700, Andre Kaufmann
<an************ *********@t-online.dewrote:
Peter Duniho wrote:
>On Thu, 24 Jul 2008 12:30:34 -0700, Andre Kaufmann
<an*********** **********@t-online.dewrote:
[...]
But you can include reference counting in the C# object if you want.
You can even implement a "smart pointer" class that uses Dispose() to
decrement the counter and call Dispose() on the wrapped object if it
reaches 0.

I can include reference counting, but I can't use smart pointers.
Why not?
I prefer GC memory handling, but for resources GC can't be used
effectively, because often resources have to be released directly.
I do a lot of multi threaded programming, there I permanently have the
need of some kind of reference counted resource handling.
For what it's worth, I've done a fair amount of multi-threaded programming
in C# without needing ref-counting.

Not that I agree that ref-counting can't be done in C#, but I've found
that in many cases, what's really needed is a different way of looking at
the problem.
>[...]
But there's nothing about C# that precludes using that
technique if you find yourself i

If you could add methods to value structures in C# I would agree.
I don't know what you mean here. What methods do you want to add? To
what structure? How would that help?
But currently in C# you have to either use a temporary object in
combination with using or call the AddRef / Release functions by hand.
How is a smart pointer not a temporary object?
Perhaps it wouldn't be a good idea to add the complexity of C++ which
allows RAII to C#, but some kind of simple automatism would IMHO help
too.

E.g. the temporary objects could be replaced by some kind of using which
calls specified methods of an object.

Pseudo code:

MyObject o; // member variable
....
autocall(o) --calls enter / leave methods automatically
{ // call o.enter()
} // call o.leave()
Why not just create a smart-pointer-like class or struct that does that
with the "using" statement? Adds a ref when the object is created,
decrements the ref on disposal, zero ref-count causes disposal of the
wrapped object.

Maybe I'm just being obtuse, but I don't see what the big problem is.

Pete
Jul 25 '08 #118
In article news:<Od******* *******@TK2MSFT NGP02.phx.gbl>, Mc wrote:
Yes... the big difference is that with C#, errors manifest themselves
as incorrect output or recognizable error messages rather than random
crashes or memory leaks.
At least you KNOW there's something wrong when you get a random crash ...
that incorrect output you get from your C# program is really much more
dangerous.

I think you and Larry and others here blowing the C# trumpet are vastly
over-stating the case about C++ being hard to use and hard to get right.
The fact is that bad programmers will write bad code in any language, and
if you want good code you have to employ good programmers. Once you have
those your problems will start to go away -- whatever language you are
using.

Of course, you need good management, too. Bad management and irrational
budgetary constraints can ruin a project just as easily as bad programming.

Cheers,
Daniel.
Jul 25 '08 #119
In article news:<OP******* *******@TK2MSFT NGP04.phx.gbl>, Larry Smith wrote:
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.
I think the answer to that is "it looked too hard at the time" ... and IIRC
that constraint is to be removed an some future version of the standard.

I certainly agree that the ability to use a local class as an argument
would make the use of for_each much more natural.
C# allows me to use anonymous methods which is so
much cleaner
You can achieve the same sort of effect with boost::lambda
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.
I think it's /only/ the very experienced developers (and those who aren't
but think they are -- which is more worrying) who "continuous ly bend their
minds out of shape" looking for new ways to use the expressive power of the
language. These are the library builders, the Boost developers, the
Alexandrescus of the world ... most C++ programmers just /use/ their work
and are grateful for the way that it makes their lives easier and more
pleasant.

Cheers,
Daniel.

Jul 25 '08 #120

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
9854
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
1
10645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10290
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7015
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
5681
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
5865
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
4063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3131
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.