C# vs. C++

H

Hendrik Schober

Andre said:
Arne said:
[...]
Boost is a good, cool library - sure. But these libraries get somewhat
bloated, because of all the template stuff and compilation slows down
more and more.
Compilation speed is usually not important.

Why ? For RAD tools it's IMHO essential and if 1000 developers wait
daily an hour for compilation they are loosing simply 1000 hours of
development time, besides the energy wasted.

You can always throw processing power at this problem
(www.xoreax.com). This worked great for a company I used
to work for and turned 60mins into 12mins.
OTOH, you cannot throw processing power at debugging. So
easily creating correct code is more important than fast
compilation.
[...]
Andre

Schobi
 
H

Hendrik Schober

Daniel said:
[...]
The fprintf and sprintf functions will always be slow as they have to
parse the formatting string each time as well as producing output, so I
wouldn't expect them to do well. I'd expect the iostreams version to be
a good bit quicker [...]

Usually iostreams are implemented using the 'printf()' family,
so it's very unlikely they're faster. It's sad, because with all
the type info known at compile-time streams ought to be faster
than 'printf()', but that potential was never used. Dietmar Kühl
once had an implementation that didn't do this and was regarded
fast, but for some reason it never took off.
[...]
Daniel.

Schobi
 
H

Hendrik Schober

Rudy Velthuis said:
Still a long time. <g>

Yes, but this was several MLoC. And usually you don't
have to compile /everything/ during writing/fixing
code.

Schobi
 
J

Jon Skeet [C# MVP]

Not really. First bit says the JVM is only meant to be for Java, second
bit says that hasn't stopped people using it for other languages
(without Sun's blessing, at least in the earlier cases).

I think we'll have to agree to disagree about the wording that started
this subthread then. To me, Java *is* an "intermediate code engine
targeted by more
than one source language". It just isn't an intermediate code engine
*designed* to be targeted by more than one source language.
Yeah ... Sun would probably say that the JVM has no opcodes that can be
used to support pointer arithmetic (a) because Java doesn't need them,
and (b) because they're potentially unsafe; but I bet they regarded the
fact that that meant you couldn't target it from C or C++ as an added
bonus.

Not sure. I strongly suspect that treating Sun as a single entity
doesn't really work here. Different employees of Sun are likely to
have different attitudes.

There's a big difference in mindset, though, between what Sun did with
Java (we've just reinvented p-code and it's just for our new language
called 'Java' -- so we've called it the "Java Virtual Machine") and what
Microsoft did with .NET (we've just reinvented p-code (again) -- and we
want it to be able to run any language you like, and we want third
parties to port their languages to it ... oh, and we've just developed a
new language called C# that will target this and nothing else, but don't
you worry about that).

Agreed, although I don't think MS ever claimed that they want you to
be able to run "any language you like" - it needs to have a certain
degree of similarity to the underlying platform. (Some people have
criticised it for precisely this reason, in fact.)

Does anyone actually use Eiffel.NET, BTW? I haven't heads anything about
it since it was heralded as one of the first examples of a third-party
language targeting the CLI, way back when.

I haven't heard of much use, but that's a good example of where the
platform gets in the way of the language. From what I remember,
multiple inheritance in Eiffel.NET is a bit of a kludge with various
limitations. In other words, .NET doesn't have the same set of
limitations as Java when it comes to porting languages to it, but
there certainly *are* limitations.
Yes, I agree. Sorry, I think you missed my point -- I should probably
have said "but" or "whereas" or something in there -- Most of the
languages mentioned are just research toys, BUT (I went on to say)
Jython and Groovy (and JRuby, if you say so, I know less about that) do
have real-world uses.
Righto.

I hadn't seen Scala before ... it looks very Java-like (perhaps
unsurprisingly) and I'm not sure quite what makes it different, on a
first glance. I'll obviously have to read further.

From what I've seen it has some similarities to C# 3, but taken a bit
further. It supports a functional style of programming much more
neatly than Java does. It may also have some dynamic aspects, although
I can't remember offhand.
I certainly don't know much about it ... usually it's been discussed as
a way to bind databases to C# code (and it all seemed very reminiscent
of the hype that ODBC got when it was new). I'll look further, thanks
for the "heads up".

Yup, it's unfortunate that the SQL side of things is what's gained the
most attention. I wouldn't like to try to describe it in just a few
sentences - I'm sure you'll have more joy investigating it properly :)

