some personal rambling on java the lang

P

Pascal J. Bourguignon

Joshua Maurice said:
Really off-topic here, but let me correct this. While I agree that
this should be done for other reasons, portability is not one of them.
As soon as you're writing to particular hardware memory addresses,
there is no such thing as portability, with peek and poke functions or
not. It is inherently tied to the system, and the C standard says
little to nothing about such things (though it was explicitly written
to allow the system to take some of the undefined behavior and make it
defined /for that platform/).

I beg to differ.

You can get your addresses from a configuration file.

The semantics and of sequences of peeks and pokes depend more on the
device, than on the system. There may be different routing, it's true,
but this also can be dealt with in a modula way. Ultimately, on sane
hardware, I think it's perfectly possible to write portable drivers or
systems. Linux and Microsoft Windows are clear examples.

What I have said in this thread was for portable C programs, aka
programs written to the C standard and not to platform extensions.
Obviously writing device drivers and such is possible in C and not in
Java because of C's unchecked pointer casts and other "unsafe" pointer
stuffs. It's not fair to compare this.

I'm saying you can do the same in Java provided the JVM gives you access
to a low level peek and poke, and some wait to control timing
(eg. disable garbage collection for time-critical sections). Or any
other programming language such as Lisp on the LispMachine.

What is fair is to compare the semantics of pointers and Java
references. You can assign to a pointer without changing the
pointed-to object, changing a passed by value pointer in a function
call leaves the callee pointer unchanged, and so on. This is very much
unlike C++ references which act more like aliases, and I again contend
that because Java in its beginning largely lifted its syntax and
semantics from C++, it should not have conflated and confused these
two terms because it causes (minor) undue confusion in the
communities.

There's so few words...
 
R

Roedy Green

Also, of all big software companies, i HATE Sun Microsystems with
passion

You are a bit out of date. It has not existed for some time.
Perhaps the rest of your opinions are out of date too.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Microsoft has a new version out, Windows XP, which according to everybody is the "most reliable Windows ever." To me, this is like saying that asparagus is "the most articulate vegetable ever."
~ Dave Barry
 
M

Mayeul

> [...]
I won't speak for Xah, but I suspect many people (especially that use
CL) don't get Java's very inexpressive form of OO, and consider it
pretty much broken.

Java's form of OO seems quite on par with my academic education and very
competitive with state-of-the-art alternate approaches, but I stay open
to suggestion.

What exactly do you mean by CL? Google seems to leave me with a lot of
old candidates.
 
X

Xah Lee

On 15/10/2010 21:08, (e-mail address removed) wrote:
 > [...]
I won't speak for Xah, but I suspect many people (especially that use
CL) don't get Java's very inexpressive form of OO, and consider it
pretty much broken.

Java's form of OO seems quite on par with my academic education and very
competitive with state-of-the-art alternate approaches, but I stay open
to suggestion.

What exactly do you mean by CL? Google seems to leave me with a lot of
old candidates.

CL means Common Lisp. Common Lisp has a general OOP system called
CLOS, see
http://en.wikipedia.org/wiki/Common_Lisp_Object_System

OOP in lisp predates java. I don't know CL so i cant really say but i
think Java heat around 1990s brought invigoration into CLOS, but am
not sure to what degree, whether there's new work into it or new spec
etc. But certainly more awareness and use.

Xah ∑ http://xahlee.org/ ☄
 
S

Stefan Ram

Mayeul said:
Java's form of OO seems quite on par with my academic education and very

No wonder.

»I fear - as far as I can tell - that most undergraduate
degrees in computer science these days are basically
Java vocational training.«

http://en.wikiquote.org/wiki/Alan_Kay
competitive with state-of-the-art alternate approaches, but I stay open
to suggestion.

Alan Kay coined the term »OOP« in 1967.
In 2003, he wrote with regard to OOP:

»It can be done in Smalltalk and in LISP. There are
possibly other systems in which this is possible, but
I'm not aware of them.«

http://www.purl.org/stefan_ram/pub/doc_kay_oop_en

For example, in Java, blocks are not objects, while OOP
makes heavy use of (possibly, parameterized) blocks as
objects. Also, Java has many primitive values that are not
objects.
 
T

Tim Bradshaw

Java's form of OO seems quite on par with my academic education and
very competitive with state-of-the-art alternate approaches, but I stay
open to suggestion.

What exactly do you mean by CL? Google seems to leave me with a lot of
old candidates.

