Pascal Hertleif
2018-09-05
“This is RustFest, Pascal, not AssemblyCamp”
Declarative programming is often defined as any style of programming that is not imperative.
How?
Is there an item that starts with “l”?
{"a": 4}
This structure now has three fields
let v: serde_json::Value = serde_json::from_str(
"{\"a\": 4, \"b\": 8, \"c\": 15}"
)?;
struct Response { a: u64, b: u64, c: u64 }
let a = if let Some(value) = v["a"].as_u64() {
value
} else {
return Err("invalid".into())
};
let b = if let Some(value) = v["b"].as_u64() {
value
} else {
return Err("invalid".into())
};
let c = if let Some(value) = v["c"].as_u64() {
value
} else {
return Err("invalid".into())
};
let res = Response { a, b, c };
std
tool -o Output.file Input.file
use getopts::Options;
let mut opts = Options::new();
opts.optopt("o", "", "set output file name", "NAME");
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(f) => { panic!(f.to_string()) }
};
let output = matches.opt_str("o");
let input = if !matches.free.is_empty() {
matches.free[0].clone()
} else {
print_usage(&program, opts);
return;
};
use clap::{Arg, App, SubCommand};
let matches = App::new("My Super Program")
.arg(Arg::with_name("output")
.help("Sets a output file")
.short("o").long("output")
.takes_value(true))
.arg(Arg::with_name("INPUT")
.help("Sets the input file to use")
.required(true).index(1))
.get_matches();
if let Some(input) = matches.value_of("INPUT") {
// ...
}
We write generic functions.
The concrete types will declare what the user wants
“This is RustFest, Pascal, not Haskell Symposium”
Code whose behavior is hard to predict (or remember)
e.g. using cargo expand
That often only moves the complexity but doesn’t resolve it
I’m Pascal and I want you to talk to me!