Discussion:
[dart-misc] Re: Empty else clause. Should this be an error?
'Lasse R.H. Nielsen' via Dart Misc
2015-11-16 07:07:51 UTC
Permalink
Making it an error at this point would be a breaking change. It's perfectly
valid syntax by the current specification, even if it's somewhat ridiculous.

On the other hand, it should be caught by any linter or style-checked
because you have a multi-line if statement without braces. Most style
guides disallow that.
The dart formatter would unindent the line after the "else", which shows
you that something is wrong.

I think it would be reasonable for the analyzer to give a hint in cases
like this - you are doing something which looks questionable, and even if
it is actually correct, you could still remove the entire else branch and
make the program shorter and easier to read.

/L
An empty else clause is just syntactic noise, and sometimes even confusing
as I had to read the example twice to spot the ';'.
I don't think it's a real problem (I didn't even imagine empty else
clauses before) but I agree that a hint would be nice.
I'm pretty sure there are other priorities, though.
Java and C++ behaving a certain way is not a reason not to try and do
better.
--
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
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
Lasse R.H. Nielsen - ***@google.com
'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
'Phil Quitslund' via Dart Misc
2015-11-16 19:51:19 UTC
Permalink
Seems like a great candidate for a lint.

Thanks for filing the bug Davy!
Thanks guys - good points. Interestingly CSharp raises a warning.
https://github.com/dart-lang/sdk/issues/24936
Thanks,
Davy
On 16 November 2015 at 07:07, 'Lasse R.H. Nielsen' via Dart Misc <
Post by 'Lasse R.H. Nielsen' via Dart Misc
Making it an error at this point would be a breaking change. It's
perfectly valid syntax by the current specification, even if it's somewhat
ridiculous.
On the other hand, it should be caught by any linter or style-checked
because you have a multi-line if statement without braces. Most style
guides disallow that.
The dart formatter would unindent the line after the "else", which shows
you that something is wrong.
I think it would be reasonable for the analyzer to give a hint in cases
like this - you are doing something which looks questionable, and even if
it is actually correct, you could still remove the entire else branch and
make the program shorter and easier to read.
/L
An empty else clause is just syntactic noise, and sometimes even
confusing as I had to read the example twice to spot the ';'.
I don't think it's a real problem (I didn't even imagine empty else
clauses before) but I agree that a hint would be nice.
I'm pretty sure there are other priorities, though.
Java and C++ behaving a certain way is not a reason not to try and do
better.
--
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
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
--
'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
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
--
Diving Into Dart - http://divingintodart.blogspot.co.uk/
--
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
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
Phil Quitslund
Software Engineer
Google, Inc.
--
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
Loading...