digitalmars.D - Small Changes for Java JDK7
- bearophile <bearophileHUGS lycos.com> Mar 01 2009
- davidl <davidl 126.com> Mar 02 2009
- Walter Bright <newshound1 digitalmars.com> Mar 02 2009
- bearophile <bearophileHUGS lycos.com> Mar 02 2009
- Jarrett Billingsley <jarrett.billingsley gmail.com> Mar 02 2009
- Lutger <lutger.blijdestijn gmail.com> Mar 02 2009
- The Anh Tran <trtheanh gmail.com> Mar 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
Mar 01 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.
Mar 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
Mar 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.
Mar 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
Mar 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?
Mar 02 2009
Walter Bright wrote:bearophile wrote:From: http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-
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.
Mar 02 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; }
Mar 02 2009









Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> 