The Artima Developer Community
Sponsored Link

Weblogs Forum
The Positive Legacy of C++ and Java

210 replies on 15 pages. Most recent reply: May 8, 2009 11:50 PM by Daesung Park

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 210 replies on 15 pages [ « | 1 ... 6 7 8 9 10 11 12 13 14 ... 15  | » ]
Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 21, 2009 3:39 AM
Reply to this message Reply
Advertisement
> > Stroustrup's main goal was
> > performance. Objective-C dynamic dispatch method call
> will
> > never be as fast as a C++ non-virtual/virtual method
> call.
>
> It can be as fast as non-virtual method calling if you use
> imp caching on time critical portions. This, of course,
> unnatural and somewhat inconvenient, rather like giving up
> polymorphism in an alleged OO language for performance
> reasons.

And the inconvenience does not scale well. Imagine having to do this for a lot of methods.

>
> More about optimizing objective c:
> http://www.mulle-kybernetik.com/artikel/Optimization/opti-3
> -imp-deluxe.html
>
> > The run-time environment of C++ and many of the choices
> > make perfect sense from a performance point of view.
>
> I disagree with this. 99% of written code is not time
> critical and does not need maximum performance. If this
> were not true, Java, Ruby, Python, etc would be stillborn.
> As long as there is a means of expending a little extra
> a effort on bottlenecks to get closer to hardware and thus
> faster code, any language can be used for any real time
> application.
>
> C++'s problem is it thinks 99% of the time everything must
> be maximally performant and that just isn't true. Wrong
> tradeoff.

Every little performance lost over here and there accumulates and results in a slow computing experience. For a single threads and a single program, perhaps it does not make sense. But when you have many processes and threads, it matters.

If I can make it faster without sacrificing flexibility, why shouldn't I do it?

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 21, 2009 3:41 AM
Reply to this message Reply
Ok, we bashed c++ enough. Anyone cares to co-operate in creating a replacement?

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 21, 2009 7:01 AM
Reply to this message Reply
> Ok, we bashed c++ enough. Anyone cares to co-operate in
> creating a replacement?

The problems with the existing "replacements" are that they are not replacements at all - they serve different purpose (Java, C#). A true replacement would need to keep the same major goals C++ has (esp. easy access to the system, controllable memory consumption and performance - yes, 100% of the time) while fixing the problems it has and probably even offering something significantly new. I just don't see this happening.

Frankly, I would like to see a resurrection of Ada, but outside of the defense domain. That looks like a very nice language that is (almost?) as low level as C++ but does not have many of its problems. Or maybe I just have the feeling because I have never worked with Ada :)

Todd Blanchard

Posts: 316
Nickname: tblanchard
Registered: May, 2003

Re: The Positive Legacy of C++ and Java Posted: Mar 21, 2009 1:13 PM
Reply to this message Reply
> Every little performance lost over here and there
> accumulates and results in a slow computing experience.
> For a single threads and a single program, perhaps it does
> not make sense. But when you have many processes and
> threads, it matters.

Doesn't. Not really for most programs. Efficiency argument is bogus today. It makes zero sense. Here is one example:

http://www.audiofreakshow.com/?q=node/10

This is my app. It does live music performance and MIDI routing. It makes an objective C object for every blessed MIDI event, on the heap, using copious polymorphism during the handling of that MIDI event (transposition, filtering, rechannelization) until its delivery to its destination audio processor. Live. Real time. Audio. With undiscernable latency. Using dozens of threads. It never stumbles even when handling multiple MIDI input devices and crazy keyboardists that lay on the whole keyboard at once. Using unoptimized Objective C. The graphics animation is the same (keyboard animates). If I had needed to optimize, I could have. But I didn't.

> If I can make it faster without sacrificing flexibility,
> why shouldn't I do it?

You can't. If you need wicked fast dispatching, you sacrifice virtual methods (and there isn't a good way to undo that sacrifice without extensive rewriting of the classes themselves - unlike imp caching where you can using it with any object any time. C++ makes tons of sacrifices in flexibility in the name of performance.

Krisztian Sinka

Posts: 30
Nickname: skrisz
Registered: Mar, 2009

