how does C# compare to C++ and VB

A

Arne Vajhøj

Peter said:
Ah, yes...like Ben's "self-evident" comment. Suffice to say, I don't
find that sort of expression a valid debating style. "Should be
obvious", "self-evident", etc. are just crutches for people who don't
feel like proving their point.

Well - I actually offered a demonstration below. Which makes your
comment above look rather stupid.
What would make you think that a single data point in any way represents
a valid study?

Last 10 so ?
I find myself doing it somewhat regularly, when dealing with different
code examples different people post. The context isn't about getting a
program to work; it's about understanding what someone else has written.

It is quite common to want to do something manually to learn from it,
but it is rather irrelevant in a discussion of whether it is easy to
do automatically.

Arne
 
P

Pavel Minaev

But a simple one you should be very familiar with is
EqualityComparer::Default

Just you try to make a Dictionary in .NET that supports *any* Key class or
struct without a virtual call to test equality.

If you mean doing so while keeping the existing interface of
Dictionary, then it's possible, though tricky - once you get the
comparer, you create dynamic methods for all the search operations
that directly invoke the most derived implementation of
IComparer<T>.Compare on the actual comparer instance. In effect, you
still have dynamic dispatch, but it's moved outside the loop where it
kills performance.

In fact, I wouldn't be surprised if JIT was able to lift virtual
method resolution outside the loop on its own, without any dirty Emit
tricks.

On the other hand, if you mean writing my own class with interface
different from that of Dictionary, that's quite doable, too, and will
actually look very similar to std::map:

class Map<TKey, TValue, TComparer>
where TComparer : IComparer, new()
{
readonly TComparer comparer = new TComparer(); // calls to Compare()
on this won't be virtual, and will likely be inlined
}

This is particularly efficient if you then pass an empty struct,
rather than class, as TComparer.
 
B

Ben Voigt [C++ MVP]

Forgive me if I fail to see the point of the analogy. The
I never said it does. As far as your example being "self-evident",
that's in the eye of the beholder. Suffice to say, I disagree with
your claim of "self-evident", and that is in fact the crux of the
point here.

Before we forget, here was the example:

"C++ is an almost 100% superset of C89, yet C89 and C99 are far closer to
each other in every respect than to C++."

Do you want to contest that?
[...]
Just you try to make a Dictionary in .NET that supports *any* Key
class or
struct without a virtual call to test equality. I suspect that the
.NET JIT
is coded to specifically recognize Dictionary or at least
EqualityComparer::Default and perform a spot optimization, because
doing the
virtual call would kill performance. C++ templates easily
implement the different comparison cases at compile-time with no
runtime overhead, using
type traits and partial specialization.

You seem to be making the assumption that this difference represents
"more power". I simply disagree. And again, this is because you are
trying to argue a point ("a language is more powerful than another")
before we have decided to agree on the definition of "more powerful".
You have a priori defined "more powerful" in a way that supports your
claim, so of course your claims seem self-evident to you. But they
fail to convince someone who doesn't agree on the definition.

The other issue is that I've never said that C++ doesn't have features
that C# has. That's not the point. I readily admit the languages are
different. The question is whether C++ has ALL the features C# has. As
far as I know, it doesn't. Certainly the C++ I'm familiar with
doesn't.
All that said, your religious view of C++ as _the_ superior language
is intractable, and it's this sort of religious view that I find
pointless to try to debate. Tautological arguments are the norm,
openness to compromise is absent, and I detest such discussions. So
I won't bother you further on the point.

I didn't say "superior". Simplicity and barriers to making mistakes are
advantageous in their own right. I said "almost superset" and "more
powerful" and I stand behind that claim.
 
B

Ben Voigt [C++ MVP]

Pavel said:
If you mean doing so while keeping the existing interface of
Dictionary, then it's possible, though tricky - once you get the
comparer, you create dynamic methods for all the search operations
that directly invoke the most derived implementation of
IComparer<T>.Compare on the actual comparer instance. In effect, you
still have dynamic dispatch, but it's moved outside the loop where it
kills performance.

Congratulations, you can do it by *re-implementing the C++ rules for
templates*. Pretty cool that .NET gives you the dynamic codegen to let you
do it, but still waaaay more difficult than using C++ to do it.
In fact, I wouldn't be surprised if JIT was able to lift virtual
method resolution outside the loop on its own, without any dirty Emit
tricks.

On the other hand, if you mean writing my own class with interface
different from that of Dictionary, that's quite doable, too, and will
actually look very similar to std::map:

class Map<TKey, TValue, TComparer>
where TComparer : IComparer, new()
{
readonly TComparer comparer = new TComparer(); // calls to Compare()
on this won't be virtual, and will likely be inlined
}

This is particularly efficient if you then pass an empty struct,
rather than class, as TComparer.

They will be virtual unless TComparer is a struct. Which, unfortunately,
EqualityComparer<T> isn't, and EqualityComparer<T>.Default isn't.

But honestly, you've done a great job of working within the confines of .NET
and making the JIT work for you.
 
A

Arne Vajhøj

Peter said:
The only person having that discussion is you.

Actually it was you that wrote:

#What would make you think that a single data point in any way
#represents a valid study?

in response to me talking about automatic conversions.

So yes - you were actually also participating in that discussion.

Arne
 
D

Daniel

(although closures are coming soon to C++ as well). But none of them
respresent a truely different paradigm, such as TMP is, so ultimately most


What does TMP stand for?

Daniel
 

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