// not good
void toggle => isOpen = !isOpen;
void toggle => shutUp(isOpen = !isOpen);
void toggle() { isOpen = !isOpen; }
--
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 email to misc+uns...@dartlang.org.
If you wouldn't write the return, you shouldn't use the arrow either.
Do we need a shorthand syntax for function bodies that are single expressions that are NOT returned?
Or will the problem go away if we start consistently treating "void" as "Object that you can't use.
/L
+1
Setters look like boilerplate when next to getters.
+1
Setters look like boilerplate when next to getters.
void set myValue(value) => _myValue = value;
void set myValue(value) => void(_myValue = value);
void set url(String value) { _request.url = value; }
void set angleDegrees(value) { _angle = value * Math.PI / 180; }
void set rotation(value) { _typedData[4] = value; }
I agree but ...
void set myValue(value) => _myValue = value;Not sure how this would work in strong mode when we're declaring 'void' but are actually returning a value.
void set myValue(value) => void(_myValue = value);
As Gonzalo suggested, maybe it would take an extra keyword to treat a value as void.
I fully agree with you and that's a great detail about Dart.However I use getters/setters a lot for derived properties, and those are usually one-liners.
void set url(String value) { _request.url = value; }
void set angleDegrees(value) { _angle = value * Math.PI / 180; }
void set rotation(value) { _typedData[4] = value; }
One-line functions are less common, but the same applies.
void set myValue(value) { _myValue = value; }and drop the =>. It is *one* character longer
On Wed, Aug 31, 2016 at 6:08 AM, 'Lasse R.H. Nielsen' via Dart Misc <mi...@dartlang.org> wrote:void set myValue(value) { _myValue = value; }and drop the =>. It is *one* character longer
The formatter will split that { ... } into three lines. It could make an exception for cases like this, but that feels a little fishy.
Personally, I'd be happy if => just discarded the result if used for a void-returning declaration.
On Wed, Aug 31, 2016 at 9:57 PM, 'Bob Nystrom' via Dart Misc <mi...@dartlang.org> wrote:On Wed, Aug 31, 2016 at 6:08 AM, 'Lasse R.H. Nielsen' via Dart Misc <mi...@dartlang.org> wrote:void set myValue(value) { _myValue = value; }and drop the =>. It is *one* character longer
The formatter will split that { ... } into three lines. It could make an exception for cases like this, but that feels a little fishy.I'd approve of that exception.
If an entire function body consists of one statement, and it all fits on the same line as the function header, keep it as a one-liner. We already allow one-line "if" statements. Do we allow one-line "while" statements?foo(bar) { throw new FooTheBar(bar); }foo2(bar) { if (bar != baz) throw new FooTheBar(bar); }foo3(bar) { while (bar > 0) print(--bar); }Yep, works for me.
--Also, if I used the formatter, I wouldn't worry about the look, and then writing:foo(value){_myValue=value;}is actually *shorter* than:foo(value)=>_myValue=value;and the formatter would insert the whitespace for me. My editor would probably even add the final brace when I type the leading one. Two characters less!Personally, I'd be happy if => just discarded the result if used for a void-returning declaration.That is an interesting option. We special-case void in other ways, and in Strong-mode/Dart 2 the type annotation can affect the behavior.If we could disallow `=>` for void functions, we can also special-case it in other ways./LLasse R.H. Nielsen - l...@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
---
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 email to misc+uns...@dartlang.org.
The formatter will split that { ... } into three lines. It could make an exception for cases like this, but that feels a little fishy.I'd approve of that exception. If an entire function body consists of one statement, and it all fits on the same line as the function header, keep it as a one-liner. We already allow one-line "if" statements.
Do we allow one-line "while" statements?
foo(bar) { throw new FooTheBar(bar); }foo2(bar) { if (bar != baz) throw new FooTheBar(bar); }foo3(bar) { while (bar > 0) print(--bar); }
Yep, works for me.Also, if I used the formatter, I wouldn't worry about the look, and then writing:foo(value){_myValue=value;}is actually *shorter* than:foo(value)=>_myValue=value;and the formatter would insert the whitespace for me. My editor would probably even add the final brace when I type the leading one. Two characters less!
Personally, I'd be happy if => just discarded the result if used for a void-returning declaration.That is an interesting option. We special-case void in other ways, and in Strong-mode/Dart 2 the type annotation can affect the behavior.