1) It removes annoying indentation caused by try/catch. This point only
matters for complex functions. When you have too many indentations and you
split the screen, using the horizontal scroll bar could be very annoying.
and finally blocks. To people who are familiar with C-like languages, only
variables from current scope and scopes above could be used. This looks
like it gives access to sibling scopes.
On 21 August 2015 at 09:41, 'Lasse R.H. Nielsen' via Dart Misc <
Post by 'Lasse R.H. Nielsen' via Dart MiscWhen I see a specific feature like this, I try to see if it generalizes.
Whether it does or not tend to be enlightening :)
What if *any* block could have a catch/finally.
It sounds more general ... but it turns out, all that all it does is to
remove the "try" from a try/catch/finally statement. It may be slightly
shorter, but lacks the leading hint that something is wrapping the
following block (all special blocks have leading syntax, "for", "while",
"do", "try", "catch", "finally").
Uniquely among these, the "try" actually isn't necessary (the "do" is
because otherwise {stmts} while (expr); would be a block statement followed
by an empty while).
A function body isn't *exactly* a block statement, but it's close enough
that if we remove "try" and make "catch/finally" a possible suffix of a
block statement, it could generalize to function bodies.
So what would we lose?
One thing is that the entirety of a function's body is no longer inside an
outer block. That means parser complications - the "catch(e)" after a
method must not be seen as a new function declaration. Since "catch" is a
reserved word, that's probably not a problem.
It will be slightly harder to read for people trained to find the matching
"}" and assume the function ends there (and ditto tools).
What is the variable scope of those extra blocks? It would be reasonable
that they are in scope of the function parameters. So far a "(var x) {
stmts; }" has only had the scope of "x" extend to the following block. It's
not a big problem to have it also extend to more blocks, but it is a slight
idiosyncrasy that might trip people up.
So, all in all, it adds a bunch of small differences from other languages
and other parts of Dart in order to save "{ try" and "}" (and some
whitespace).
I'm not sure it's actually worth it (even if I personally think "try" is
ugly and annoying). If anything, I'd remove the need for "try" inside the
function, and still require you to wrap it in an outer "{" and "}" body
delimiter.
/L
Post by FelipeI would like to do this in Dart.
void myFunction(){
try {
....
} catch (e) {
....
}finally{
....
}
}
Proposal (I think for many situations is cleaner)
void myFunction(){
....
} catch(e){
....
} finally{
....
}
Thanks ;)
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an
--
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 KÞbenhavn K
- Denmark - CVR nr. 28 86 69 84
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an