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 ... 4 5 6 7 8 9 10 11 12 ... 15  | » ]
John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 8:19 AM
Reply to this message Reply
Advertisement
>>, since you brought
> up the supposition that people fled to Java because it was
> too hard for them to "write good C++ in the first place"

Actually, I never said that. I meant that some bad practices in C++ (overuse of 'new') translated to normal practice in Java. The (ex)C++ programmer then thinks 'Hey, all my manual memory management woes are over', when in fact they were probably not needed in the first place.

I'm not sure I understand the relevance of the Dilbert quote?

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 8:19 AM
Reply to this message Reply
>
> So I have a different question for you, since you brought
> up the supposition that people fled to Java because it was
> too hard for them to "write good C++ in the first place"
> .. do you think it is naturally more difficult to write
> good C++, and do you think that is a good characteristic
> or something to be avoided in a language? ;-)
>

Have you noticed that I am constantly being accused here of introducing memory leaks in C# code? If I don't cause memory leaks in C++ and do in C# then GC hardly solves any problems.

Seriously, I am not claiming C++ as a language encourages writing good code. The learning curve is steep and there are many gotchas to watch. However, it is pretty much the only (real-life) language that offers both very low level access to system and optional high level abstractions and that's why it is being used so much.

Java vs C++ rants maybe made some sense in mid 1990s when C++ was for some reason also widely used for "enterprise computing", but today the two languages serve pretty much completelly different purposes. Better watch Ruby, Java guys :)

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 8:32 AM
Reply to this message Reply
> By
> lower-level, I mean languages that are old enough to not
> provide facilities that are commonly expected today, such
> as garbage collection, intrinsic support for thread safety
> and concurrent programming, a well-integrated run-time
> type system, an exhaustive standard class library, etc.

As for this "old-enough" part: Lisp had almost everything you mention in late 1950's, not to mention SmallTalk. It is not a metter of "new vs. old" but a purpose. For a system programming language many of these facilities you mention either make no sense or are a burden.

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 8:44 AM
Reply to this message Reply
>
> As for this "old-enough" part: Lisp had almost everything
> you mention in late 1950's, not to mention SmallTalk. It
> is not a metter of "new vs. old" but a purpose. For a
> system programming language many of these facilities you
> mention either make no sense or are a burden.

It seems to me that much of the value of C/C++ as a systems language derives from its use for the operating systems that are currently popular and isn't intrinsic to the language. Languages which have a low impedance mismatch with the OS enjoy a favoured position. Compare with those systems which run Lisp, SmallTalk and Java essentially right down to the hardware.

Todd Blanchard

Posts: 316
Nickname: tblanchard
Registered: May, 2003

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 9:10 AM
Reply to this message Reply
To understand how the language can be both unpleasant and complicated,
and well designed at the same time, you must keep in mind the primary
design decision upon which everything in C++ hung: compatibility with
C.


Funny, but Objective C had the same goal, held to it better, and the language doesn't suck. Why? Because Stroustrup's fundamental mistake, the core error, the basic screwup, was not to stay compatible with C (which he didn't do nearly as good a job of as Objective C). His fundamental mistake from which all pain flowed was to conflate structs with objects. This was, in retrospect, the stupidest decision in the history of language development and the root cause of most of C++'s ugly little quirks.

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 9:25 AM
Reply to this message Reply
> To understand how the language can be both unpleasant
> and complicated,
> and well designed at the same time, you must keep in mind
> the primary
> design decision upon which everything in C++ hung:
> compatibility with
> C.

>
> Funny, but Objective C had the same goal, held to it
> better, and the language doesn't suck. Why? Because
> Stroustrup's fundamental mistake, the core error, the
> basic screwup, was not to stay compatible with C (which he
> didn't do nearly as good a job of as Objective C). His
> fundamental mistake from which all pain flowed was to
> conflate structs with objects. This was, in retrospect,
> the stupidest decision in the history of language
> development and the root cause of most of C++'s ugly
> little quirks.

I have to disagree. 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. The run-time environment of C++ and many of the choices make perfect sense from a performance point of view.

What are the most important problems of C++? I'd say, the following, in no particular order:

1) uninitialized variables. Stroustrup thought (and maybe it is true on embedded systems) that not initializing variables automatically would have a performance cost. Should he have chosen safety first, he could have made variables always initialized except if not explicitly marked so.

2) array and ptrs equality. Again, for performance reasons, this has remained from C. The correct choice should have been to make arrays different from ptrs, and only treat them equal only when explicitly marked so.

3) lack of array bound checking. Same as above. Array access should be bounds-checked by default, except when explicitly not desired.

4) manual memory management. This is a big huge problem for the language, not because manual memory management is not feasible, but because it does not scale well. The solution here is not optional collection (as some might suspect from reading the above), but compile-time struct introspection: if the programmer was able to visit struct members at compile-time, safe generic precise collection could have been introduced as a library.

5) untyped new and delete operators. Without access to the type of the allocated object, the operators new and delete can not do enough magic to help in the problem of memory management.

6) header files. Big problem from the development point of view. Much effort is spent in synchronizing header and implementation files.

There is a good programming language struggling to come out from C++, especially with templates/type traits. Whoever does it, will put his name into the history books.

Todd Blanchard

