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?
Zaphos
Member #1,468
August 2001

Quote:

The academic approach. Figure out some kind of code analysis algorithm that can verify whether pointers are being used correctly. Nice idea but unfortunately nobody has figured out how to actually do it yet :-)

I categorized the academic approach as more like Cyclone or Typed Assembly Language ... which do, as far as I can tell, have working implementations. I don't think anyone's expecting an after-the-fact code analysis to be able to verify such things generally -- that seems like it's obviously not possible (since you could construct, you know, a program that only uses pointers incorrectly if it finds a counterexample to [insert famous theorem here]). Code analysis techniques like Model Checking are more additional debugging aids than full solutions ...

Richard Phipps
Member #1,632
November 2001
avatar

With CPU speeds now faster than ever, aren't we approaching the point where low-level pointer operations should be replaced with slower (but safer) methods of manipulating data?

HoHo
Member #4,534
April 2004
avatar

Quote:

Was that question aimed at me?

Yes but I think I misunderstood you. When you said "It still seems like a real advantage to get rid of them completely." I thought you were talking about getting rid of any possibility to cause segfaults by eliminating all things that can cause user-errors (pointers, overflowing arrays and other stuff)

Quote:

With CPU speeds now faster than ever, aren't we approaching the point where low-level pointer operations should be replaced with slower (but safer) methods of manipulating data?

In about 95% of the cases, yes. For them CPU speed is fast enough. Problem is that the other 5% still needs at least some tuning and part of that needs extreme tuning. Difference between non-optimized code and optimized code can be several orders of magnitude, even when the general algorithm is the same.

__________
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

Shawn Hargreaves
The Progenitor
April 2000
avatar

Quote:

With CPU speeds now faster than ever, aren't we approaching the point where low-level pointer operations should be replaced with slower (but safer) methods of manipulating data?

For 99% of code, yes.

But there is still that final 1% to worry about.

For instance I just got done writing a class for doing design time texture manipulation (creating mipmaps and so on). To the people using this, it looks like a 2D array, and the methods for reading and writing pixels do bounds checking. But internally I need every bit of speed I can get. If it takes me a couple of extra hours dealing with more complicated coding constructs, but in exchange I can speed up some common image processing operations by 20% for everyone using the library, that seems like a worthwhile tradeoff.

Personally I like to have the choice. Use slower and safer methods by default, but have an emergency switch that I can throw in case I really need to.

This is kind of the same thing as people who write big apps in Python, but then optimize a few critical sections in C. Except just sticking an unsafe tag in the middle of some C# code is much easier than dealing with all the Python to C interop hassles.

The ability to drop down to raw pointer artihmetic is also very useful when doing interop to existing non-managed code. Of course in an ideal world everything would be managed and typesafe and good, but we don't live in an ideal world. Sometimes you're writing high level managed code and badly need to call some icky low level system API that was designed 15 years ago and is inherently untypesafe. I find it very handy that I can just wrap the thing in an unsafe tag and have at it: no need to jump through hoops using some other language to make a wrapper.

Goalie Ca
Member #2,579
July 2002
avatar

Quote:

But I won't touch C# as long as it is not open source...not free as in beer, but free as in speech, and available for other O/Ses as well...and not only the compiler, but the libraries as well (because the compiler alone is worthless).

C# is a pretty nice language and i've done work in it. THe main problem i've had with c# is the lack of good strong libraries. Windows Forms is terribly incomplete (though consisten) and it uses GDI+ instead of GDI which means no hardware acceleration for things like blitting images (which means its makes a terribly slow picture viewer unless you bother to p/invoke gdi and winapi).

Mono is pretty nice and i use several mono applications including beagle and tomboy. A lot of beagle core is actually still in c++ for various reasons. Mono apps seem to run just as fast as the rest (because they all use c libraries in the end).

gtk# and glade# are pretty nice and there's gecko# gimp# and everything else in the gnome world. qt# was sadly canned after the people lost interest. QT is an awesome toolkit.

