I dream of a day where I can write a program with some stupid thresholds/flags, run it for a while, and automatically learn better thresholds...

That sounds appealing. How would the program know what "better" was?

Defining a loss function comes to mind. Checkout JAX[1] or Autograd[2]. As this is essentially a different programming paradigm there are a ton of opportunities, but it is fresh enough such that there is little to no history of software engineering differentiable programs. Design patterns, rules of thumb, and standard practices have yet to be defined.

[1] https://github.com/google/jax

[2] https://github.com/HIPS/autograd