Thread overview
Small Changes for Java JDK7
Mar 02, 2009
bearophile
Mar 02, 2009
davidl
Mar 02, 2009
Walter Bright
Mar 02, 2009
bearophile
Mar 02, 2009
Lutger
Scope(exit) has been recently added to Boost 1.38
Mar 03, 2009
The Anh Tran
March 02, 2009
From: http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-jdk7.html

Automated Resource Blocks, to be able to say things like:

try (BufferedReader br = new BufferedReader(new FileReader(path)) {
  return br.readLine();
}

instead of:

BufferedReader br = new BufferedReader(new FileReader(path));
try {
   return br.readLine();
} finally {
   br.close();
}

based on having BufferedReader implement a Disposable interface.

------------------

Exception handling improvements:

try {
    doWork(file);
} catch (final IOException | SQLException ex) {
    logger.log(ex);
    throw ex;
}

Bye,
bearophile
March 02, 2009
在 Mon, 02 Mar 2009 08:02:35 +0800,bearophile <bearophileHUGS@lycos.com> 写道:

> From:
> http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-jdk7.html
>
> Automated Resource Blocks, to be able to say things like:
>
> try (BufferedReader br = new BufferedReader(new FileReader(path)) {
>   return br.readLine();
> }
>
> instead of:
>
> BufferedReader br = new BufferedReader(new FileReader(path));
> try {
>    return br.readLine();
> } finally {
>    br.close();
> }
>
> based on having BufferedReader implement a Disposable interface.
>
> ------------------
>
> Exception handling improvements:
>
> try {
>     doWork(file);
> } catch (final IOException | SQLException ex) {
>     logger.log(ex);
>     throw ex;
> }
>
> Bye,
> bearophile

I believe it is worse than scope(exit) resource.dispose(); in terms of syntax.
March 02, 2009
davidl wrote:
> 在 Mon, 02 Mar 2009 08:02:35 +0800,bearophile <bearophileHUGS@lycos.com> 写道:
> 
>> From:
>> http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-jdk7.html 
>>
>>
>> Automated Resource Blocks, to be able to say things like:
>>
>> try (BufferedReader br = new BufferedReader(new FileReader(path)) {
>>   return br.readLine();
>> }
>>
>> instead of:
>>
>> BufferedReader br = new BufferedReader(new FileReader(path));
>> try {
>>    return br.readLine();
>> } finally {
>>    br.close();
>> }
>>
>> based on having BufferedReader implement a Disposable interface.
>>
>> ------------------
>>
>> Exception handling improvements:
>>
>> try {
>>     doWork(file);
>> } catch (final IOException | SQLException ex) {
>>     logger.log(ex);
>>     throw ex;
>> }
>>
>> Bye,
>> bearophile
> 
> I believe it is worse than scope(exit) resource.dispose(); in terms of syntax.

I agree. They keep on missing the point that the blessed code on the normal path MUST NOT TAKE THE HIT OF AN EXTRA INDENTATION LEVEL. I am screaming because people keep on falling in that trap in various languages, mostly by copying without thinking from other languages. The first language I know that did that mistake was Lisp itself.

Andrei
March 02, 2009
bearophile wrote:
> From:
> http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-jdk7.html
> 
> Automated Resource Blocks, to be able to say things like:

Reinventing scope, rather badly.
March 02, 2009
Walter Bright:
> Reinventing scope, rather badly.

Python has recently introduced something similar to that Java solution: http://www.python.org/dev/peps/pep-0343/

Bye,
bearophile
March 02, 2009
On Mon, Mar 2, 2009 at 3:57 PM, bearophile <bearophileHUGS@lycos.com> wrote:
> Walter Bright:
>> Reinventing scope, rather badly.
>
> Python has recently introduced something similar to that Java solution: http://www.python.org/dev/peps/pep-0343/

Does that change the fact that it's a poor imitation of scope?
March 02, 2009
Walter Bright wrote:

> bearophile wrote:
>> From: http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-
jdk7.html
>> 
>> Automated Resource Blocks, to be able to say things like:
> 
> Reinventing scope, rather badly.

It looks more like (or rather exactly like) C#'s using.

March 03, 2009
http://www.boost.org/doc/libs/1_38_0/libs/scope_exit/doc/html/scope_exit/alternatives.html

try
{
    File passwd("/etc/passwd");
    BOOST_SCOPE_EXIT( (&passwd) )
    {
        passwd.close();
    } BOOST_SCOPE_EXIT_END
    // ...
}
catch(...)
{
    log("could not get user info");
    throw;
}