CL in this context would be Common Lisp. CL has an object system -
CLOS - which is very different than Java's and whose ancestors diverged
from the ancestor's of Java's quite a long time ago. It's different to
the extent that people only exposed to Java-style OO will often reject
CL's object system as not being OO at all (despite the fact that it's a
relatively small amount of work to implement a Java-style OO system in
CLOS).
 
M

Mayeul

No wonder.

»I fear - as far as I can tell - that most undergraduate
degrees in computer science these days are basically
Java vocational training.«

http://en.wikiquote.org/wiki/Alan_Kay

Not implying I am a great result of my education, but in my case it was
more:
- Theory of abstract classes and polymorphism, pseudo-language and
trivial design patterns.
- UML
- C++
- And /then/, Java.

Alan Kay coined the term »OOP« in 1967.
In 2003, he wrote with regard to OOP:

»It can be done in Smalltalk and in LISP. There are
possibly other systems in which this is possible, but
I'm not aware of them.«

http://www.purl.org/stefan_ram/pub/doc_kay_oop_en

For example, in Java, blocks are not objects, while OOP
makes heavy use of (possibly, parameterized) blocks as
objects. Also, Java has many primitive values that are not
objects.

Okay. I guess I concentrated too much on Java to realize the value of those.
 
J

Joshua Maurice

I beg to differ.

You can get your addresses from a configuration file.

The semantics and of sequences of peeks and pokes depend more on the
device, than on the system.  There may be different routing, it's true,
but this also can be dealt with in a modula way.  Ultimately, on sane
hardware, I think it's perfectly possible to write portable drivers or
systems.  Linux and Microsoft Windows are clear examples.


I'm saying you can do the same in Java provided the JVM gives you access
to a low level peek and poke, and some wait to control timing
(eg. disable garbage collection for time-critical sections).  Or any
other programming language such as Lisp on the LispMachine.

We're arguing over definitions of portability. I'll grant you this
point in large part. However, I was trying to claim something much
more broad. Sure you can write a program that manipulates hardware
addresses and runs on a large portion of desktops. However, that thing
will not run on an old PDP-11, nor will it run on some new arbitrary
embedded processor. This is unlike a portable program which calculates
PI to the nth decimal place, which could be written in C or Java. This
PI program could run on any conceivable hardware to produce sensible
results, unlike your device drivers.
There's so few words...

Ok. Presumably you still disagree. I'm still curious as to where. Stop
me where you disagree:

1- Java is a direct descendant of C++. It is not an extension of, nor
does it share the same design goals. However, Java is based largely
off the C family of languages, and specifically C++. Java was meant as
a better C++.

2- The C family of languages largely popularized the term "pointer".
The term "reference" was already well known, and its definition was
vague and meant many different related things in different contexts.

3- Java's references have identical semantics to C pointers (minus
unsafe casting, pointer math, and null pointer checking), and they are
very different than C++ references. That is, there is a pre-existing
term widely known by all which excellently captured the semantics of
this construct of the new language Java, and that term was "pointer".
The identifying characteristic of "pointer" is not pointer math, nor
unsafe casting, nor null pointer checking or lack thereof, as
evidenced by the term pointer being used in other languages which also
lack those things. The term pointer references to an "object" or
"entity" which refers to another object. You can change the pointer to
point to a new object, and you can change the pointed-to object
without changing the pointer's state. They have distinct state.

4- The term which Java did pick, references, was vague in the
literature. It could refer to pointers, aliases, and any of kind of
thing which "references" another thing. Moreover, "references" had a
domain specific definition in C++, the language on which Java is
based.

5- By choosing the vague term "reference" which was already overloaded
in its predecessor language which denoted a thing very related but
distinct from pointer, the Java creators introduced confusion into the
programming world. Yes, this confusion is quite minor, perhaps not
even enough to write home about. I merely noted it as a pet peeve.

It's probably a pet peeve of mine because it's a form of political
correctness - they wanted to use a "safe" kind of pointers, which they
could and did by removing the "dangerous" aspects of pointers, but
they wanted to sell their language and "pointer" was a dirty word so
they picked a different word. To compound this annoyance, they picked
a term which could lead to (minor) confusion.
 
J

Joshua Maurice

  No wonder.

      »I fear - as far as I can tell - that most undergraduate
      degrees in computer science these days are basically
      Java vocational training.«