Jon
 
H

Hendrik Schober

Daniel said:
That's obviously an easy-but-naive implementation, I'd hope that as C++
continued to mature quick hacks like that would disappear.

Certainly the current Visual C++ (Dinkumware) runtime doesn't seem to
use sprintf.

That would have been a pleasant surprise. But outputting
an 'int' using '<<' certainly lands you in 'sprintf()'. :(

Schobi
 
P

Peter C. Chapin

Daniel said:
OTOH A remember being very impressed with the AppletMagic Ada for JVM
when I first looked at it -- too long ago now -- but I'm not sure it's
still around. Ada is a real language (one that really deserves to be
better known outside the war-toys factories) and it's interesting that
you can run it well on the JVM.

Also AdaCore has recently developed a version of the GNAT Ada compiler
that targets the CLR. I haven't played with it much (yet), however.

Peter
 
A

Andre Kaufmann

Thanks for the link.
Yes, but this was several MLoC. And usually you don't
have to compile /everything/ during writing/fixing
code.

Yes, agreed. But in a large team it's still a pain to start the build
process over and over again, because in your local project it compiled
fine but in another project some weird side effect causes a compilation
error.

Even if I use processing power, C++ still compiles way more slower than
most of the other languages do. Currently our build time is 30 minutes,
which has been 3 hours before we switched to a quad core system.

I could live with the compilation time, if the slow down would be caused
by the complex syntax of C++ only and if that would be outweighed by the
productivity increase by all the goodies of C++ (templates, RAII etc.).
But since the slow down isn't caused by the complexity, but because the
compiler has to compile code over and over again, I think it's a huge
loss of productivity for - nothing - .

I hope modules will fix the problem, at least they should if I
understood them correctly. But they have been delayed again and I think
it will need 5+ years till they will be part of the standard.

There should be IMHO something like boost is for the C++ standards
library, a fast track standard for the C++ language, which takes the
risk of changes and if the features are stable, the could be taken over
by the "stable" C++ standard. I know that GCC has taken over somewhat
this part, to see the stability of new features. But unfortunately this
doesn't help me that much, since other compilers don't support this
experimental features.

Andre
 
A

Andre Kaufmann

Daniel said:
I had it half in mind to repeat your tests and try to see where the C++
versions were taking their time ... I obviously can't do that very
meaningfully if I can't know that I'm using the same tools.

You are using one of the same C++ compiler ;-). You can do a simple test
of your own, write integers to a file with iostreams and with sprintf
with the latest Microsoft VC/C# compiler. Sprintf should be faster, C#
fastest.
I guess at least the C# compiler must have been a Microsoft one <smile>

Yes, there are other alternatives, but their heap management is IMHO slower.
[...]
I haven't got a VC9 installation handy ... but in VC8 the iostream
implementation certainly doesn't use sprintf. That would be a very

I'm sorry to say, but it does.
Have a look at the file "...VS2005\VC\crt\src\xlocnum".
Search for "ld".
Set a break point on this function and then use a fstream object and
write an integer to it to see by yourself.

suboptimal implementation when you already know the type of the value
that's to be formatted. The overhead of printf is quite considerable as
the "%d" (or whatever) has to be interpreted on every call.

Yes. I think it is done for consistency reasons, to use the same
formatting.
There is certainly some overhead associated with streams, too, but it
should be less than that with the ?printf functions, except in a very
naive implementation.

You're right that localization imposes some overhead with streams -- but
not for printing integers.

The problem is only, C# (.NET) deals with localization too and the
strings are Unicode - meaning it's using 16 Bit characters.
So I'm somewhat disappointed from C++ performance (in this regard), why
do I need localization for a simple integer ?
..NET isn't (generally) faster in large projects, because the memory
footprint is still somewhat higher - IMHO.
[...]
boost::format( "%d" ) % charvar

boost::format takes the type (char) from the variable and ignores the
type implied by the %d, so you get a character rather than a number. The
only way to get the result you wanted is to cast the variable to an int
(yuk).

