Posts

Showing posts with the label Dart

Supporting command line arguments in Dart programs

Image
Dart programs, really all programs, are either hardcoded against certain targets and configurations or they configurable at startup. Not sure about you but the word "hardcoded" always sounds bad.  The most common way of providing configuration information is probably: Command-line arguments Environmental variables Properties files or other accessible storage Properties services The approach you pick depends on the nature ephemeral nature of the program, the environment you run in, and if the configuration can change while the program is running .  Sometimes you use a combination, one configuration method at bootstrap, and then a different one as the program continues running. In all command-style programs, I've found that I need some way to bootstrap the process.  It almost always has command-line arguments or environmental variables. Environment variables are great but can be a bit opaque depending on how the program is run. My go-to is to include run-time argument suppo...

Creating Immutable Functional Style Dart Model Objects based on JSON or JSON schemas

Image
Flutter is opinionated about using a functional programming model that includes immutable data objects.  I've found that we tend to ignore that whole immutable thing when dealing with JSON data.   Projects can be loose when handling incoming JSON data and how it is accessed, sprinkling string-style map keys across the codebase.  We can reduce that tendency by providing models to eliminate the string keys and mutable models to stop people from directly manipulating maps of strings. Some languages are functional only.  Other languages have no way of generating immutable objects. In those cases, we just end up with objects that can be easily converted into and out of JSON structures and strings. I'm working in Dart right now so the rest of this will be Dart samples Modeling Longitude and Latitude Using the JSON Schema Let's pick something simple as an example.  We're going to use this Latitude and Longitude  JSON Schema  that follows the schema defin...