4 ms·
> This article is overly pedantic. Java's semantics are pass-by-value only of you consider that the "values" that are being passed are pointers. ??? Pretty sur
by SeanLuke 9y ago
> This article is overly pedantic. Java's semantics are pass-by-value only of you consider that the "values" that are being passed are pointers.
??? Pretty sure Java is uniquivocably pass-by-value. Your example of Swap is simply incorrect.
IIRC, in a pass-by reference language, Swap could be written as
swap(int x, int y):
int z = x;
x = y;
y = z;
And then you could call it as:
int a = 4;
int b = 5;
swap(a, b); // b now is 4 and a is 5
This can't be done in Java.
Also Java's reference types seem to be pretty FCO to me. Just because Java don't have pointer arithmetic is hardly a disqualification.
BTW, I find it interesting that Java's argument passing semantics and Common Lisp's are, so far as I can tell, identical.
- dfox 9y agoThe semantics are mostly identical in most OO languages with C++ being one notable exception.
- pjmlp 9y agoThat notable exception exists at least in Object Pascal, Oberon, Oberon-2, Active Oberon, Component Pascal, Modula-2, Modula-3, Ada, Eiffel, Sather, D, Swift.
- dfox 9y agoI probably should have qualified that with "widely used". :) On the other hand this list is to some extent relevant to the point I was trying to make, as most of these languages are somehow related to Algol/Simula/Modula (as is C++) and not to Lisp/Smalltalk (as is Java, Python, .net...). Object Pascal has the problem that there are at least two unrelated languages with same name. And the duffernce between Borland Pascal 7 and the Object Pascal used by Delphi is that the latter is firmly in the camp "there are only references to objects". (ie. for classes defined by 'object' keyword common pattern was "PFoo = ^TFoo", while for the 'class' ones, eg. essentially whole VCL, this is implicit)
- pjmlp 9y agoActually there a few unrelated Object Pascal languages, the language features from Turbo Pascal, introduced on version 5.5 for MS-DOS, were copied from Apple's Object Pascal. Then there is FreePascal with its compatibility modes and own extensions. The object keyword is still accepted in Delphi, even if they don't recommend it any longer. Also a few languages implicitly deference pointers as references, depending on the context.