3 ms·
Fibonacci function in Dart can be as easy as: fib(n) => n < 2 ? n : (fib(n - 1) + fib(n - 2)); Examples on the main page just exists to show cases as much lan
by mraleph 13y ago
Fibonacci function in Dart can be as easy as:
fib(n) => n < 2 ? n : (fib(n - 1) + fib(n - 2));
Examples on the main page just exists to show cases as much language features as possible. It does not say that you have to wrap your Fibonacci into a class.
- deleted 13y ago[deleted]
- nailer 13y agoMaybe it's a matter of bad docs giving the wrong impression then? Examples should be terse, the ability to create unnecessary wrappers don't seem like much of a feature to show off.
- mraleph 13y agoStrictly speaking it's not a doc. It's a snippet on the main page that tries to show case available language constructs. I do agree however that wrapping Fibonacci in a class looks a bit strange. Documentation that showcases features in the terse form is available at http://synonym.dartlang.org/ http://synonym.dartlang.org/ If you have better ideas you can file a bug or even submit a pull request for the site: https://github.com/dart-lang/dartlang.org https://github.com/dart-lang/dartlang.org
- nailer 13y agoWeb pages showing people how to do things are documentation. No inclination to contribute, Google have known that verbosity is a common reason for disliking Dart for 750+ days and haven't done much about it. I'm fine using JS and, when I want strong typing, know that Typescript is there.
- spankalee 13y agoYeah, I think the Fibonacci class example is odd too. I also would love to propose a self-imposed internet-wide ban on the recursive Fibonacci implementation as I'm pretty sure it causes brain rot and makes dynamic programming seem way more magical than it is.
- ahoge 13y ago>fib(n) => n < 2 ? n : (fib(n - 1) + fib(n - 2)); + the laziest way to do memoization: var cache = new Map(); fib (n) => cache.putIfAbsent(n, () => n < 2 ? n : fib(n - 1) + fib(n - 2));