C++ vs. C#

T

tonytech08

Very recently, I started a thread enquiring about the C++ object
model. All that remains in my mind about that thread is: "why would
you want to do that?", and "it's not portable" and probably other
irrelevancy (read, no real answers). I spoke of "Lightweight" vs.
"Heavyweight" objects. And of "representation in memory of an object"
as important.

Well guess what? I stumbled upon some C# description pages of structs,
classes and the like. Guess what? What seems to be in this NG as
"don't do that" and "non-portable", a multi-billion dollar company is
implementing their language in seeming lockstep to my preponderances
here.

Look it up: C# recognizes "lightweight" classes (structs) as relevant.
C# recognizes struct layout as relevant.

I'm not saying "I told you so". I'm also not saying C# is the way to
go. Just like where I began, searching for that simply elegant
language that C++ is not. I hope for something better (I'd do it
myself if I was young).
 
A

alfps

Very recently, I started a thread enquiring about the C++ object
model. All that remains in my mind about that thread is: "why would
you want to do that?", and "it's not portable" and probably other
irrelevancy (read, no real answers). I spoke of "Lightweight" vs.
"Heavyweight" objects. And of "representation in memory of an object"
as important.

Well guess what? I stumbled upon some C# description pages of structs,
classes and the like. Guess what? What seems to be in this NG as
"don't do that" and "non-portable", a multi-billion dollar company is
implementing their language in seeming lockstep to my preponderances
here.

Look it up: C# recognizes "lightweight" classes (structs) as relevant.
C# recognizes struct layout as relevant.

I'm not saying "I told you so". I'm also not saying C# is the way to
go. Just like where I began, searching for that simply elegant
language that C++ is not. I hope for something better (I'd do it
myself if I was young).

C# is a great language for its purpose. It's the Turbo Pascal of our
times. Incidentally with the same main creator.

C++ serves different purposes.

I don't understand what you're talking about wrt. light-weight missing
in C++, because in terms of memory usage or overhead you can't get
more light-weight. I think what you're writing must be due to
confusion. And I'm sure that if you simply ask about how to do X or Y
in C++ you'll get better answers than "don't do that". :)

Cheers & hth.,

- Alf
 
R

red floyd

tonytech08 said:
Look it up: C# recognizes "lightweight" classes (structs) as relevant.
C# recognizes struct layout as relevant.

And so does C++. If you have a POD struct, the layout is relevant.
 
I

Ian Collins

tonytech08 said:
Very recently, I started a thread enquiring about the C++ object
model. All that remains in my mind about that thread is: "why would
you want to do that?", and "it's not portable" and probably other
irrelevancy (read, no real answers). I spoke of "Lightweight" vs.
"Heavyweight" objects. And of "representation in memory of an object"
as important.
It's very important for us embedded and driver writers.
Look it up: C# recognizes "lightweight" classes (structs) as relevant.
C# recognizes struct layout as relevant.
So does C++, I couldn't write most of my code if it didn't.
I'm not saying "I told you so". I'm also not saying C# is the way to
go. Just like where I began, searching for that simply elegant
language that C++ is not. I hope for something better (I'd do it
myself if I was young).

So it runs on all of my embedded and non-windows targets, does it?

I can't see where using C# (about as non-portable as one can get)
differs from using platform specific features in C++.
 
B

Bo Persson

tonytech08 said:
Very recently, I started a thread enquiring about the C++ object
model. All that remains in my mind about that thread is: "why would
you want to do that?", and "it's not portable" and probably other
irrelevancy (read, no real answers). I spoke of "Lightweight" vs.
"Heavyweight" objects. And of "representation in memory of an
object" as important.

Well guess what? I stumbled upon some C# description pages of
structs, classes and the like. Guess what? What seems to be in this
NG as "don't do that" and "non-portable", a multi-billion dollar
company is implementing their language in seeming lockstep to my
preponderances here.

C# is only "portable" to the .NET platform, so it is easy to document
the "representation in memory", as there is only one.

One goal for the C++ language is to be efficiently implementable on a
wide range on systems. This is, in part, achieved by not specifying
the exact size of an int, or the binary format of a float, or the
exact layout of a class.
Look it up: C# recognizes "lightweight" classes (structs) as
relevant. C# recognizes struct layout as relevant.