Didn't know that boost::format supports the printf formatting syntax
too. I used only the placeholder style: %1% %2%
[...]
I agree entirely that modules will be a better solution ... but I don't
think that means that we shouldn't also try to improve tool support for
efficient compilation of today's sourcecode. There are millions and
[...]

Yes agreed. But on the other side I once asked in the C++ forum why C++
still doesn't support >override<, while all other languages do.
I had a huge problem, with template virtual base classes and somewhere
in the object hierarchy the base function hasn't been overridden and the
compiler logically didn't complain about it. Fortunately I had VC which
has a proprietary extension supporting override for native code too to
ensure that the compiled code does what I expected it to do.

I was only told in the forum that this is a minor problem and therefore
there is no need for override to get into the next standard.
I don't use this coding style anymore, but anyways if I have to use a
class library which uses this style I can't control it's functionality
at compile time.
[on "Macros are useful too"]
I know and agree. I use them too. But they could have been restricted
to have an effect on one single header file or must be globally
defined.

That wouldn't be compatible with C. In particular it wouldn't be
compatible with the way that C (and C++) allows you to redefine the
NDEBUG macro and include assert.h repeatedly to turn ASSERT macros on
and off throughout a compilation unit. That's a very widespread usage in
some codebases, and restricting the use of macros would break it.

Yes, but in this case and for this files I explicitly could activate the
old behavior. Or the other way round - doesn't matter.

On the other side a global definition of the assert macro and local
redefines would to the trick too.
They *could*, but they haven't been. If you were to add a
metaprogramming facility to C# it wouldn't be the C# that we know today.
OTOH if you were to design a metaprogramming facility to add to C# the
resulting language might be a bit nicer to use than C++ is now ... using
C++ templates for metaprogramming (rather than just for implementing
generics) is a bit of a hack -- but it's a very powerful hack, and the
fact that it has been used so much shows how much people want to do this
sort of thing.

They are powerful for sure, but if they are used too much the code gets
unreadable and hard to debug and maintain. By the way 'D' has IMHO a
good, way more readable implementation of meta templates directly in the
language.

E.g:

template Function(long n)
{
static if (n < 0) .....
else ......
}

I'm not suggesting that C++ is the best language imaginable, just that
it is the best language available today for solving most of the
programming problems with which I find myself faced.

I would perhaps migrate to 'D' if I could use my C++ more easily.
[...]
It's not that template couldn't be implemented by other languages, just
that -- at present -- they aren't.

As I wrote above, IMHO the implementation in 'D' is superior.
Even if they were I'm not sure that you would be able to achieve
inter-language compatibility with templates, as (in C++, at least) they
are source-code abstractions, and you need a C++ compiler to make use of
them.

To problem is templates aren't strong typed, in contrast to generics. If
they would be used for multiple languages e.g. in .NET and if the code
would be compiled at startup of the application, as it's done (normally)
in .NET, the code could fail to compile.
But it certainly could be done - just remove the compilation checking
from generics and you potentially would have it ;-).
Maybe if someone were to come up with a standard for some sort of
meta-code representation then different languages would be able to share
template representations that had been compiled (or part-compiled) down
to that meta-code. The "export" feature in C++ does something along
those lines, but AIUI the intermediate form is still largely C++.

Unfortunately "export" doesn't do what it's meant to be. It doesn't
separate translation units. But yes, I agree that templates could be
supported over language boundaries too.
I said Andrei had been talking about a mixture of C++ and functional
programming, didn't I? Well, it's D not C++. Still interesting, though.

Hm, the headline is about the 'D' language in it's current
implementation version 2.0.
Cheers,
Daniel.

Cheers,
Andre
 
A

Andre Kaufmann

