digitalmars.D - Small Changes for Java JDK7
- bearophile (24/24) Mar 01 2009 From:
- davidl (4/28) Mar 02 2009 I believe it is worse than scope(exit) resource.dispose(); in terms of
- Andrei Alexandrescu (7/47) Mar 02 2009 I agree. They keep on missing the point that the blessed code on the
- Walter Bright (2/6) Mar 02 2009 Reinventing scope, rather badly.
- bearophile (5/6) Mar 02 2009 Python has recently introduced something similar to that Java solution:
- Jarrett Billingsley (2/6) Mar 02 2009 Does that change the fact that it's a poor imitation of scope?
- Lutger (3/10) Mar 02 2009 It looks more like (or rather exactly like) C#'s using.
- The Anh Tran (15/15) Mar 02 2009 http://www.boost.org/doc/libs/1_38_0/libs/scope_exit/doc/html/scope_exit...
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, bearophileI 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> 写道: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. AndreiFrom: 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, bearophileI believe it is worse than scope(exit) resource.dispose(); in terms of syntax.
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:Does that change the fact that it's a poor imitation of scope?Reinventing scope, rather badly.Python has recently introduced something similar to that Java solution: http://www.python.org/dev/peps/pep-0343/
Mar 02 2009
Walter Bright wrote:bearophile wrote:jdk7.htmlFrom: http://jeremymanson.blogspot.com/2009/02/small-language-changes-for-Automated Resource Blocks, to be able to say things like:Reinventing scope, rather badly.
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