473,839 Members | 1,542 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


"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
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.
Yes, it is a burden. You have to remember the using block at every use of
the class. You have to remember which classes need using blocks and which
don't. And when you add a resource (unmanaged or IDisposable) to a class,
you have to add the IDisposable interface to that class and go back to every
single user and put in the using block.

That's not "a different way to write the same thing" any more than the empty
string is a different way to write a letter.

Or shall I claim that C++'s delete statement and the C# garbage collectors
are just different ways to call the deallocator? Of course they aren't, one
is automatic and the other is not.
>
>[...]
>>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.
That's why no real-world system is 100% GC-ed. Not .NET, not Java, not any
other. Files, for example, are part of a shared namespace and can't be
garbage collected. And no number of improvements to the garbage collector
are ever going to help with the problem of synchronizing file access. But
all the C# advocates keep pretending that you don't need deterministic
cleanup because you have GC. Yes, you do. A file access object needs to be
cleaned up by releasing a lock on the file, at the point the file access
ceases. Not when you run out of memory (if you run out of memory, if your
program doesn't deadlock waiting for the result of some process which needs
to access that file to continue.
>
>>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.
If it isn't possible in C#, then it obviously isn't just a difference of
syntax as you keep insisting, now is it?
>
Pete
Jul 27 '08 #131


"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
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.
C++ has quite a few brittle behaviors, but I'm not sure what you mean by
limitations on the use of stack-allocated classes.

Can you explain what you're talking about?
>
But it does, so I don't.

Pete
Jul 27 '08 #132
On Sat, 26 Jul 2008 20:00:45 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nos pamwrote:
[...]
>>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.

If it isn't possible in C#, then it obviously isn't just a difference of
syntax as you keep insisting, now is it?
If we were talking about whether "it's possible to create an object that
automatically performs cleanup when it becomes unreachable", then your
statement would be relevant. But we weren't. So it's just a straw man.

The fact is, it's not possible in C++ to do that either. So your straw
man is particularly pointless.

But it is fairly indicative of the direction the discussion has gone,
which is to say it's being corrupted into something altogether different
from what I was pointing out. I'm not going to waste my time trying to
argue a point I never made in the first place, nor in trying to drag the
point back to what I _was_ talking about when it's clear that's not what
anyone else really wants to talk about.

Pete
Jul 27 '08 #133
Peter Duniho wrote:
On Sat, 26 Jul 2008 20:00:45 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nos pamwrote:

[...]
If we were talking about whether "it's possible to create an object that
automatically performs cleanup when it becomes unreachable", then your
I think it is. Most objects in C++ are allocated in the way "structs"
are allocated in C# and they get automatically destroyed, if they aren't
reachable anymore.
statement would be relevant. But we weren't. So it's just a straw man.

The fact is, it's not possible in C++ to do that either. So your straw
man is particularly pointless.
In C++ you have heap allocation and about 8 additional different ways to
create an object.

The only allocation type you have to care about freeing in C++ is heap
allocation. The trick in C++ is to use objects not allocated on the heap
to care about the lifetime of the heap allocated ones.
Just like the "using" keyword in C# can be used to control the lifetime
of an object allocated in a control block.

The big difference in C++ is, that I'm not restricted to a control block
and don't have to care about the lifetime of the object, regardless
where I have allocated them. (for heap allocated objects you have to use
smart pointers surely)

It's just a different point of view:

- In C++ an object is responsible to care about it's resources
and free them in the destructor

- In C# the external code is responsible for calling Dispose
to free the resources of an object

-------------------------------------------------------------------

A small example:

List<objectl;
list<objectl;

In C++: l.erase(...) -the object gets automatically destroyed
(if no heap allocated object is used)

In C#: l.remove(...) -the object is not disposed. If you wish
to you have to call it manually

-------------------------------------------------------------------
For allowing the same automatic deallocation of objects in C# like in
C++, in C# you would need:

- Overloading of assignment operator or at least protecting it
- Destructor for structs
Andre
[...]
Pete
Jul 27 '08 #134
In article news:<O#******* *******@TK2MSFT NGP02.phx.gbl>, Larry Smith wrote:
C++ is significantly more demanding to get right
from a purely mechanical perpsective alone.
C++ is harder, yes ... but is it actually hard in any absolute sense?

Given that your programs will never work correctly if you employ stupid
programmers you are going to have to employ smart people anyway ... so you
might as well let them use powerful tools.

I don't consider that C++ is harder than other languages by a sufficient
degree for that to be any reason not to prefer it over those languages.
There may be other reasons to choose another language over C++ for a
particular project ... but the fact that it is complex should not be one of
them.

If you don't agree with that we shall just have to agree to differ.

Cheers,
Daniel.

Jul 27 '08 #135
>C++ is significantly more demanding to get right
>from a purely mechanical perpsective alone.

C++ is harder, yes ... but is it actually hard in any absolute sense?

Given that your programs will never work correctly if you employ stupid
programmers you are going to have to employ smart people anyway ... so you
might as well let them use powerful tools.

I don't consider that C++ is harder than other languages by a sufficient
degree for that to be any reason not to prefer it over those languages.
There may be other reasons to choose another language over C++ for a
particular project ... but the fact that it is complex should not be one
of
them.
While I believe you honestly see things this way, none of what you've said
stands up to even mild scrutiny.
Jul 27 '08 #136
On Sat, 26 Jul 2008 23:39:58 -0700, Andre Kaufmann
<an************ *********@t-online.dewrote:
Peter Duniho wrote:
>On Sat, 26 Jul 2008 20:00:45 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.no spamwrote:
[...]
If we were talking about whether "it's possible to create an object
that automatically performs cleanup when it becomes unreachable", then
your statement would be relevant. [...]

I think it is. Most objects in C++ are allocated in the way "structs"
are allocated in C# and they get automatically destroyed, if they aren't
reachable anymore.
All due respect, C++ (not counting the GC/managed add-ons of C++/CLI)
doesn't even really have the concept of "reachable" . So any claim about
what C++ does _when_ something becomes "unreachabl e" is necessarily wrong,
or at the very least inaccurate.

I appreciate that RAII doesn't exist in C#. But it's just a way of doing
something. It's not the only way, and C# simply has different idioms for
managing resources. _Occasionally_ where those idioms have to interface
with APIs designed for C++ code, there's the appearance of friction. But
in most cases, simply adjust one's approach to the design resolves that,
and where it doesn't, C# still does allow for code that is semantically
equivalent, albeit in a slightly more verbose way.

I understand how tempting it is for people to just assume I don't have a
clue about what I'm saying. I also realize that, having only used C++ for
a decade or so before exploring C#, I may have less C++ experience than
others involved in the discussion. But I have found that C# and its lack
of RAII hasn't impeded my usage of C# one iota, not even when dealing with
code that has to interact with the unmanaged, C/C++-centric paradigms of
the Windows API.

Finally, just as an aside: I find the "smart pointer" example particularly
weak, as reference counting is itself overused and fragile. I suspect
that there are actually lots better examples of using RAII in powerfully
useful ways, and I think those who are so enamored by it would do well to
explore and expound on those examples, rather than sticking to reference
counting.

And with that, I'm done. Thanks for your time and interest.

Pete
Jul 27 '08 #137
Giovanni Dicanio wrote:
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 :)
And it never will.