Daniel said:
Took my a while to get there (I was searching for "ld" without the
quotes, which didn't help) but I see you're right.

Sorry, my fault - single quotes have been misleading.
[...]
why do I need localization for a simple integer ?

Good question ... I'm not sure whether localization covers things like
using different chars (Arabic?) for digits ...?

I don't know for sure - I only know that Romans have written them
differently. I assume that all other languages use the same digits - if
I'm not totally wrong.
I don't think that's been shown conclusively. When Daveed Vandevoorde
implemented export in the EDG compiler he changed his opinion on the
usefulness of the feature ... unfortunately most people (I might say,
cynically, most of those who don't want to spend time and money
implementing the feature) still adhere to the notion that export would
not offer much advantage.

I too don't think export isn't worth the time (2 man years of coding).
It would be better to put the time into modules instead.
I think modules will offer more advantage, but it's not clear that
export really is as bad as most pundits seem to be saying.

Perhaps not bad, but it doesn't offer more than modules - so IMHO there
is no need to implement both - (assuming that the code base of STL and
boost must be changed either - for export support or for modules).
Cheers,
Daniel.

Cheers,
Andre
 
A

Angus

Anyone that thinks an operating system would be written in C# is seriously
in cloud cuckoo land.

Most operating systems I guess still have a lot of C code. But suspect some
parts being re-written in C++.

There are a ton of reasons why C++ is more flexible and powerful than C#.
Same reasons that C++ is more flexible and powerful than Java.

If you wanted to write a general purpose program with a small footprint,
with good performance then C++ is a great choice.
 
B

Bo Persson

Daniel said:
Kaufmann wrote:

Does that double-negative mean you DO think it IS worth the time?
I'm guessing not, but I can't be sure.

That 2 man years figure that gets bandied about comes, I think, from
Daveed's account of the time it took him. He's a seriously smart guy
so it might take other implementors a little longer ... BUT that
time, AIUI, includes the time taken to implement two-phase lookup
which he found was needed to support export. I think two-phase
lookup is going to have to be done anyway ... so the 2-man-year
figure is misleading.

I could imagine that a company with 78000 employees could actually
afford a 2 man year project, if they really wanted to. .-)

Saying that implementing this language feature is too expensive, while
simultaneously designing several other entierly new languages, doesn't
really maximize your credibility.


Bo Persson
 
A

Andre Kaufmann

Daniel said:
[...]
I don't think you quite understand ...

The Romans used an entirely different system for writing numeric
quantities anyway. In Arabic, numbers are written in base 10 using 10
different digit symbols, but they use different symbols from ours
(and, just to be confusing, their symbol for '5', looks a bit like our
'0').

Hm, we have to translate our applications in Arabic too, but I didn't
recognize different numbers, however I don't view our applications in
Arabic that often, since I'm not involved that much in GUI applications.
I think you mean the East-Arabic numbers.

But anyways since they are base 10 too isn't it just done with either
using a different font or changing an offset for the base number,
depending on the locale settings.
I mean - it shouldn't have an negative impact effect on the performance,
since the algorithm is basically the same.
See Unicode code points U+0660 to U+0669.

[...]
I too don't think export isn't worth the time (2 man years of
coding).

Does that double-negative mean you DO think it IS worth the time? I'm
guessing not, but I can't be sure.

Upps - sorry typo. Should read "I do not think it is...."
That 2 man years figure that gets bandied about comes, I think, from
Daveed's account of the time it took him. He's a seriously smart guy
so it might take other implementors a little longer ... BUT that time,
AIUI, includes the time taken to implement two-phase lookup which he
found was needed to support export. I think two-phase lookup is going
to have to be done anyway ... so the 2-man-year figure is misleading.

It would be better to do BOTH. Modules don't solve all the same
problems as export ... and export is in the standard TODAY -- all it

I wonder what export solves, that modules don't ?
needs is acceptance and implementation -- we could have it next year
if there was a will. Modules won't be in any sort of standard before
2012 at the earliest.
[...]

Sadly I have to agree.

Andre
 
A

Andre Kaufmann

Bo said:
Daniel said:
Kaufmann wrote:

[...]
Saying that implementing this language feature is too expensive, while
simultaneously designing several other entierly new languages, doesn't
really maximize your credibility.

Then why do only the EDG based commercial compilers support export ?
Because all want to loose their credibility ?
Bo Persson

Andre
 
A

Arne Vajhøj

RFOG said:
We have a phrase: "confía en Dios y no corras", that will be translated
as "be confident with God and don't run".

Of course, C# can deal with LDT, GDT, vector interrupts, rings, direct
hardware access and of course microprocessors executes MSIL directly(*).

You will need something native to do that.

But that is a microscopic part of an OS like Windows Vista.

Arne
 
A

Arne Vajhøj