Last summer i wrote some numerical code in c# for some basic image processing. I took some time, read a lot of docs, followed good practices, turned off all the safety stuff, and it still ran 2-4 times slower than naive c++ (compiled with mingw). Obviously though c# is not designed for that stuff. Actually if you think about it matlab is horrendously slower (but syntactic gold).

I love c# for writting everyday applications but for me c++ is awesome for everything else. I do a lot of image processing, numerical analysis (often i call fortran code which can optomize a lot better because of constraints like lack of pointers etc.)

Quote:

You'd could still access arrays out of bounds, deference null pointers, overwrite memory, etc ... and segfaults are really quite a liability, security-wise ... It still seems like a real advantage to get rid of them completely.

Which is why you try and use nice helper objects which throw exceptions where speed doesn't matter. They are speaking of making the next version of the STL entirely "safe" and having an unsafe one available for those who count cycles. But ya, pointer abuse is one of those things that make C++ a real drag. Smart pointers go a long way to fixing that but are not perfect themselves.

I was also pleasently surprised last summer when i discovered that i could write void* in c# and have it compile. I believe though that i needed to mark the function using the "unsafe" keyword. That seems like a perfectly reasonable thing to do. It's basically the equivalent of casting to/from type object.

Quote:

With CPU speeds now faster than ever, aren't we approaching the point where low-level pointer operations should be replaced with slower (but safer) methods of manipulating data?

Hell no! Although i must admit that my "research code" for my biomedical engineering thesis uses a lot of checking and such so it takes overnight to run instead. There are a few performance critical areas where i could fix it but since i'm constantly modifying the code it would be suicide. That aside it would be marvelous if once it stabilizes i could run it in even 70% of the time. Don't forget that there are a LOT of cases where even an algorithm of nlog(n) is far too large and every cycle counts (especially every branch! especially with blocking and multi-threads/processes)

edit: In particular i'm using smart pointers, very "safe" collections, built checking in them, etc. The best thing any compiler could do in my opninion is throw compile time errors and warnings. The more the better. I always make my code work to output no warnings even and gcc 4 makes things a lot "stricter".

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

Steve++
Member #1,816
January 2002

I love Java, but the more Shawn extols the virtues of C#, the more I lean towards it. Ah heck, I'll write my next game in C# just for fun.

topicms.gif

axilmar
Member #1,204
April 2001

Zaphos said:

That's another issue with C/C++ -- seems that because of all the preprocessor support, it's a lot harder to find an IDE which refactors & which compiles (and underlines errors / warnings) as you type/save. Does such exist?
I find I edit Java in Eclipse, and C++ in SciTE, so writing Java code is a lot nicer.

Eclipse can edit C++, but I haven't tried the refactoring capabilities yet. But it is certainly doable in C++ as it is in Java, because the preprocessor is not used heavily in C++ to provide code; that's unlike C, where certain tricks are only possible through the preprocessor.

Quote:

Isn't jailing a design? It seems like the only way to provide gaurantees about the code, short of having it carry proofs ... I'm not sure why you would dismiss this as worthless out-of-hand.

It is a totalitarian design. It puts unneeded constraints. It is certainly not worthless, but security could be done without it.

Quote:

The 'niceness' of Java also seems to mean it gets neat things like the omniscient debugger [lambdacs.com] first and more freely ...

www.parasoft.com

Quote:

You'd could still access arrays out of bounds

vector.at is your friend.

Quote:

deference null pointers

ptr<T> is your friend.

Quote:

overwrite memory

Not really possible with GC and guarded pointers.

Quote:

etc ... and segfaults are really quite a liability, security-wise ... It still seems like a real advantage to get rid of them completely.

Not really. The vast amount of problems in C++ come from manual memory management. If you do not believe me, check out com.std.c++.

HoHo said:

How would you eliminate pointer calculations? Would you cut out inline assembly also because that would allow modifying pointers and data on lower level than the language might.

You don't have to eliminate pointer calculations. In C++, you don't pay for what you don't use. Let them do pointer calculations if they want to screw their program...if you don't, provide a special pointer class which can easily do guarded pointer arithmetic. That's a task that can hapilly exist in a library, unlike gc.