Experience has shown that even though the C++ way of destructors
will work fine with perfect code, then in practice the apps leaks
resources.

Bad programmers or that the language is too difficult for average
programmers in reality means the same.

Arne
Jul 28 '08 #138
Ben Voigt [C++ MVP] wrote:
C# is just as capable of hanging, leaking memory, and having
non-deterministic behavior as C++.
I don't believe that.

C# has much less undefined and implementation specific behaviors
than C++.

C# has array index checks and no pointers (assuming not using unsafe).

The language is is in general simpler to understand what is going on.

Those hard to find memory overwrites you can get in C/C++ or mysterious
memory leaks is not possible in C#.
And most C# developers have bought the
company line that .NET prevents memory leaks so they haven't the slightest
clue how to begin looking for one.
I agree that most C# developers does not have a clue about how to
find them.

Because they happen so rarely.

For those that know where to look it is usually easy to find, because
the places to look are pretty limited.

Arne
Jul 28 '08 #139
Daniel James wrote:
In article news:<O#******* *******@TK2MSFT NGP02.phx.gbl>, Larry Smith wrote:
>C++ is significantly more demanding to get right
from a purely mechanical perpsective alone.

C++ is harder, yes ... but is it actually hard in any absolute sense?

Given that your programs will never work correctly if you employ stupid
programmers you are going to have to employ smart people anyway ... so you
might as well let them use powerful tools.
The concept of hiring smart programmers is fundamentally flawed.

The reality is that companies have to hire the programmers they
can get. And that means a few smart, a lot average and a few hopeless.

The hiring only smart does not work at the industry level.

Arne
Jul 28 '08 #140

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
10585
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10647
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
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...
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.