Fernando said:
The new version of MFC is just great! With the Ribbon, docking windows,
new common controls, MSN menus, and a bunch of other things... I wonder
why Microsoft is investing in MFC, if it is doomed...

There is still a lot of MFC apps out there. MS has a lot themselves.

But new apps will be done in Win Forms or WPF.

And eventually that will change the desktop landscape.

Arne
 
A

Arne Vajhøj

Andre said:
The point is that JVM has been officially been restricted to a single
language and wasn't meant to be open for other languages - don't know
it's current state in this regard.

What do you mean by "has been officially been restricted" ?

The JVM specs are public so anyone can target it. SUN has released
some other languages for the JVM themselves.
And it's not only the runtime that makes the difference. Can you write
code in Java and use it easily from any other language targeting the JVM ?

Yes. No problem.

Arne
 
A

Arne Vajhøj

Daniel said:
Did you notice that the very next paragraph of the bit you snipped said:


So, yes, of course, I agree with you. The point I was making in the bit
you didn't snip is that Java is a single-language environment BY DESIGN.
The Java zealots at Sun would have you believe that you don't need any
language other than Java and that Java is all the languages that you
will ever need ... at least, that was their mantra last time I passed by
the temple.

That is one of the worst pieces of logic I have seen in a long time.

You can not conclude that:

the JVM is not suite dfor C/C++ => the JVM is only designed for one language

There are actually other languages than C/C++ in the world.

And your impression of SUN's policy sound totally out of touch
with reality.

SUN has released several other languages for the JVM.
All the same, most of the languages you list -- and those in the
Wikipedia article you cited -- are experimental "academic" languages,
which aren't likely to be anyone's first choice for commercial
application.

Ada, Python, Ruby etc. are all used commercially.

Arne
 
H

Hendrik Schober

Andre Kaufmann said:
Thanks for the link.


Yes, agreed. But in a large team it's still a pain to start the build
process over and over again, because in your local project it compiled
fine but in another project some weird side effect causes a compilation
error.

I'm not sure what you're getting at.
Yes, include files and macros are a PITA. But, as I said,
it easily gets better by using more hardware resources.
And that's a cheap way to solve a problem. How much your
language supports you in writing correct code is IMO far
more important.
Even if I use processing power, C++ still compiles way more slower than
most of the other languages do. Currently our build time is 30 minutes,
which has been 3 hours before we switched to a quad core system.

I could live with the compilation time, if the slow down would be caused
by the complex syntax of C++ only and if that would be outweighed by the
productivity increase by all the goodies of C++ (templates, RAII etc.).
But since the slow down isn't caused by the complexity, but because the
compiler has to compile code over and over again, I think it's a huge
loss of productivity for - nothing - .

Yes, agreed. But still. We used to use several dozen CPUs
for one build. Since every developer has a couple of them
and since most of the time developers are thinking or
typing, their CPUs are available for this most of the time.
With this setup, /linking/ was the worst bottleneck, not
compiling.
If compile-times are your worst problem, then that's good.
Buy some IncrediBuild licenses, get over it, and focus on
writing correct code.
[snipped other points I mostly agree with]
Andre

Schobi
 
J

Jordi Maicas

One day somebody tell something like the following:

"Work with C#, and learn C++"

I explain it in my opinion; C# is easy to learn, and I consider C++ (not
only C), is a little difficult to use for a begginer. In the other hand, the
most of programmers develop in C++; For example, I think Windows 9x,nt,xp,2k
were designed with c++6. So, with C++, you could do all you need and want,
but... there would be an easiest way to do the same with C#.

Actually there're too many platforms, devices and.... any more? Programming
languages, are not reduced to C++, C# or VB, in the other hand there're
Java, Perl, Python, Ruby. And other platforms, like Unix,Solaris,Novell.

When you use a .NET language, you're falling down to Windows OS, but ... you
know. If you're a programmer, you maybe would like to do a program that runs
at any platform. Solution? Java.

In addition, I only see a problem with Java, and is about execution time;
but the same problem is when you're running a .net app. Slow, slow, slow,
...... But the same Java app, runs on other platforms.

Learn a lot of language, think about the problem, and decide with language
must you use looking at the problem, may be C#, maybe C, maybe Java, ....

"Work with C#, and learn C++".
 

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