tatumizer-v0.2
2016-09-22 16:10:37 UTC
Flutter Examples provide a rare opportunity for psychological
experimentation and theorising with respect to visual pattern recognition.
As a first example, let's contemplate the following fragment:
Widget build(BuildContext context) {
return new Material(
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Text('Hello from Flutter!'),
new RaisedButton(
child: new Text('Get Location'),
onPressed: _getLocation
),
new Text('Latitude: $_latitude, Longitude: $_longitude'),
]
)
)
);
}
Can you see how "child"/"children" stand out here? Why do they? My theory
is that our Mind is very good at capturing repeating patterns. Due to this
"pattern recognition effect", our Mind perceives token "child" as the main
character of the scene, whereas everything else at best serves as a
background or decoration (*)
Since "child" tokens carry very little information here (indentation is
more than enough to express parent-child relationship), they distract us
from appreciating the semantics of the expression.
As an experiment, let's try to remove "child" and "children". Suppose we
allow one of the named parameters of constructor to declare itself a "list
of children" (the name of parameter itself can be anything), in which case
we don't need to use its name in object literal at all, and are not
supposed to explicitly write it as list. Instead, we can write each child
independently, each time ADDING it to a list (so, expression ": x" in the
literal is treated as "add x to the list of children")
Let's rewrite our example using new notation:
Widget build(BuildContext context) {
return new Material(
: new Center(
: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
: new Text('Hello from Flutter!'),
: new RaisedButton(
onPressed: _getLocation,
: new Text('Get Location')
),
: new Text('Latitude: $_latitude, Longitude: $_longitude'),
)
)
);
}
After modification, term "new" becomes a repeating pattern, adding no value
to presentation, but distracting from the real content. Let's remove it,
too:
Widget build(BuildContext context) {
return Material(
: Center(
: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
: Text('Hello from Flutter!'),
: RaisedButton(
onPressed: _getLocation,
: Text('Get Location')
),
: Text('Latitude: $_latitude, Longitude: $_longitude'),
)
)
);
}
Isn't it GOOD? Crisp, clear code, joy to write and look at.
It's my conjecture that the change alone may turn dart from "meh" language
to "two thumbs up!" language, especially for UI programming.
Opinions are welcome!
(*) The alternative theory is that we have just too many nested blocks
experimentation and theorising with respect to visual pattern recognition.
As a first example, let's contemplate the following fragment:
Widget build(BuildContext context) {
return new Material(
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Text('Hello from Flutter!'),
new RaisedButton(
child: new Text('Get Location'),
onPressed: _getLocation
),
new Text('Latitude: $_latitude, Longitude: $_longitude'),
]
)
)
);
}
Can you see how "child"/"children" stand out here? Why do they? My theory
is that our Mind is very good at capturing repeating patterns. Due to this
"pattern recognition effect", our Mind perceives token "child" as the main
character of the scene, whereas everything else at best serves as a
background or decoration (*)
Since "child" tokens carry very little information here (indentation is
more than enough to express parent-child relationship), they distract us
from appreciating the semantics of the expression.
As an experiment, let's try to remove "child" and "children". Suppose we
allow one of the named parameters of constructor to declare itself a "list
of children" (the name of parameter itself can be anything), in which case
we don't need to use its name in object literal at all, and are not
supposed to explicitly write it as list. Instead, we can write each child
independently, each time ADDING it to a list (so, expression ": x" in the
literal is treated as "add x to the list of children")
Let's rewrite our example using new notation:
Widget build(BuildContext context) {
return new Material(
: new Center(
: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
: new Text('Hello from Flutter!'),
: new RaisedButton(
onPressed: _getLocation,
: new Text('Get Location')
),
: new Text('Latitude: $_latitude, Longitude: $_longitude'),
)
)
);
}
After modification, term "new" becomes a repeating pattern, adding no value
to presentation, but distracting from the real content. Let's remove it,
too:
Widget build(BuildContext context) {
return Material(
: Center(
: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
: Text('Hello from Flutter!'),
: RaisedButton(
onPressed: _getLocation,
: Text('Get Location')
),
: Text('Latitude: $_latitude, Longitude: $_longitude'),
)
)
);
}
Isn't it GOOD? Crisp, clear code, joy to write and look at.
It's my conjecture that the change alone may turn dart from "meh" language
to "two thumbs up!" language, especially for UI programming.
Opinions are welcome!
(*) The alternative theory is that we have just too many nested blocks
--
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+***@dartlang.org.
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+***@dartlang.org.