Skip to main content


Showing posts from September, 2012

Dart: An Algorithm to Unindent Code

Have you ever had to write an algorithm to unindent a block of code consistently? Figuring out the maximum amount of whitespace among all the lines and then removing that amount of whitespace is non-trivial. Remembering to ignore lines that only have whitespace makes the problem even harder. Here's some Dart code that I wrote to do it. I do believe the performance is O(num_lines * max_line_length), which I think is optimal. It should be easy to port this to other languages if you need it: /** * Remove the indentation from the given lines. * * Only remove as much indentation as the line with the least amount of * indentation. */ List<String> unindentFilter(List<String> lines) { // Make a copy so that we can modify it in place. lines = new List<String>.from(lines); // Make sure there is at least one line. if (!lines.isEmpty()) { // Figure out how much indentation the first line has. var indentation = new List<String>(); for

3 Articles Every Hardcore Dart Developer Should Read

I answer a lot of questions about Dart. Some of my friends are even working on their own programming languages, and they tend to ask really hard questions. In the past, I've struggled with some of those questions. However, I finally got around to reading three articles that answered a lot of those tough questions: Why Dart Types are Optional and Unsound Why Not a Bytecode VM? Optional Types in Dart Reading these three articles really helped me appreciate Dart at a much deeper level. If you're a language geek like I am, I highly recommend them!