http://en.wikiquote.org/wiki/Alan_Kay


  Alan Kay coined the term »OOP« in 1967.
  In 2003, he wrote with regard to OOP:

      »It can be done in Smalltalk and in LISP. There are
      possibly other systems in which this is possible, but
      I'm not aware of them.«

http://www.purl.org/stefan_ram/pub/doc_kay_oop_en

  For example, in Java, blocks are not objects, while OOP
  makes heavy use of (possibly, parameterized) blocks as
  objects. Also, Java has many primitive values that are not
  objects.

I've been here before, and there is only fire, no light.
http://www.c2.com/cgi/wiki?DefinitionsForOo
Contained within are all of the good arguments, counter arguments, and
so on.
 
G

George Neuner

+---------------
| (e-mail address removed) (Rob Warnock) wrote:
| >Ahhh, how quickly they forget!!! BLISS <http://en.wikipedia.org/wiki/BLISS>
| >predated C (at least publicly), and not only had pointers and an explicit
| >dereference operator (the infamous "dot"!)
|
| You're right ... I did forget about BLISS. However, my comment was
| about when the term entered popular usage - which I don't believe
| BLISS accomplished.
+---------------

Maybe not in the general public, though it certainly made it
to a large subset of DEC users... and not always favorably! ;-} ;-}

+---------------
| >But even better, BLISS has "structures" which were actually little
| >*user*-defined pieces of code for calculating a pointer, including
| >subfields [the "P" (offset) & "S" (width) values above], so a more
| >idiomatic way to write it [assuming "foo" had previously been "mapped"
| >with an appropriate structure] would be:
| >
| > foo[13, my_nibble] = .foo[13, my_nibble] + 5;
|
| Interesting ... but does a pointer to a partial word have any utility
| beyond device register control?
+---------------

Sure, the same thing as bitfields in C -- any time you have compact
data structures where you want to pack multiple values per machine word.

+---------------
| (Maybe what it was meant for?)
+---------------

Not really. Actually, BLISS's pointers almost *exactly* mirror the
hardware byte pointers in the DEC PDP-10 instruction set. The BLISS code:

foo[13]<12,4> = .foo[13]<12,4> + 5;

could be written in PDP-10 assembler like this:

movei t0, foo+15 / Note: Default base in MACRO-10 is octal.
hrli t0, 140400 / Make a byte pointer from &foo[13].
ldb t1, t0 / Load byte using byte pointer in t0.
addi t1, 5
dpb t1, t0 / Deposit byte.

If you need the subscript "13" to be computed dynamically, then you
can use the built-in indexing in byte pointers, and construct one
at compile time [assuming you can fix which register will be used
for indexing -- here we assume that "t2" == register 7]:

myfield: xwd 140407,foo / Byte pointer to foo[t2]<12,4>

Then the code becomes:

move t2, ...[the index]...
ldb t1, myfield / The contents of t2 get used by the hardware
addi t1, 5 / in the calculation of the effective addr.
dpb t1, myfield

The motivation for having such flexible byte pointers in hardware came
in part from the fact that the PDP-10 was a 36-bit wide word-addressed
machine that used 7-bit ASCII for normal text files [packed 5 to a word
with one bit wasted] but also used *6*-bit subset ASCII for file names
and extensions, as well as keywords in system calls. But the hardware
actually supported *any* byte size from 1 to 36. [In fact, it even
supported a byte size of 0, which gave a sometimes-useful no-op!]

I should also mention that there were also ILDB & IDPB instructions,
which would first *increment* the referenced byte pointer [by decrementing
the "position" field by the "size" field] and then perform the LDB or DPB
function on the ultimate target location. If there weren't enough bits
left in the byte pointer for the field to fit in the current word [the
"position" field went negative], the ILDB/IDPB would increment the *word*
address and reset the position field to 0, thus allowing the use of
ILDB/IDPB to step sequentially through the bytes of a packed string.


-Rob

p.s. Yes, I used mixed-endian conventions in my sample code in the
previous posting. The BLISS code there (and the PDP-10 assembler above)
used big-endian byte descriptions, while the C code used little-endian.
[I was trying to keep it simple.]


Sorry I was a little dense - I never used a PDP, they were a little
before my time :) I'm more at home with VAX.

I forgot about the PDP's long words, packed strings, etc. In that
context, having such a field pointer construct makes perfect sense.
Thanks for taking the time to explain them.

George
 
G

George Neuner

Stop me where you disagree:

