Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Which language is best?

This thread is locked; no one can reply to it. rss feed Print
Which language is best?
Steve++
Member #1,816
January 2002

I can only speak for Java...

Java has an integrated build system. You compile one file and if another is needed, that is compiled first, and so on. But if the dependency (which is always just a class) is already compiled, then its interface is very easily and quickly extracted from its class file. I think C++ should modernise its compilation system similarly and rid itself of its preprocessor legacy once and for all. Also, another annoying legacy that should die in C++ is that a global or class identifier must be declared above the code that first references it.

C++ was designed to be a better C. It's time for a better C++.

HoHo
Member #4,534
April 2004
avatar

Quote:

Source?

http://ompf.org/forum/viewtopic.php?p=1153#1153
Download that file. Compile with maximum optimizations and see the difference. IIRC under win32 ICC was fastest, next came GCC 4.2 alpha being ~10% behind and last was MSVC 2k5 ~5% slower than GCC.
Under 64bit GCC was fastest, ICC ~5% slower and MSVC ~10% slower than GCC.
I haven't personally done those tests but others in that forum had and I think I can trust them.

As for code size, I don't know. Most likely ICC generated the biggest and MSVC the smallest

Quote:

Is that true for AMD chips as well?

ICC bypass or how to keep dirty monopolist at bay. :)
[edit]
Got rid of recursion :)

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

Marcello
Member #1,860
January 2002
avatar

Quote:

and MSVC ~10% slower than MSVC

ahhh the recursion! make it stop!

Marcello

Zaphos
Member #1,468
August 2001

Quote:

Download that file. Compile with maximum optimizations and see the difference. IIRC under win32 ICC was fastest, next came GCC 4.2 alpha being ~10% behind and last was MSVC 2k3 ~5% slower than GCC.

So, for some random raytracer, a two-year-old version of MSVC is slower than an unknown version of ICC and the GCC 4.2 alpha? Um, this benchmark seems ... broken ...

HoHo
Member #4,534
April 2004
avatar

Quote:

ahhh the recursion! make it stop!

Got rid of it :)

Quote:

So, for some random raytracer, a two-year-old version of MSVC is slower than an unknown version of ICC and the GCC 4.2 alpha?

Oops, they used 2005 instead. The last version I used was 2k3, thus the confusion.
ICC version was the latest, 9.1.
Newer GCC has vastly improved SIMD code generator, thus the alpha. I'm not sure if GCC 4.1 series have the same optimizations or not.

Quote:

Um, this benchmark seems ... broken ...

If you don't remember what I said before in ]edit I'll say this again:
... at least for compiling code with lots of SSE2 intrinsics
So when dealing with that topic narrowing my "benchmark" is correct :)
Btw, that ray tracer should currently be one of the fastest single-threaded ray tracers in the world if not the fastest. Too bad it currently only supports primary rays and no textures. Those problems should be fixed soon and also it should have extremly good support for completely dynamic scenes. Tracing those dynamic scenes is almost as fast and efficient as tracing static scenes.

When comparing some random code ICC should mostly be a bit faster than GCC and MSVC is usually the slowest. Of course there might be exceptions but that is what I and some other people I know have seen.

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

Zaphos
Member #1,468
August 2001

Quote:

So when dealing with that topic narrowing my "benchmark" is correct

Ah! Probably. As correct as benchmarks tend to get, anyway :)

Quote:

When comparing some random code ICC should mostly be a bit faster than GCC and MSVC is usually the slowest. Of course there might be exceptions but that is what I and some other people I know have seen.

All right. I'll file it under "probably usually true," then ;). Thanks for all the clarifications -- casually googling, it's hard to find good (up to date) data on this!

Quote:

Btw, that ray tracer should currently be one of the fastest single-threaded ray tracers in the world if not the fastest.

Cooool! I hope it gets features soon!

Marcello
Member #1,860
January 2002
avatar

I made a ray tracer that's even faster! It can render everything in under a second. Although it's limited to 1x1 renders. It does support antialiasing though.

Marcello

Zaphos
Member #1,468
August 2001

Quote:

It does support antialiasing though.

;D

axilmar
Member #1,204
April 2001

Zaphos said:

The preprocessor is just as powerful & available, though, so if it can't work in C then it can't work generally in C++.

No, you don't understand. In C, certain things are only/much easier doable through the preprocessor. Take linked lists, for example: a couple of macros will save you from casts. You don't need to do stuff like that in C++.

Quote:

Er ... how else can you make guarantees about the safety of a binary?

