Trouble with Java concepts

G

Gary Labowitz

Dale King said:
Hello, Michael Borgwardt !

[I'm lost as to who said this, was it Michael? Anyway...]
I looked in the mirror and I'm not blue and red in the face. But the way
Java works should be stated precisely, not any way you want and then saying
everything means the same thing (to you). Why not just give in and say
"Objects are passed by a little gremlin who takes care of everything for you
and never tells how he does it."? Then you don't have to worry about
anything ... unless you actually want to debug your program. I think the
whole thread started with someone asking why his program didn't work the way
he wanted. The answer was he didn't understand the way Java works.
On second thought, maybe sticking to correct statements will be a help after
all.
 
P

P.Hill

Gary said:
The answer was he didn't understand the way Java works.

I think we can all agree on that point.

-Paul

p.s. I was baiting when I accused people of being pedantic and turning blue.
If the shoe doesn't fit, don't worry about it.
Maybe a few people read through the thread and got a better understanding
of objects and primitives and what is passed. Let's hope so.
 
D

Dale King

Hello, Michael Borgwardt !
You said:
Which is exactly what Java does: pass a copy of the reference value, which
is exactly the reason why the OP's program does not work the way he thinks
it should.


I thought like that as well at one point, but eventually came around to be
one of those pedants as well - being pedantic is the most essential part
of being a good programmer.

The point is that "pass by reference" has a very narrow traditional meaning,
namely one that would allow the OP's program to work as expected - and Java
simply doesn't work that way: assigning something to a passed parameter does
not change its value outside the method call.

I think you have that backwards. That is more like the meaning of
pass by value. The true definitions involve terms like R-value
and L-value, but when I use that definition someone will start
trying to change the meaning of those words to try to say that
passing object references is passing by reference when it
definitely is not.
 
D

Dale King

Hello, Jim Cochrane !
You said:
Do newbies ever get confused by the "pass-by-value" terminology and think
that it means that the object being referred to is passed by value (i.e.,
that a copy of the object is passed, so that the original cannot be
changed)? If so, then perhaps a new terminology (not using "by value" or
"by reference") would be less confusing. If not then, I guess IIABDFI
(If it ain't broke, don't fix it.).

The key thing to get through to the newbie is not so much whether
the parameter is passed by value or by reference, but to
understand what the actual parameter is.

I try to focus more on the fact that the question "Are objects
passed by value or reference?" is a nonsense question. The answer
to that question is NO. Objects can never be passed at all. There
are no java semantics for holding object instances. Objects live
completely outside of Java the language on the heap. The only
connection between the two are object references.

Once that concept is firmly established the whole question of
passing semantics are obvious.

And note that a similar question arises with assigning on
variable to another. I might not be obvious to the newbie that
this is not making a copy of the object and the same knowledge is
necessary to grasp why.
 
D

Dale King

Hello, P.Hill!
You said:
Jim,

There seems to be this weird pedantic subset of Java programmers who insist
that "passing" does not always include putting the value of something on
the stack, so don't want to say "objects are passed by reference", but
insist until they turn blue and red in the face that we all should
say "pass the value of the reference to the object", which to me clarifys
nothing and means exactly the same thing.

Edsger Dijkstra is probably rolling in his grave!

"My area of interest focuses on the streamlining of the mathematical argument so
as to increase our powers of reasoning, in particular, by the use of formal
techniques." -- Edsger Dijkstra

Sounds to me like Dijkstra is in complete agreement. He talks
about mathematical argument and formal techniques, which are
pretty much impossible without a clear, unambiguous vocabulary.
If one starts changing the meanings of words in the vocabulary
communication becomes nonsense.

There is a precise, formal definition to what pass-by-reference
means. It was created for the purpose of "streamlining of the
mathematical argument so as to increase our powers of reasoning".
Unfortunately we have had years of muddying of that definition by
those with only a very narrow viewpoint of a particular language.
The definition was created to be language neutral and to allow
objective discussion.

So should we allow the definitions to be changed or point out the
correct definition? I go with the latter which sometimes requires
being pedantic. In the end it allows greater understanding and
improved communication.
 

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,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top