Re: The Positive Legacy of C++ and Java Posted: Mar 22, 2009 1:32 AM
Reply to this message Reply
> Doesn't. Not really for most programs. Efficiency
> argument is bogus today. It makes zero sense. Here is
> one example:
>
> http://www.audiofreakshow.com/?q=node/10
>
> This is my app. It does live music performance and MIDI
> routing. It makes an objective C object for every blessed
> MIDI event, on the heap, using copious polymorphism during
> the handling of that MIDI event (transposition, filtering,
> rechannelization) until its delivery to its destination
> audio processor. Live. Real time. Audio. With
> undiscernable latency. Using dozens of threads. It never
> stumbles even when handling multiple MIDI input devices
> and crazy keyboardists that lay on the whole keyboard at
> once. Using unoptimized Objective C.

But here the performance bottleneck was solved by the MIDI standard:
It handles MIDI events and not sound wave information. MIDI event AFAIK is small textual commands (pitch, note, tempo, etc.) passed to a highly optimized sound processor hardware for synthetization.

Jeff Ratcliff

Posts: 242
Nickname: jr1
Registered: Feb, 2006

Re: The Positive Legacy of C++ and Java Posted: Mar 22, 2009 11:48 AM
Reply to this message Reply
> But here the performance bottleneck was solved by the MIDI
> standard:
> It handles MIDI events and not sound wave information.
> MIDI event AFAIK is small textual commands (pitch, note,
> tempo, etc.) passed to a highly optimized sound processor
> hardware for synthetization.

You're right. The fact is that hard real-time systems can't be implemented in software alone on a platform like the PC. While multiple execution units and caching improve average performance, their non-deterministic time performance makes them unsuitable for software-based timing.

At the risk of telling everyone what they already know, real-time is about time accuracy, not speed.

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: The Positive Legacy of C++ and Java Posted: Mar 22, 2009 2:09 PM
Reply to this message Reply
> In fact I like to learn more about "because C++ has both
> stack allocation and heap allocation and you must overload
> your operators to handle all situations and not cause
> memory leaks"
>
> Anyone know more detail about it?

Download "Thinking in C++" and read the chapter on operator overloading.

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: The Positive Legacy of C++ and Java Posted: Mar 22, 2009 2:14 PM
Reply to this message Reply
> > "Java brought the mainstream of programmers into the
> world
> > of garbage collection, virtual machines and a
> consistent
> > error handling model"
> >
> > Not to mention, design by contract. Up until then, only
> > academic languages carried that flag forward.
>
> Eiffel was the first to use design by contract.

Perhaps the poster was saying that Eiffel is an academic language.