The key is the word 'unneeded'. You can ensure a binary module does nothing serious if the O/S does not let it do anything serious. It is the O/S that hands privileges out. Unfortunately, O/Ses do not provide the proper 'sandboxing' of applications, so VMs take over. A proper sandboxing of an exe would be ring protection, like in CPU: an exe could not touch resources of a higher privilege level; unfortunately no O/S implements this.

Quote:

Um, I'm not familiar with their entire product catalog, but they don't seem to offer a backwards debugger. And if they do, it seems unlikely it will be free.

Yes, it's not free, but the point is it is doable.

Quote:

The C# approach described by Shawn seems far preferable.

If something can be in a library, then it need not be in the language.

Quote:

Templates take a lot of time to process. If C++ had a proper generic system then it wouldn't need templates to thrash the compiler and bloat the binary.

C++ templates are preferrable to generics. I do not want objects to be allocated each time I use primitives.

The compile speed difference is not as important as it sounds, because projects are developed incrementally anyway.

Evert
Member #794
November 2000
avatar

Quote:

In C, certain things are only/much easier doable through the preprocessor. Take linked lists, for example: a couple of macros will save you from casts.

Eh? Sorry, but what are you talking about?
I use linked lists all the time in C and I've never remotely needed a preprocessor. Then again, I've never needed to cast either.

Marcello
Member #1,860
January 2002
avatar

Quote:

The key is the word 'unneeded'. You can ensure a binary module does nothing serious if the O/S does not let it do anything serious. It is the O/S that hands privileges out. Unfortunately, O/Ses do not provide the proper 'sandboxing' of applications, so VMs take over. A proper sandboxing of an exe would be ring protection, like in CPU: an exe could not touch resources of a higher privilege level; unfortunately no O/S implements this.

So your point is moot, is it not? We don't live in utopia, we have to work with what we have. ;)

Marcello

Zaphos
Member #1,468
August 2001

Quote:

You don't need to do stuff like that in C++.

Yes, but you can, and the refactoring tech is supposed to work generally. Of course, you could have refactoring tech that just breaks down when macros are being abused ("error: code is stupid") but it seems less good then. Also, I think templates are essentially another turing complete macro system, under the hood, so it seems like you could trip up refactoring tech with that, too.
(Tangentially, I am familiar with using icky macros in C, and have done the linked list thing.)

Quote:

unfortunately no O/S implements this.

What Marcello said.

Quote:

but the point is it is doable.

Yeah, I never argued with doable. I just said easier and (hence) more free in Java.

Quote:

If something can be in a library, then it need not be in the language.

It can be more friendly when in the language. In C#'s case, it'll make it a lot nicer when you come in to a code base which you didn't have full control over, because the design of C# should make it really easy to see the unsafe code and it should also discourage its use.

Quote:

I do not want objects to be allocated each time I use primitives.

That's not really how the C# generics work, so all you seem to be saying is that you don't want Java Generics in C++.

C++ templates are also a pain, language wise, 'cause the compiler errors they give are often difficult to read.

Quote:

The compile speed difference is not as important as it sounds, because projects are developed incrementally anyway.

To some extent, one would hope, anyway.

Marcello
Member #1,860
January 2002
avatar

Compile time isn't incremental as soon as you're including other .hpp files. As soon as you modify a class, everything that uses it has to be recompiled, potentially everything.

In Eclipse, there is no compile time, everything is compiled automatically. :D

Marcello

GullRaDriel
Member #3,861
September 2003
avatar

If something can be in a library, then it need not be in the language:

Are you so sure to proudly tell that ? Tell me if I am wrong, but aren't all the language a couple of header and libraries ? Haaa, yes, you have the compiler. But with only one of these you can't do something. I really do not agree here.

For the C memory question: You can do as error as you can make in C++ for example. Forget to write a destructor or a free(...), and the result will be the same. Everything is a matter of debugging. Garbage collector ? Heh, do not assume everything is nicely done there. I think we can easily find that most of the time, That is the OS who take care of freeing memory for you. There are really mad code everywhere. And even if the memory is perfectly managed, you can not be sure that the RAM or DDR will keep it's efficiency for eternity ;-)

The speed question is a false question. Most of the application you will have to program for a company will not need the so/most/ever coded/optimized code. Companies are like that: As it is and works, as it should stay. Only the FBI,NASA,CNRS and allegro.cc's people must ;-)