C# can prescribe the struct layout, as there is only one choice. :)
I'm not saying "I told you so". I'm also not saying C# is the way to
go. Just like where I began, searching for that simply elegant
language that C++ is not. I hope for something better (I'd do it
myself if I was young).

No language is the best for all purposes.


Bo Persson
 
T

tonytech08

C# is a great language for its purpose. It's the Turbo Pascal of our
times. Incidentally with the same main creator.

I equate C# to be like Java. And Turbo Pascal was Borland's thing
(still is).
C++ serves different purposes.

But perhaps the features of the higher level C# under the microscope
herein are detrimentally ignored in C++.
I don't understand what you're talking about wrt. light-weight missing
in C++, because in terms of memory usage or overhead you can't get
more light-weight.

C# distinguishes between structs ("Lightweight classes") and classes
whereas C++ does not.
I think what you're writing must be due to
confusion.

Not at all (not mine at least, that is). See D&E for the reasoning
behind NOT distinguishing between structs and classes and see the
reference manual for C# for their take on structs, classes and
"lightweight objects" (and object field layout control also).
And I'm sure that if you simply ask about how to do X or Y
in C++ you'll get better answers than "don't do that". :)

All questions are not simple or simple to answer.
 
T

tonytech08

And so does C++.  If you have a POD struct, the layout is relevant.

You quoted 2 lines and only responded to one of them. C++ does not
recognize any sort of "lightweight class" concept. And the layout
control is non-existent whereas in C# it is formally defined.
 
T

tonytech08

It's very important for us embedded and driver writers.

I think it is important at a higher level also.
So does C++, I couldn't write most of my code if it didn't.

Again, addressing only the second line of a 2 line quote (?). See my
response to red floyd above.
So it runs on all of my embedded and non-windows targets, does it?

I was promoting the use of C#, I was just noting that that language is
addressing issues I have with C++ at the feature level. I still
consider C# as "Microsoft Java".
I can't see where using C# (about as non-portable as one can get)
differs from using platform specific features in C++.

Again, I'm not suggesting C# and C++ are in the same category (I
shouldn't have left out the fact that I view C# as "a Java killer
wannabe" in my original post).
 
T

tonytech08

C# is only "portable" to the .NET platform, so it is easy to document
the "representation in memory", as there is only one.

I think that level of guarantee should be a goal of some sort (whether
that means less widely defined programming languages or more
standardization of hardware). It may be idealistic, but maybe not.
One goal for the C++ language is to be efficiently implementable on a
wide range on systems.

Understood: it bows to every whim of hardware engineers and to non-
standardization of hardware.
This is, in part, achieved by not specifying
the exact size of an int, or the binary format of a float, or the
exact layout of a class.

I'm suggesting that is a problem to be solved.
C# can prescribe the struct layout, as there is only one choice.  :)

What about the "lightweight class" concept though? Address that.
No language is the best for all purposes.

Not yet. Or, at least, that state of language technology could be much
better than it currently is.
 
I

Ian Collins

tonytech08 said:
I think it is important at a higher level also.
Specifying a memory layout and portability are pretty much orthogonal.
Again, addressing only the second line of a 2 line quote (?). See my
response to red floyd above.
So? C++ recognises portability as relevant.

A POD struct in C++ is no different from a C struct and you can't get
much more lightweight than that.
Again, I'm not suggesting C# and C++ are in the same category (I
shouldn't have left out the fact that I view C# as "a Java killer
wannabe" in my original post).
Then what are you suggesting? If you want to get closer to an apples to
apples comparison, you have to consider all the platform specific
options offered by C++ compilers.
 
I

Ian Collins

tonytech08 said:
Understood: it bows to every whim of hardware engineers and to non-
standardization of hardware.
Don't be a fool, how can hardware be standardised? Different
requirements have different solutions. Do you want a 125W quad core
monster in your toaster?
I'm suggesting that is a problem to be solved.

No it isn't. What use is a 64 bit int on an 8 bit PIC?

C++ is a general purpose programming language, C# isn't.
 
T

tonytech08

Specifying a memory layout and portability are pretty much orthogonal.