But more importantly, Eiffel has language support for design by contract. There's nothing in Java that supports DBC. I have spent a fair number of pages in Thinking in Java 4e (and I think 3e) showing how you can implement DBC with Java, but that's very different than Eiffel, which has keyword support for DBC.

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 22, 2009 3:01 PM
Reply to this message Reply
> > Ok, we bashed c++ enough. Anyone cares to co-operate in
> > creating a replacement?
>
> The problems with the existing "replacements" are that
> they are not replacements at all - they serve different
> purpose (Java, C#). A true replacement would need to keep
> the same major goals C++ has (esp. easy access to the
> system, controllable memory consumption and performance -
> yes, 100% of the time) while fixing the problems it has
> and probably even offering something significantly new. I
> just don't see this happening.

We could make it.

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 22, 2009 3:06 PM
Reply to this message Reply
> > Every little performance lost over here and there
> > accumulates and results in a slow computing experience.
> > For a single threads and a single program, perhaps it
> does
> > not make sense. But when you have many processes and
> > threads, it matters.
>
> Doesn't. Not really for most programs. Efficiency
> argument is bogus today. It makes zero sense. Here is
> one example:
>
> http://www.audiofreakshow.com/?q=node/10

Nope, it does make absolute sense, when Firefox freezes from too many open tabs, when Word chokes on complex documents, when Excel does a complex calculation...it matters in compiling big projects...it matters in a lot of cases!

>
> This is my app. It does live music performance and MIDI
> routing. It makes an objective C object for every blessed
> MIDI event, on the heap, using copious polymorphism during
> the handling of that MIDI event (transposition, filtering,
> rechannelization) until its delivery to its destination
> audio processor. Live. Real time. Audio. With
> undiscernable latency. Using dozens of threads. It never
> stumbles even when handling multiple MIDI input devices
> and crazy keyboardists that lay on the whole keyboard at
> once. Using unoptimized Objective C. The graphics
> animation is the same (keyboard animates). If I had
> needed to optimize, I could have. But I didn't.

Nice app, but you can't win the performance argument with a single app.

>
> > If I can make it faster without sacrificing
> flexibility,
> > why shouldn't I do it?
>
> You can't. If you need wicked fast dispatching, you
> sacrifice virtual methods (and there isn't a good way to
> undo that sacrifice without extensive rewriting of the
> classes themselves - unlike imp caching where you can
> using it with any object any time. C++ makes tons of
> sacrifices in flexibility in the name of performance.

I don't find C++ or Java inflexible. Why should I have dynamic dispatch ala Objective C when virtual methods ala C++ does the job perfectly?

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 22, 2009 4:51 PM
Reply to this message Reply
> > > Every little performance lost over here and there
> > > accumulates and results in a slow computing
> experience.
> > > For a single threads and a single program, perhaps it
> > does
> > > not make sense. But when you have many processes and
> > > threads, it matters.
> >
> > Doesn't. Not really for most programs. Efficiency
> > argument is bogus today. It makes zero sense. Here is
> > one example:
> >
> > http://www.audiofreakshow.com/?q=node/10
>
> Nope, it does make absolute sense, when Firefox freezes
> from too many open tabs, when Word chokes on complex
> documents, when Excel does a complex calculation...it
> matters in compiling big projects...it matters in a lot of
> cases!

I think it's a little ironic that the three apps you mention are all (AFAIK) written in C++. I'm pretty sure Firefox is.

But the real thing that's confusing to me is that GC is more efficient (in terms of CPU) than deterministic memory deallocation. Basically GC lets the work pile up and then cleans up in one big swoop often when there's reduced load.

This is often inefficient in terms of memory because the leaving the cleanup until later means that memory that isn't actively in use is not available immediately. This is a tradeoff that works for a lot of applications especially as memory has dropped in price.

The 'problem' you pointed out before is another example of such a trade-off of memory for time. The VM pre-allocates a block of memory from the OS larger than what it needs so that it doesn't have to do that when the application is running full-bore. It doesn't return that memory to the OS when it's not using it (not for a long while) because it might need it later. These were choices were made on purpose. The VM could return the memory to the OS after each collection but that would make it slower.

So, in a way, by arguing for the best CPU efficiency, you are making an argument for garbage collected languages.

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 23, 2009 2:25 AM
Reply to this message Reply
> So, in a way, by arguing for the best CPU efficiency, you
> are making an argument for garbage collected languages.

Indeed I do. GC is a good tool to have, alongside manual memory management. Both are useful.

What I see, from this site, and from other sites, that we like to criticize programming languages a lot, but when it comes to doing something about it, no one really wants to.

The fun part is that we are all good programmers and understand the problems and the solutions, but we are not doing anything to solve the problems.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 23, 2009 8:50 AM
Reply to this message Reply
> What I see, from this site, and from other sites, that we
> like to criticize programming languages a lot, but when it
> comes to doing something about it, no one really wants to.
>
> The fun part is that we are all good programmers and
> understand the problems and the solutions, but we are not
> doing anything to solve the problems.

I'm not sure that's fair. A lot of the bloggers here are creating new languages or working on them with others.

I've actually considered hacking around on a new language of my own using my favorite features of all the languages I know about while attempting to keep it very simple (a tall order, I know.) I really would only be doing this for fun, though, I don't imagine that it would be likely to be widely adopted, even if it were spectacular.

Jeff Ratcliff

Posts: 242
Nickname: jr1
Registered: Feb, 2006

Re: The Positive Legacy of C++ and Java Posted: Mar 23, 2009 9:42 AM
Reply to this message Reply
> Perhaps the poster was saying that Eiffel is an academic
> language.
>

Perhaps he was, but Eiffel is an academic language only to the extent that C++ or Java is - a commercial language sometimes used for teaching.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 23, 2009 11:33 AM
Reply to this message Reply
> I think it's a little ironic that the three apps you
> mention are all (AFAIK) written in C++. I'm pretty sure
> Firefox is.

They are (except that MS Office apps have some C left from olden days). It would be nice to compare similar Java applications, but there are none. What is your experience with Eclipse/NetBeans?

>
> But the real thing that's confusing to me is that GC is
> more efficient (in terms of CPU) than deterministic memory
> deallocation. Basically GC lets the work pile up and then
> cleans up in one big swoop often when there's reduced
> load.

Nothing prevents you from doing that without a GC when it makes sense, and plus you have actual knowledge about your application logic and know where is the reduced load. In fact I did that once.

Flat View: This topic has 210 replies on 15 pages [ « | 6  7  8  9  10  11  12  13  14 | » ]
Topic: Should I use a netbook as my main development platform? Previous Topic   Next Topic Topic: Social Newsfeeds: The Next Big Thing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use