The other day I gave you a quick overview of Dart’s fat arrow syntax. Here’s a fun example program I threw together that incorporates a whole bunch of
=>s. It’s a program about a boat that docks at a port and picks up a random number of randomly-sized cargo boxes before continuing on its journey.
I wouldn’t necessarily treat this code as instructive. There are a few things in here I wouldn’t normally condone. For example, I always avoid ternary operations (
condition ? expressionA : expressionB), since I feel regular
then branching reads more clearly, particularly when any nesting is involved. I’m only using a ternary operator here to show how compact fat arrows can make your code–in case that’s the quality you want to optimize for.