Richard Phipps said:

With CPU speeds now faster than ever, aren't we approaching the point where low-level pointer operations should be replaced with slower (but safer) methods of manipulating data?

There are everyday tasks that require speed. Try Sql Server Express, a .net managed app...slow as hell. Then try VS...not as slow, but slow nevertheless. Also try to edit a 265-page word document with technical schematics...each time you add something, word will repaginate the document, taking lots of time to do that. And what about compiling?

Let's not kid ourselves. The day performance does not matter is not here yet.

Shawn Hargreaves
The Progenitor
April 2000
avatar

Quote:

And what about compiling?

Interestingly, the Microsoft C++ compiler is written in C++, while the C# compiler is written in C#.

Guess which runs fastest?

(ok, so that's not really a fair test because they aren't both compiling the same language. But I still find it interesting)

The Visual Basic compiler, however, is not written in Visual Basic. Conclude from that what you will :-)

Marcello
Member #1,860
January 2002
avatar

That odb thing looks pretty neat. D: But hasn't been updated in over a year? It'd be nice if it integrated into Eclipse...

Marcello

Zaphos
Member #1,468
August 2001

Quote:

But it is certainly doable in C++ as it is in Java, because the preprocessor is not used heavily in C++ to provide code; that's unlike C, where certain tricks are only possible through the preprocessor.

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

Quote:

It is a totalitarian design. It puts unneeded constraints.

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

Quote:

www.parasoft.com

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.

Quote:

Let them do pointer calculations if they want to screw their program...if you don't, provide a special pointer class which can easily do guarded pointer arithmetic.

The C# approach described by Shawn seems far preferable.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Quote:

Interestingly, the Microsoft C++ compiler is written in C++, while the C# compiler is written in C#.

Guess which runs fastest?

I'll take Greek Mythology for $500, Alex!

I'll byte and say that C++ is faster... OTOH he wouldn't have stated the quote otherwise since it wouldn't have been "newsworthy"

They all watch too much MSNBC... they get ideas.

Shawn Hargreaves
The Progenitor
April 2000
avatar

Curiously, the C# compiler is literally about 100x faster than the C++ one!

And that's even without it bothering to implement any of the clever speedup techniques the C++ compiler uses, like precompiled headers, incremental linking, and so on.

The speed difference is just ridiculous. In C++ you get totally used to large projects taking several minutes if not hours to compile. But in C#, a codebase similar in size to Allegro compiles in about 5 seconds. It's just crazy.

That's mostly down to the language, though, which is designed to avoid constructs that will give the compiler anything too time consuming to worry about.

Curious factoid: Anders Helsborg, the chief designer of C#, previously invented Delphi and before that Turbo Pascal. Both also languages notorious for having ridiculously fast compile times.

Goalie Ca
Member #2,579
July 2002
avatar

THe MS VC++ compiler sucks donkey balls. It chokes on templates and simple stuff all the time. But that has absolutely nothing to do with "which language is the best".

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

Zaphos
Member #1,468
August 2001

I hear the MS VC++ compiler is quite good -- and it certainly seems to be respected and used in industry. Perhaps you're thinking of an older version?
And since Shawn's claims seems to extend generally across all C++ compilers -- I've never seen a C++ compiler that can get the compile-speed that Shawn's seeing for C# -- it does apply as a language critique. A faster compile-time means less time lost waiting for builds, which means more productivity.

edit: this actually means a lot to me -- a build time of a few seconds keeps me focused on the task at hand. If I have to wait a few minutes to get back to my project and test out my changes, I'll probably use those minutes to start checking my email or the boards or etc, and often waste a lot more than the actual time-to-build. And when I get back to the problem, it's less fresh in my head, so there's more lost productivity getting re-oriented.

Steve++
Member #1,816
January 2002

Quote:

Curiously, the C# compiler is literally about 100x faster than the C++ one!