1- Java is a direct descendant of C++. It is not an extension of, nor
does it share the same design goals. However, Java is based largely
off the C family of languages, and specifically C++. Java was meant as
a better C++.

You can stop right here.

To my mind, a "better" version of a programming language should be at
least equivalent in utility - the "better" can be in other dimensions
such as safety and ease of use.

Gosling wrote that his motivation was to [clean up syntax, remove
redundancy and make the language safer and easier to use] (I'm
paraphrasing here, the actual quotes are long [1]).

But Gosling did not simply remove redundancy, he also removed critical
language functionality without offering an equivalent. As compared
to C++, Java is less expressive and provides less functionality.

How is that making it "better"?

YMMV, but I don't believe "dumbing down" a programming language can be
considered an improvement. Programming languages are not door knobs,
toasters or consumer MP3 players ... they are tools that need a sharp
edge. You can put a guard over the edge or you can teach people to be
careful, but removing the edge makes the tool useless.

Though still far from equivalent, C# nevertheless is closer than Java
to being a functional replacement for C++.

2- The C family of languages largely popularized the term "pointer".
The term "reference" was already well known, and its definition was
vague and meant many different related things in different contexts.

No, the definition of reference was not vague. As the C (and Pascal)
families use them, the terms "reference", "reference variable" and
"reference parameter" all were defined by Algol.

The languages of the C family, including Java, all use Algol's notions
unchanged.

3- Java's references have identical semantics to C pointers (minus
unsafe casting, pointer math, and null pointer checking), and they are
very different than C++ references. That is, there is a pre-existing
term widely known by all which excellently captured the semantics of
this construct of the new language Java, and that term was "pointer".
The identifying characteristic of "pointer" is not pointer math, nor
unsafe casting, nor null pointer checking or lack thereof, as
evidenced by the term pointer being used in other languages which also
lack those things. The term pointer references to an "object" or
"entity" which refers to another object. You can change the pointer to
point to a new object, and you can change the pointed-to object
without changing the pointer's state. They have distinct state.

Partly.

Modulo automatic dereferencing, C and C++ pointers, and Java's
references all are semantically equivalent to Algol's reference
variables. C++ references include the non-NIL, init-only attributes
of Algol's reference parameters.

[Stroustrup's mistake, I think, was in making C++ references first
class objects akin to pointers. Had references been simply name
syntax, I don't think there would be as much (or even any) confusion
about them.]

4- The term which Java did pick, references, was vague in the
literature. It could refer to pointers, aliases, and any of kind of
thing which "references" another thing. Moreover, "references" had a
domain specific definition in C++, the language on which Java is
based.

The term was not vague in relevant literature. Rather I think people
superimpose the everyday meaning of the term upon their (often
shallow) understanding of the semantics as defined by the programming
language ... and then are surprised when the real semantics don't
conform to their bogus understanding.

5- By choosing the vague term "reference" which was already overloaded
in its predecessor language which denoted a thing very related but
distinct from pointer, the Java creators introduced confusion into the
programming world. Yes, this confusion is quite minor, perhaps not
even enough to write home about. I merely noted it as a pet peeve.

C++ does not "overload" the term reference. Algol did, to some
extent, with dual notions of reference both as a syntactic identifier
and as a first-class, address container object.

C++ does not have Algol's notion of reference as "syntax" ... it has
only the notion of "container object". So despite whatever
misconceptions people may have, there is no overloaded meaning.

Similarly, Java has only the notion of "container object".

Moreover, all the notions of "pointers" and "references", regardless
of language, include notions of object identity and aliasing, so those
too are not overloaded meanings.


George
[1] James Gosling, Henry McGilton, "The Java language Environment: A
white paper", Sun Microsystems, 1996
 
J

Joshua Cranmer

But Gosling did not simply remove redundancy, he also removed critical
language functionality without offering an equivalent. As compared
to C++, Java is less expressive and provides less functionality.

How is that making it "better"?

If, in removing some functionality, you can cut the number of bugs by
eye-popping amounts, I would consider it better.

I presume you're referring to manual memory management and pointer
arithmetic as the tools that Java lacks to make it "less functional".
YMMV, but I don't believe "dumbing down" a programming language can be
considered an improvement. Programming languages are not door knobs,
toasters or consumer MP3 players ... they are tools that need a sharp
edge. You can put a guard over the edge or you can teach people to be
careful, but removing the edge makes the tool useless.