Posts: 316
Nickname: tblanchard
Registered: May, 2003

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 9:40 AM
Reply to this message Reply
> Bill Venners: Why are there primitive types in Java? Why
> wasn't everything just an object?
>
> James Gosling: Totally an efficiency thing. There are all
> kinds of people who have built systems where ints and that
> are all objects. There are a variety of ways to do that,
> and all of them have some pretty serious problems. Some of
> them are just slow, because they allocate memory for
> everything. Some of them try to do objects where sometimes
> they are objects, sometimes they are not (which is what
> the standard LISP system did), and then things get really
> weird. It kind of works, but it's strange.
>
> Just making it such that there are primitive and objects,
> and they're just different. You solve a whole lot of
> problems.
>

The problems he solves are the problems of the VM implementors, not the language users. While taking the easy way out for himself, he blithely introduces a whole host of problems for the Java programming world.

This little exchange evoked much laughter among people familiar with Smalltalk and LISP VM implementation where most of Java's primitive value types are represented as tagged memory (also known as "immediate objects").

"Kind of works" is disingenuous. It works great from the standpoint of the user. It does make the VM a bit more complicated. Then there is the space argument, but this doesn't hold up either once you do a little profiling.

http://arcanesentiment.blogspot.com/2009/03/where-have-all-pointers-gone.html

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 9:48 AM
Reply to this message Reply
> "Kind of works" is disingenuous. It works great from the
> standpoint of the user. It does make the VM a bit more
> complicated. Then there is the space argument, but this
> doesn't hold up either once you do a little profiling.
>
> http://arcanesentiment.blogspot.com/2009/03/where-have-all-
> pointers-gone.html

I believe its usefullness still depends on the kind of application you look at. Certain types of numerical application are still heavily penalised by this approach.

John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 9:52 AM
Reply to this message Reply
> There is a good programming language struggling to come
> out from C++, especially with templates/type traits.

I'll second that.
Also, there has been an attempt to create an alternate syntax for C++.
http://www.csse.monash.edu.au/~damian/papers/HTML/ModestProposal.html

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 10:40 AM
Reply to this message Reply
> Have you noticed that I am constantly being accused here
> of introducing memory leaks in C# code?

Actually, technically speaking, there's no way to introduce a memory leak in C# (or Java) code, or if you want to think of it a different way, all C# (and Java) applications leak all over the place.

That's because the condition of having an object with no live references to it is a description of one type of memory leak scenario and also the exact condition that makes an object collectable.

You describe two different issues: page faults and an out of memory exception. The first may or may no be real issue because of the way Windows reports virtual memory usage. There's no way to know without running the application. The second issue, however, we only ever occur if you are trying to reference more memory in your application than is available to it. Unless the VM is flawed, this is just a fact. If you didn't actually mean to allocate that much memory, you had a space leak. There's no other explanation aside from a bug in the VM which would be expected to be identified and fixed across the many thousands of developers using the CLR. No one is accusing you of anything, we are telling you the facts.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 10:48 AM
Reply to this message Reply
> It seems to me that much of the value of C/C++ as a
> systems language derives from its use for the operating
> systems that are currently popular and isn't intrinsic to
> the language. Languages which have a low impedance
> mismatch with the OS enjoy a favoured position. Compare
> with those systems which run Lisp, SmallTalk and Java
> essentially right down to the hardware.

I would go a step further and attribute it to the hardwer. If you had a CPU that runs Lisp, of course Lisp would be a better system language than C. I remember hearing about some efforts to build a CPU that would natively run Java, but I believe it ended up in the same place with Java OS, Java Office and Java web browser.

Cameron Purdy

Posts: 186
Nickname: cpurdy
Registered: Dec, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 11:23 AM
Reply to this message Reply
> I would go a step further and attribute it to the hardwer.
> If you had a CPU that runs Lisp, of course Lisp would be a
> better system language than C. I remember hearing about
> some efforts to build a CPU that would natively run Java,
> but I believe it ended up in the same place with Java OS,
> Java Office and Java web browser.

It's a good point. The "C" language is pretty close to an ideal representation of what you need to drive a "von Neumann machine".

Peace,

Cameron.
http://www.oracle.com/technology/products/coherence/index.html

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 11:37 AM
Reply to this message Reply
> better system language than C. I remember hearing about
> some efforts to build a CPU that would natively run Java,

They just can't keep up with the huge effort that drives the x86 architecture forward in spite of its many warts.

> but I believe it ended up in the same place with Java OS,
> Java Office and Java web browser.
Some of those efforts were started too early in Java's evolution (the libraries were missing necessary capabilities). However their main problem isn't technical but the shere scale of the effort required to match the incumbents and then market it.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 11:52 AM
Reply to this message Reply
> However their main problem isn't technical
> but the shere scale of the effort required to match the
> incumbents and then market it.

Google Chrome? :)

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: The Positive Legacy of C++ and Java Posted: Mar 19, 2009 1:41 PM
Reply to this message Reply
> > However their main problem isn't technical
> > but the shere scale of the effort required to match the
> > incumbents and then market it.
>
> Google Chrome? :)

Which rather proves the point. Firstly Google undoubtedly have the marketing capability. Secondly it is based on WebKit which is descended from KHTML (started 1998), which forked from the KDE HTML Widget (date of origin unknown). So that is at least 10 years of development history that I can easily trace.

Flat View: This topic has 210 replies on 15 pages [ « | 4  5  6  7  8  9  10  11  12 | » ]
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