I more than suggest that you are wrong. I suggest that is the problem
to be solved.
So? C++ recognises portability as relevant.

Say it right: it's a bitch to the hardware wielding.
A POD struct in C++ is no different from a C struct

Duh, that's the definition of a POD struct.
and you can't get
much more lightweight than that.

Extremism does not mean practicalism or "nicely correct" (akin to
"simply elegant").
Then what are you suggesting?  

I'm taxing you to heavily with what I consider fundamental? (No
offense intended). I'm not going to take this conversation to "the
meaning of life" level. Recognize the removal of C++ from the concepts
I think should be fundamental (or "guaranteed" or <something>..
something is missing). I gave examples of independed thought (ha!) by
Microsoft :)P). Tony says the world is not flat, so be it.
If you want to get closer to an apples to
apples comparison, you have to consider all the platform specific
options offered by C++ compilers.

I DO consider platforms. I'm quick to this: designed by committee is a
false leader.
 
T

tonytech08

Don't be a fool,

Don't be an extremist hoping I would fall for your propoganda/
opression. Are you a simpleton?! It's hardly one thing or the other
(the VERY first principle of engineering.. if you don't have it by age
3, then give it up), there is always AT LEAST a range (spherical
thinkers take heart)
how can hardware be standardised?  

Now we're talkin!! (Why did it take so long is the more relevant
question).
Different
requirements have different solutions.

Oh yeah, "everything, all the time". That's short term thinking and
that kind of thinking is good in appropriate context. "operations
manager" or "project manager". Most things built are upon that, and it
is wrong (see stock market crash of 2008).
 Do you want a 125W quad core
monster in your toaster?

That's why short term thinkers shouldn't be in charge of anything long
term.
No it isn't.  

Yes it is.
What use is a 64 bit int on an 8 bit PIC?

You proved my case.
C++ is a general purpose programming language, C# isn't.

Oh, now at the end of the post? k. Like I said, I recognize C# as
proprietary Java wannabe. I don't program at that level. But I don't
do device drivers or OSes either. But I would do both of those if I
had enough time left. Stop making it hard.
 
B

Bo Persson

tonytech08 said:
I think that level of guarantee should be a goal of some sort
(whether that means less widely defined programming languages or
more standardization of hardware). It may be idealistic, but maybe
not.

You have the problem of standardizing hardware that was already
designed before your programming language. Some of these "odder"
platforms are really important, like this one:

http://www-03.ibm.com/systems/z/

Do you think they will abandon 40+ years of backward compatibility to
support a new programming language? That's one reason why C++ says
that some operations depend on the underlying hardware.
Understood: it bows to every whim of hardware engineers and to non-
standardization of hardware.

Because the hardware was there already. If you want the language
implementable on the widest range of platforms, you have to allow for
some variations of the hardware.

Besides, as long as you stay within your own platform, the struct
layout doesn't have to be portable, just consistent. If you write
programs for embedded platforms, and I write transaction intensive
applications for the mainframe, portability isn't a problem in
practice, because it is not there. Bet you don't have DB2 on your
platform anyway. :)


Bo Persson
 
S

SG

Hello tonytech08,

you strike me as someone with a mindset heavily influenced by
languages like C# and Java. Let me bring a quote by B. Stroustrup to
your attention:

"Language comparisons are rarely meaningful and even less often
fair. A good comparison of major programming languages requires
more effort than most people are willing to spend, experience in
a wide range of application areas, a rigid maintenance of a
detached and impartial point of view, and a sense of fairness."

IMHO, this is very well put. You can find it in his FAQ. The reason
why I brought this up is because I think you don't (yet) qualify as
someone being able to do a fair comparison. No offense, I don't even
see myself in this position. Though, I have a fairly good Java
background and switched "recently" (2 years ago) to C++. Guess why: I
appreciate C++ for being better suited for number chrunching tasks.

I don't have a problem with some things left implementation-defined.
The headers <climits> and <limits> are there to query certain
properties at compile-time.

Also, you're using words like leightweight and heavyweight which I
don't attach much meaning to in the context of structs/classes. C++
has the idea of PODs (plain old data structures). What is it about
PODs that you don't find "lightweight" enough? In case you already
axplained what you mean exactly by lightweight and heavyweight forgive
me for missing that.