Not necessarily. I may not easily be able to express exactly how long I
want this Java object to last, but it's not a feature I use very often
when I have that capability.

The world doesn't need a One True Programming Language™ which solves any
problem under the sun--what you get when you try that is an unholy
kludge of a language which has surprisingly little compiler
interoperability, is truly understood by almost nobody, and which
requires style guidelines to limit you to a strict subset of the
language to be usable in production code.

Instead, it is better to have multiple languages which work very well
for their design goals and are reasonably interoperable between each
other. For example, you can call C code from pretty much any language,
and some dynamic languages even have modules to allow you to dynamically
call C code ("ctypes").
 
S

Steve Sobol

If, in removing some functionality, you can cut the number of bugs by
eye-popping amounts, I would consider it better.

I presume you're referring to manual memory management and pointer
arithmetic as the tools that Java lacks to make it "less functional".

Not having to deal with memory management and pointer arithmetic is, by
far, the biggest reason I prefer Java over C++.
 
J

Joshua Maurice

  I remember having read that it was actually Scheme covered
  with C++ syntax to make it look more familiar to C++ programmers.

  I was not able to find exactly this source, but at least:

      »The Java programming language adopted most of
      the syntax of C++ and semantics of Scheme.«

http://google.to/search?q="syntax+of+C+++and+semantics+of+Schem....

No offense to Stefan intended, but I intend great offense towards the
source of that quote. I don't even know what to say to it. It's so
stupid. Scheme is a functional programming language, a Lisp dialect,
whereas Java and C++ are very much based on ALGOL and imperative
programming (though they both offer limited support for functional
programming styles). The semantics of Java and the semantics of Lisp
and Scheme are worlds apart.
 
S

Stefan Ram

Joshua Maurice said:
The semantics of Java and the semantics of Lisp
and Scheme are worlds apart.

LISP was the first language with a garbage collector, now
Java also has a GC, while C++ does not have a GC. But this
is only one aspect. However, in Java, one can partially
emulate the LISP style, where functions (like CONS) return
complex entities (dotted pairs) allocated at runtime which
might be linked and passed around in complex ways. In C++,
this is much more difficult, because there is no garbage
collector.

Lisp and Scheme are not pure functional languages, but allow
some functional programming, possibly not to the extend of
Haskell. Lisp also allows for a more OO or procedural style.

There is some overlapping between OOP and FP, because FP is
based on functions-as-values (reification of functions)
which can also be done in OOP via functions-as-objects
(sometimes called »functors« in C++).

Maybe I confounded Java with JavaScript in this
regard? For JavaScript, Wikipedia says:

»JavaScript also has many functional features
based on the Scheme language.«

http://en.wikipedia.org/wiki/JavaScript
 
M

Martin Gregorie

Not having to deal with memory management and pointer arithmetic is, by
far, the biggest reason I prefer Java over C++.
+1

Pointer arithmetic probably has no place in a high-level language. And,
no, much as I like it, I don't consider C to be a HLL - more a structured
assembler.
 
P

Pascal J. Bourguignon

LISP was the first language with a garbage collector, now
Java also has a GC, while C++ does not have a GC. But this
is only one aspect.

One could try to use BoehmGC.

Unfortunately, I'm not sure at 100% that it would be safe, given how
hard C++ libraries and preconized C++ usage tries to make it hard for a
GC to work well with C++ code...

Nonetheless, some success have been reported, eg. with using Qt with
BoehmGC.


However, in Java, one can partially
emulate the LISP style, where functions (like CONS) return
complex entities (dotted pairs) allocated at runtime which
might be linked and passed around in complex ways. In C++,
this is much more difficult, because there is no garbage
collector.

Indeed. There's still Lpp (but you'd need an old gcc).



http://www.informatimago.com/articles/life-saver.html
 
X

Xah Lee

No offense to Stefan intended, but I intend great offense towards the
source of that quote. I don't even know what to say to it. It's so
stupid. Scheme is a functional programming language, a Lisp dialect,
whereas Java and C++ are very much based on ALGOL and imperative
programming (though they both offer limited support for functional
programming styles). The semantics of Java and the semantics of Lisp
and Scheme are worlds apart.

totally agree here. To say that java's semantic is mostly based or
connected to scheme lisp in would be the most egregious sophistry.

one might as well say any 2 langs is based on any other.

btw, did anyone actually stated that somewhere?

Xah
 

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

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top