++i is faster than i++ in Java?

R

Roedy Green

I guess an average Java weenie won't acknowledge the problem
even if it panted itself blue and danced on the keyboard naked..

As if you, a newbie, would be the first to discover some fundamental
error in Java that all the ten year vets overlooked.
 
M

Mike Schilling

Dimitri Maziuk said:
Benji sez:

Why? Because the assignment takes place in a subroutine
or because it uses append() instead of "operator +"?

Because it's nothing like

x=y
y=z
All native types are by-value, all UDT's are by-reference.

Everything in Java is passed by value, both scalars and references.
Simplified illustration of resulting semantic inconsistency is
"x=y; y=z;", do I really have to spell it out in working code?
Y


I guess an average Java weenie won't acknowledge the problem
even if it panted itself blue and danced on the keyboard naked...

All you've done is confuse yourself. Try constructing an example of

x=y; y=z;

that doesn't result in x having the initial value of y; you'll see you
can't.
 
D

Dimitri Maziuk

Benji sez:
UDTs are assigned by-value-of-the-reference. This is not c++ pass-by-ref.
Assignment is not a mutating operation for the object, just the reference
variable. This is a really simple problem that I originally thought you
had just mistyped, but now I think you have a fundamental misunderstanding
of what is going on.

Not quite. Yes, references are implemented as pointers, pointers
are allocated on stack like all other "primitives". As a result,
by-value sematics appear to work on objects -- at least as far as
assignment operator goes. That doesn't change the fact that objects
are by-reference and a subroutine is free to modify an object passed
to it.

Getting back to original topic, by-value "=" on objects works only
as long as the programmer is not allowed to override operators. If
you override '=' to do deep copy, the "x=y; y=z;" will start working
as it should.

Dima
 
B

Benji

Dimitri said:
Getting back to original topic, by-value "=" on objects works only
as long as the programmer is not allowed to override operators. If
you override '=' to do deep copy, the "x=y; y=z;" will start working
as it should.

Being wrong isn't a problem. Being arrogant and wrong is. You should
probably fix that.

the semantics of "x=y;y=z;" resulting in x==y is simply not correct for
assignment. if you implemented deep copy, it still wouldn't work.
again, I would suggest that you give an example in a language that allows
that. the variable y would have to in some way remember that it had been
assigned to x, so that when z got assigned to y, it would also write to x.

Not only are you not a java expert, you seem to not understand basic
programming semantics. I wouldn't go around calling people java weenies
any more.
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top