Cheers!
SG
 
E

eminhanif

Hello tonytech08,

you strike me as someone with a mindset heavily influenced by
languages like C# and Java.  Let me bring a quote by B. Stroustrup to
your attention:

  "Language comparisons are rarely meaningful and even less often
   fair.  A good comparison of major programming languages requires
   more effort than most people are willing to spend, experience in
   a wide range of application areas, a rigid maintenance of a
   detached and impartial point of view, and a sense of fairness."

IMHO, this is very well put. You can find it in his FAQ. The reason
why I brought this up is because I think you don't (yet) qualify as
someone being able to do a fair comparison. No offense, I don't even
see myself in this position. Though, I have a fairly good Java
background and switched "recently" (2 years ago) to C++. Guess why: I
appreciate C++ for being better suited for number chrunching tasks.

I don't have a problem with some things left implementation-defined.
The headers  <climits> and <limits> are there to query certain
properties at compile-time.

Also, you're using words like leightweight and heavyweight which I
don't attach much meaning to in the context of structs/classes.  C++
has the idea of PODs (plain old data structures).  What is it about
PODs that you don't find "lightweight" enough?  In case you already
axplained what you mean exactly by lightweight and heavyweight forgive
me for missing that.

Cheers!
SG
B.S was right its no use comparing languages because
obviosly some people like certain lingos more than other.

oh, yes i could say "i'm being impartial and not favoring one or the
other, its just one is plain better...."
but no one would believe me because you'd know that one or the other
is better(except those who think like me.

everyone is biased even if you don't admit it

Mr 3l1t3
 
J

James Kanze

Hello tonytech08,
you strike me as someone with a mindset heavily influenced by
languages like C# and Java. Let me bring a quote by B.
Stroustrup to your attention:
"Language comparisons are rarely meaningful and even less
often fair. A good comparison of major programming
languages requires more effort than most people are willing
to spend, experience in a wide range of application areas, a
rigid maintenance of a detached and impartial point of view,
and a sense of fairness."
IMHO, this is very well put. You can find it in his FAQ. The
reason why I brought this up is because I think you don't
(yet) qualify as someone being able to do a fair comparison.

More to the point, a comparison between languages only makes
sense if you specify why and according to what criteria you are
comparing them. I use several different languages in my day to
day work---each is better than the others for what I use it for.
No one language is perfect for everything. (I just finished a
project completely in AWK:). I could have written it in C++,
but for what I was doing, AWK was a lot easier.)
 
T

tonytech08

Hello tonytech08,

you strike me as someone with a mindset heavily influenced by
languages like C# and Java.

Not at all. I've never used either. But in seeing C# addressing some
issues/desires I have, it gives me confirmation that I'm on the right
track.

[ "Appeal to a higher authority" noted and snipped ]

Also, you're using words like leightweight and heavyweight which I
don't attach much meaning to in the context of structs/classes.

I use that terminology pretty much like it is used in the C# reference
documentation (but I have expounded on the concepts here in another
thread(s) recently).
C++
has the idea of PODs (plain old data structures).  What is it about
PODs that you don't find "lightweight" enough?  In case you already
axplained what you mean exactly by lightweight and heavyweight forgive
me for missing that.

JK and I went round-and-round on this topic in another thread recently
so review that first.
 
T

tonytech08

B.S was right its no use comparing languages because
obviosly some people like certain lingos more than other.

That's like saying: "Languages stagnate at some point and any further
"competitive analysis" is useless". Time for some people to get away
from the "everything that isn't already in the standard is a threat"
mentality.
 
T

tonytech08

More to the point, a comparison between languages only makes
sense if you specify why and according to what criteria you are
comparing them.  I use several different languages in my day to
day work---each is better than the others for what I use it for.
No one language is perfect for everything.  (I just finished a
project completely in AWK:).  I could have written it in C++,
but for what I was doing, AWK was a lot easier.)

The post wasn't meant to be a language comparison but rather a look at
some very specific features and to compare/contrast/evaluate/discuss
them. An industry driving toward more platform commonality would be a
good thing IMO. And maybe that's one of the knowledges we can get by
studying the "higher level" languagues such as C# and Java.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top