For the project part: I got a C++ project who was rewritten 3 times and who is more than 10 years old. It has gone trough lisp, C, C++. Can you imagine how painless it is to have a variable or a function, and spend 10 minutes to understand from where it comes, and from where comes the derived overloaded polymorphic obscur class ?
Perhaps it is me, but read someone C++ giant project is as trying to understand his mind. I do not say it is not the case in C, but I find it more friendly when it comes to 'get' how a ten millions lines code works. IMHO !

And as I said before, Use the language you are the best at. And as Marcello said, you will not ever have the choice.

Greets, Gull.

_

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Bob
Free Market Evangelist
September 2000
avatar

Quote:

If something can be in a library, then it need not be in the language:

Are you so sure to proudly tell that ?

This is a requirement for all C++ specification changes. If some feature can be done as a library, it should not be in the language.

--
- Bob
[ -- All my signature links are 404 -- ]

Goalie Ca
Member #2,579
July 2002
avatar

Quote:

Perhaps it is me, but read someone C++ giant project is as trying to understand his mind. I do not say it is not the case in C, but I find it more friendly when it comes to 'get' how a ten millions lines code works. IMHO !

What you are reffering to is overdesign and i see it all the time from keen comp sci students. It's sick how "generic" and "Abstract" people write the code.

I see it in C++ with even simple things like Array containers.

I've never though seen it in C. People keep things simple. I'm not sure why. Perhaps because its ugly to do things like this in the language or maybe its just the people and the purpose but generally people don't aim for "purity" and "perfection" they just aim to make it readable and short.

-------------
Bah weep granah weep nini bong!

Zaphos
Member #1,468
August 2001

Quote:

I've never though seen it in C. People keep things simple.