Even if the C# compiler was written in a native language such as C++, I doubt it would be any (or much) faster, because compilers spend a lot of time in disc access.

Quote:

Curious factoid: Anders Helsborg, the chief designer of C#, previously invented Delphi and before that Turbo Pascal. Both also languages notorious for having ridiculously fast compile times.

I remember using Turbo C and Turbo Pascal on the same machine (just running DOS). Pascal compiled way faster than plain old C. This guy should also be working on the C++ compiler team.

Quote:

THe MS VC++ compiler sucks donkey balls. It chokes on templates and simple stuff all the time. But that has absolutely nothing to do with "which language is the best".

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.

Quote:

I hear the MS VC++ compiler is quite good -- and it certainly seems to be respected and used in industry. Perhaps you're thinking of an older version?

Even verson 6 was used widely in the industry, so I guess it was 'respected' too, but that was full of ISO/ANSI non-conformance.

Zaphos
Member #1,468
August 2001

Quote:

This guy should also be working on the C++ compiler team.

Maaaaybe, but it seems like designing a language so that it is easy to compile is quite different from optimizing a compiler for a language which already has its spec finalized ... there's no particular reason to believe this guy could significantly speed up the C++ compiler.

Quote:

but that was full of ISO/ANSI non-conformance.

I think this was primarily because it was created before the standards solidified, so it's not really fair to fault them for it.

_Dante
Member #7,398
June 2006
avatar

Good God, this thread still hasn't been shut down? You are all aware that the question was asked and answered in the first two posts, and everything since then has been off-topic, right?

-----------------------------
Anatidaephobia: The fear that somehow, somewhere, a duck is watching you

Thomas Fjellstrom
Member #476
June 2000
avatar

Welcome to Allegro.cc _Dante. :)

So long as it isn't a flaming ball of trolls these sorts of discussions can be informative to some.

--
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

LennyLen
Member #5,313
December 2004
avatar

Quote:

You are all aware that the question was asked and answered in the first two posts, and everything since then has been off-topic, right?

Welcome to allegro.cc. ;)

[edit]D'oh!

_Dante
Member #7,398
June 2006
avatar

Quote:

Welcome to allegro.cc. ;)

Point taken. Uh, I'll cast my vote for APL (am I dating myself there? Nah.)

-----------------------------
Anatidaephobia: The fear that somehow, somewhere, a duck is watching you

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

I think this was primarily because it was created before the standards solidified, so it's not really fair to fault them for it.

When will it support C99? :P Why is it replacing/deprecating the majority of libc in the name of "safety" and "security", when several of the functions could only be a safety concern if an absolute idiot got a hold of them? Most of the rest are also fine as long as you use it properly.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

HoHo
Member #4,534
April 2004
avatar

Quote:

I hear the MS VC++ compiler is quite good -- and it certainly seems to be respected and used in industry.

I wonder why is that so.
ICC beats almost everything under the sun for 32bit x86, gcc gomes next. In 64bits GCC 4.1+ is the greatest followed by ICC. Well, at least for compiling code with lots of SSE2 intrinsics. For 32bit Allegro on Linux GCC 3.4 is faster than ICC :)

[edit]
I was talking about generated code speed, not compiling time.

__________
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:

ICC beats almost everything under the sun for 32bit x86, gcc gomes next.

Source? Is that true for AMD chips as well?

Steve++
Member #1,816
January 2002

Quote:

ICC beats almost everything under the sun for 32bit x86, gcc gomes next.

My understanding is that MSVC++ generates smaller and fastser code than gcc because it doesn't have a front-end/back-end architecture; or if it does to some degree, the 'intermediate' form isn't as far removed from the target hardware as is the case with gcc (because gcc targets a wide range of architectures).

Marcello
Member #1,860
January 2002
avatar

The reason the C# compiler is so much faster than the C++ compiler is similar to the reason the Java compiler is so much faster than the C++ compiler. You're not building/linking the entire program, you're making dynamically linked modules. Plus on top of that, the languages are a bit more strict and don't have to worry about things like preprocessors (eg #include).

Marcello



Go to: