I don't get the hype around JSX.
Post by tatumizer-v0.2From the article
While JSX-less code is pretty ugly in React/JavaScript, it is quite
elegant in Flutter/Dart.
When I look into examples, "elegant" is not the first word that comes to
mind.
The structure contains too many nested levels. It's difficult to read,
and even more difficult to edit (e.g. to add more stuff).
We discussed the problem before, attempting to come up with more readable
(less verbose) format.
Now I think the solution lies on the surface - the structure should be
flattened (so it becomes in a sense more verbose, but carries more meaning
as a side effect)
return new Material(
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(_batteryLevel, key: const Key('Battery level label')),
new Padding(
padding: const EdgeInsets.all(16.0),
child: new RaisedButton(
child: const Text('Refresh'),
onPressed: _getBatteryLevel,
),
),
],
),
new Text(_chargingStatus),
],
),
);
}
final refreshButton = new RaisedButton(child: const Text('Refresh'),
onPressed: _getBatteryLevel);
final refreshButtonPadded = new Padding(padding: const
EdgeInsets.all(16.0), child: refreshButton);
final noClueWhatItIs = new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Text(_batteryLevel, key: const Key('Battery level label')),
refreshButtonPadded,
new Text(_chargingStatus)
];
);
//etc.
For some reason, everybody is obsessed with making it a single literal,
but why? Is it cool or something?
This is strange: if you had a complex, 50-line-long math expression -
won't you introduce intermediate named vars to simplify it?
Pretty sure JSX is trying to solve the same non-problem, or else there
would be no justification for it
(javascript interpolation with `...${name}` solves the problem for text,
and the rest is addressed by flattening; dart supported interpolation from
day 1).
--
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