It's worth noting, here, that it's possible to write unreadable code in any language. And people will do it. (hmm, ever tried reading any of James Lohr's source code?) In C, I think the more common problem is, er, under-design ... in which the code has been written as one amorphous mass, entirely lacking generality, so when it comes time to extend the code to new uses & such, it can get quite painful. And since your C IDE probably lacks sweet refactoring tools, it can be a lot harder to clean up than similar code would have been in, say, Java.

Quote:

This is a requirement for all C++ specification changes. If some feature can be done as a library, it should not be in the language.

But this doesn't justify it as a design philosophy . . . or imply that the features discussed could be done as well if they were in library form.

axilmar
Member #1,204
April 2001

Quote:

Yes, but you can, and the refactoring tech is supposed to work generally. Of course, you could have refactoring tech that just breaks down when macros are being abused ("error: quote is stupid") but it seems less good then.

Refactoring in C++ is doable just as in Java. Macros do not obcure anything, and almost never used in C++ declarations anyway.

Quote:

Also, I think templates are essentially another turing complete macro system, under the hood, so it seems like you could trip up refactoring tech with that, too.

Yeah, templates are a great idea.

Quote:

(Tangentially, I am familiar with using icky macros in C, and have done the linked list thing.)

as If I knew it...I've also done so, and I suspect many others have.

Quote:

Yeah, I never argued with doable. I just said easier and (hence) more free in Java.

Ok, it's a little bit easier for a JVM, but it's a minor point though. And it does not concern the language, because a C++ compiler could happily emit bytequote.

Quote:

It can be more friendly when in the language.

If it covers your needs and it is not in the language, then why isn't it as friendly as if being in the language?

Quote:

That's not really how the C# generics work, so all you seem to be saying is that you don't want Java Generics in C++.

Actually, they are. For example, when you add an int to a linked list, an Integer object is created. That's why the environment can keep one version of linked list around (as opposed to C++ where there are many versions of linked lists).

I don't like generics, because they make program less fast than it can be; it bloats memory with unnecessary objects etc.

Quote:

C++ templates are also a pain, language wise, 'cause the compiler errors they give are often difficult to read.

That's an implementation detail of the compiler. It does not concern the language. In MSVC++ 8.0, for example, template error messages are much more understandable.

Quote:

Compile time isn't incremental as soon as you're including other .hpp files. As soon as you modify a class, everything that uses it has to be recompiled, potentially everything.

In Eclipse, there is no compile time, everything is compiled automatically. :D

Marcello

Eclipse supports autocompile for C++ also. It works like in Java...try it.

Shawn Hargreaves
The Progenitor
April 2000
avatar

Quote:

Refactoring in C++ is doable just as in Java. Macros do not obcure anything, and almost never used in C++ declarations anyway.

Of course refactoring is technically doable in C++: you can always write a program to programmatically manipulate code written in any well defined language.

The point is not that it is impossible, but that it is much harder to get right.

So in the real world (the world of tools I can actually download and use today, rather than theoretical ones that haven't been written yet) it turns out that there are far more refactoring tools for Java and C# than there are for C++, and these have much richer features and are more robust.

Quote:

Quote:

It can be more friendly when in the language.

If it covers your needs and it is not in the language, then why isn't it as friendly as if being in the language?

It depends on the feature. Some things are fine in libraries, but others can benefit from dedicated language support for many possible reasons:

  • Better error reporting.

  • More efficient code generation.

  • Nicer syntax.

For example take a typical lock idiom implemented via a library in C++:

{
    LockHolder lock(theObject);
    object->doStuffWhileLocked();
} // LockHolder destructor releases the lock

Versus built into the language in C#:

lock (theObject)
{
    object->doStuffWhileLocked();
}

Not a huge difference, but the C# version is slightly more concise, and more importantly, less error prone because the braces are enforced as part of the construct, rather than just relying on scoping rules to release the lock at the right place.

Another example is lambda functions. boost::lambda does an amazing job of implementing them in a library, but has lots of corner cases that can be very confusing in practice. Nowhere near as clean and easy to understand as the C# delegate syntax.

Of course not everything belongs directly in a language, but some things can be made nicer that way.

Quote:

Quote:

That's not really how the C# generics work, so all you seem to be saying is that you don't want Java Generics in C++.

Actually, they are. For example, when you add an int to a linked list, an Integer object is created.

You are mistaken about how C# generics work, and are describing the Java implementation here. C# generics do not cause any unneccessary boxing.

Quote:

Quote:

C++ templates are also a pain, language wise, 'cause the compiler errors they give are often difficult to read.

That's an implementation detail of the compiler. It does not concern the language. In MSVC++ 8.0, for example, template error messages are much more understandable.

Better than they were before, but still far from ideal.

Like the point about refactoring, this is the difference between theory and practice.

Yes, poor error messages are an implementation detail.

But also, the C++ template system makes it hard to give good error messages, as witnessed by the fact that no C++ compiler which actually exists today can come anywhere near the clarity of the errors you get from misusing generics in C# or Java.

I actually kind of like templates because they are cool and powerful: I'm not one of those people who thinks they are the spawn of Satan. But I'm also aware that they have a lot of issues, high on the list being that a lot of people just don't understand them (which is not aided by generally poor error reporting). So if I'm writing a library that I intend to be used by a wide audience, heavy reliance on templates is probably not a great idea. Generics do much better in that regard. The typical idiot Visual Basic programmer who barely knows enough to string together a couple of forms for his business would be totally lost if you handed him a template API, but can generally get on ok with using generic container types.

23yrold3yrold
Member #1,134
March 2001
avatar

I had wondered why people were bashing templates. I just resurrected my old template particle engine for a project for the church and while the syntax is still ugly, I had cool fireworks and crap running in no time. I don't even remember how the stupid thing works under the hood, I just remember if you make this one class for initialization and this other class for logic and throw them at the template class and call Emit ... voila! Perfect fast particle management every time. :)

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Zaphos
Member #1,468
August 2001

Quote:

Eclipse supports autocompile for C++ also. It works like in Java...try it.

That feature just calls "make" whenever you save, and isn't recommended. The Eclipse CDT manual, right in the "before you begin" section, states: "For C/C++ projects this feature should be turned off, otherwise builds will be performed whenever a file is saved, including makefiles and header files."

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

I actually kind of like templates because they are cool and powerful: I'm not one of those people who thinks they are the spawn of Satan.

I love to hate templates, and Hate to love them :)

Really, most of the time they are usefull, but once in a while I want to do something with them, and they totally break down and are totally useless.

IMO, C++ would be so much better if it was more consistent. If its namespace was more sane, so you could have proper nested classes, and all that nice stuff. As it is, C++ is severely lacking IMO. Though I do use it. After starting to use Qt regularly, I find myself using C++ even when not using Qt.

I guess I just like the added syntax sugar. But C++ needs allot of improvement. :(

I've also heard tons of good things about C# from many people I trust, but I just don't know if I can switch to it at this point, I don't do windows coding, and I don't have a legal licence ;) who knows if the linux C# compiler supports all I want it to (Qt for one).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Steve++
Member #1,816
January 2002

Quote:

I don't do windows coding, and I don't have a legal licence ;)

Visual C# Express is free and legal.

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

Visual C# Express is free and legal.

But Vista won't be in a year once my free beta licence runs out :P

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Steve++
Member #1,816
January 2002

Meh... I haven't had a legitimate windows since 3.11.



Go to: