Hacker News new | past | comments | ask | show | jobs | submit login

Dart:

  import 'dart:async';
  import 'dart:io';
  main() {
    var file = new File('/sys/class/leds/beaglebone:green:usr0/brightness');
    var state = 0;
    new Timer.periodic(new Duration(seconds: 2), (_) {
      state = 1 - state;
      file.writeAsStringSync('0$state', flush: true);
    });
  }
While it's not the most concise version, it's certainly very readable. Everyone can clearly see that the duration is 2 seconds and that that boolean flag is for flushing, because that's exactly what the code says.



Yes, I like it! Only thing I don't understand is '0$state'.


That's string interpolation. That line writes either "00" or "01". It's essentially the same as `'0' + state`.

  'x: $x, y: $y'
is a lot easier to type than:

  'x: ' + x + ', y: ' + y
I actually had to triple check that line. Concatenation is very error-prone. I often mess it up.

String interpolation is a fairly popular feature nowadays:

https://en.wikipedia.org/wiki/String_interpolation




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: