ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  10 Reasons We Need Java 3.0
Subject:   add READ-WRITE parameters to methods
Date:   2002-08-06 08:02:22
From:   mirek1
Java methods have very limited possibility to accept its parameters and return more values (then the only one)!


I know that it was intention (to depress "side effect" for variables defined out of body of method). But in practice the Java code of obvious program is then less synoptical and more longer then it could be if Java will inspirate at these 3 "ancient" languages: pascal, FoxPro and Informix 4GL Language.


The main problem is "How to (simpy!) return more primitive values or objects from the method?". That can be express like problem of "READ-ONLY" and "READ-WRITE" parameters of Java method.


The only current mode of Java syntax forces every Java programmar to accept these 2 regules for "radius" of method:


1) The change of parameter of object type WILL result in change of variable defined out of this method.
2) The change of parameter of primitive type WILL NOT result in change of variable defined out of this method.


Every programmer has no possibility to deside if he/she wants this. He/she only must to accept it.


So every programmer is forced to create special "one-purpose" class for every primitive value that he/she need to change in the body of method and return it out of this method into the place of parameters (for example IntegerX for primitive int, DoubleX for primitive double etc [the buil-in Java objects Integer and Doubles could be used for this reason!]).


1) How was solved this problem at "old" pascal?
-----------------------------------------------------------------


Remark: pascal distinguishes function (return value)and procedure (does not return value), but for simplicity I will here name both of it only like methods.


EVERY parameter (primitive or object) which is define in the declare of method CAN have an phrase "var":


A) "var" means that every change of this parameter inside of method will be changed the variable of parameter outside of this method.


B) Absence of "var" means that this method has no "side-effects" for suitable variable outside of this method.


When calling of this method, programmer writes only method and names. He/she must know how parameters were defined at declare of method.


It is rather danger.


2) How was solved this problem at "old" FoxPro?
-----------------------------------------------------------------


I can not remember the correct syntax level of this, but I know that programmer has here more and more more "freedom" then in pascal (and therefore it is more "danger" then in pascal):


A) Programmer can designate the type of parameter (READ-ONLY or WRITE-ONLY) at declare of function.


B) Programmer can change during calling of functions the type of this parameter or let it to act like is cited at declaration.


3) How was solved this problem at "old" Informix 4GL Language?
-----------------------------------------------------------------


The problem of READ-ONLY and READ-WRITE parameters is "converted" into possibility to enlarge of number of returned values.


So function can be declared with (for example) 3 returned values and during calling of this functions are suitable variable stated.


For example:


CALL function_abc (a, b, c) RETURNING a, b, c


This solution is very nice readable. I do not recommend this exact syntax. I "only" recommend any syntax from which every programmer will se during CALLING of method whether its parameters behave like READ-ONLY or like READ-WRITE.


The code of such program will then be clean, short and nice fore everybody!