Feedback and comments on ARM proposal - resend
Marek Kozieł
develop4lasu at gmail.com
Sat Mar 21 06:56:10 PDT 2009
I do not agree with that and what's more I think you misunderstood the
problem.
I'll try to track genesis:
The described problem exists because you try to write algorithm with graph
structure with sequence code, which is impossible now time.
As example:
static void copy(String src, String dest) throws IOException {
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dest);
try {
byte[] buf = new byte[8 * 1024];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
} finally {
out.close();
}
} finally {
in.close();
}
}
That problem can be shown as:
red line: right side can be executed only if left succeed
blue line: right side can be executed when left side ended or will not be
executed.
http://alan.umcs.lublin.pl/~lasu/develop/alg.gif
The problem is more deep than it looks like.
And how would ARM handle the situation when closing have to be done in
proper order, or we will have to get all information about exceptions?
What's more, throwing exception(s) in the air (ignore it) by default is
really bad solution like in try-finally.
Now, see how, in my opinion, this should be handled:
Let's bring more constructions:
Summon block will make that all expressions in it are executed no mater if
previously one succeed or not. What's more, block as a result will return
exception or exceptions that occurred in its body depending on mode. Let's
assume that all values & variables for which expression fails to assign will
be set to null.
Summon block mode:
first: block will result in first throwed exception
last: block will result in last throwed exception
all: block will result in all throwed exceptions as array
summon(mode){}:: exception
Bloc : simple block that will be skipped from execution on first exception.
block{};
Now see the same code:
summon(all){ // collect all exceptions
new FileInputStream(src)
::in; // value is null if constructor fails.
(in!=null?new FileOutputStream(dest):null)
::out;
if ((in!=null)&&(out!=null))
block{ // execution will stop at first exception.
byte[] buf = new byte[8 * 1024];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
}
if (in!=null) in.close();
if (out!=null) out.close;
}::exceptions;
if (exceptions.length==0) return true;
... // error handle
or:
summon(all){
new FileInputStream(src)
::in; // value is null if constructor fails.
if (in!=null){
new FileOutputStream(dest)
::out;
if (out!=null){
block{ // execution will stop at first exception.
byte[] buf = new byte[8 * 1024];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
}
out.close();
}
in.close();
}
}::exceptions;
if (exceptions.length==0) return true;
... // error handle
Maybe, that's not the best way to handle this, but AMR is not a solution in
that case at all.
--
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł
http://lasu2string.blogspot.com/
More information about the coin-dev
mailing list